package com.qxgmat.controller.admin;

import com.github.pagehelper.Page;
import com.nuliji.tools.PageMessage;
import com.nuliji.tools.Response;
import com.nuliji.tools.ResponseHelp;
import com.nuliji.tools.Transform;
import com.qxgmat.data.dao.entity.ClassCourse;
import com.qxgmat.dto.admin.response.ClassCourseListDto;
import com.qxgmat.service.inline.ClassCourseService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

@RestController("AdminClassController")
@RequestMapping("/admin/class")
public class ClassController {

    @Autowired
    private ClassCourseService classCourseService;

    @RequestMapping(value = "/course/list", method = RequestMethod.GET)
    @ApiOperation(value = "课程列表", httpMethod = "GET")
    public Response<PageMessage<ClassCourseListDto>> list(
            @RequestParam(required = false, defaultValue = "1") int page,
            @RequestParam(required = false, defaultValue = "100") int size,
            HttpSession session) {
        Page<ClassCourse> p = classCourseService.select(page, size);
        List<ClassCourseListDto> pr = Transform.convert(p, ClassCourseListDto.class);

        return ResponseHelp.success(pr, page, size, p.getTotal());
    }
}
