package com.app.controller.api;

import com.app.dto.Result;
import com.app.dto.basics.GradeClassDto;
import com.app.entity.basics.School;
import com.app.service.basics.SchoolService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotBlank;
import java.util.List;

/**
 * 功能描述：学校
 *
 * @Auther: 梁展鹏
 * @Date: 2018/7/24 11:38
 */
@Api(description = "学校")
@Slf4j
@Validated
@RestController("ApiSchoolController")
@RequestMapping("/api/school")
public class SchoolController {

    @Autowired
    private SchoolService schoolService;

    /**
     * 功能描述：查询[城市名称]下的所有学校
     *
     * @param city 城市名称
     * @return
     */
    @ApiOperation(value = "查询[城市名称]下的所有学校")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "city", value = "城市名称", dataType = "String", paramType = "path", required = true, defaultValue = "广州市")
    })
    @GetMapping("/{city}/list")
    public ResponseEntity<Result<List<School>>> list(@NotBlank @PathVariable("city") String city) {
        return new ResponseEntity(new Result().ok(schoolService.findByCity(city)), HttpStatus.OK);
    }

    /**
     * 功能描述：获取[学校]的年级班级
     *
     * @param schoolId 学校标识
     * @return
     */
    @ApiOperation(value = "获取[学校]的年级班级")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "schoolId", value = "学校标识", dataType = "String", paramType = "path", required = true, defaultValue = "")
    })
    @GetMapping("/{schoolId}/grade-class")
    public ResponseEntity<Result<List<GradeClassDto>>> gradeClass(@NotBlank @PathVariable("schoolId") String schoolId) {
        return new ResponseEntity(new Result().ok(schoolService.findByGradeClass(schoolId)), HttpStatus.OK);
    }

}
