package cn.exploring.engine.server.wx.web;

import cn.exploring.engine.server.core.util.ResponseUtil;
import cn.exploring.engine.server.db.domain.ClassInfo;
import cn.exploring.engine.server.db.service.ClassService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/wx/class")
@Validated
public class ClassController {

    @Resource
    ClassService classService;

    @GetMapping("selectClass")
    public Object selectClass(@RequestParam String className, @RequestParam(required = false, defaultValue = "1") Integer page, @RequestParam(required = false, defaultValue = "10") Integer limit,
                              @RequestParam(required = false, defaultValue = "add_time") String sort, @RequestParam(required = false, defaultValue = "desc") String order) {
        return ResponseUtil.ok(classService.webSelectClass(className,  page, limit, sort, order));
    }

    @GetMapping("addClass")
    public Object addClass(@RequestParam String className) {
        String status = classService.addClassInfo(className);
        return status.contains("OK") ? ResponseUtil.ok(status) : ResponseUtil.fail(502, status);
    }

    @PostMapping("updateClass")
    public Object updateClass(@RequestBody ClassInfo classInfo) {
        classService.updateClassInfo(classInfo);
        return ResponseUtil.ok("OK");
    }

    @PostMapping("batchDeleted")
    public Object batchDeleted(@RequestBody List<Integer> idList) {
        return ResponseUtil.ok(classService.batchDeletedData(idList));
    }

    @GetMapping("/listAll")
    public Object listAll() {
        return ResponseUtil.ok(classService.listAll());
    }






}
