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

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

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

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

    @Resource
    StudentPointService pointService;

    @GetMapping("selectPoint")
    public Object selectPoint(@RequestParam String studentName, @RequestParam  String studentUniqueId,@RequestParam Integer classId,@RequestParam String startTime,@RequestParam  String endTime,
                              @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(pointService.selectPointByWeb(studentName, studentUniqueId, classId, startTime, endTime, page, limit, sort, order));
    }


    @GetMapping("add")
    public Object add(@RequestBody StudentPointInfo pointInfo) {
        String status = pointService.addPoint(pointInfo);
        return status.contains("OK") ? ResponseUtil.ok(status) : ResponseUtil.fail(502, status);
    }


    @PostMapping("update")
    public Object update(@RequestBody StudentPointInfo pointInfo) {
        pointService.updatePoint(pointInfo);
        return ResponseUtil.ok("OK");
    }

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






}
