package com.mindskip.xzs.controller.admin; import com.github.pagehelper.PageInfo; import com.mindskip.xzs.base.BaseApiController; import com.mindskip.xzs.base.RestResponse; import com.mindskip.xzs.domain.Department; import com.mindskip.xzs.service.DepartmentService; import com.mindskip.xzs.utility.PageInfoHelper; import com.mindskip.xzs.viewmodel.department.DepartmentResponseVM; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import javax.validation.Valid; import java.util.List; @RestController("AdminDepartmentController") @RequestMapping("/api/admin/department") public class DepartmentController extends BaseApiController { private final DepartmentService departmentService; @Autowired public DepartmentController(DepartmentService departmentService) { this.departmentService = departmentService; } @RequestMapping(value = "/list", method = RequestMethod.POST) public RestResponse> getAll(){ List res = departmentService.gets(); return RestResponse.ok(res); } @RequestMapping(value = "/page/list", method = RequestMethod.POST) public RestResponse> pageList(@RequestBody DepartmentResponseVM model) { PageInfo pageInfo = departmentService.gets(model); PageInfo page = PageInfoHelper.copyMap(pageInfo, q -> { DepartmentResponseVM vm = modelMapper.map(q,DepartmentResponseVM.class); return vm; }); return RestResponse.ok(page); } @RequestMapping(value = "/add", method = RequestMethod.POST) public RestResponse add(@RequestBody @Valid String name) { return RestResponse.ok(departmentService.add(name)); } @RequestMapping(value = "/update", method = RequestMethod.POST) public RestResponse update(@RequestBody @Valid Department model) { return RestResponse.ok(departmentService.update(model)); } @RequestMapping(value = "/get/{id}", method = RequestMethod.POST) public RestResponse update(@PathVariable Integer id) { return RestResponse.ok(departmentService.getById(id)); } }