1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package com.tcm.training.admin.live.controller;
 
import com.tcm.training.admin.common.ApiResponse;
import com.tcm.training.admin.common.PageResponse;
import com.tcm.training.admin.live.dto.LiveCourseCategorySaveRequest;
import com.tcm.training.admin.live.service.LiveCourseCategoryAppService;
import com.tcm.training.admin.live.vo.LiveCourseCategoryDetailVO;
import com.tcm.training.admin.live.vo.LiveCourseCategoryItemVO;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
 
import javax.validation.Valid;
 
@Validated
@RestController
@RequestMapping({"/api/v1", "/api"})
public class LiveCourseCategoryController {
 
    private final LiveCourseCategoryAppService liveCourseCategoryAppService;
 
    public LiveCourseCategoryController(LiveCourseCategoryAppService liveCourseCategoryAppService) {
        this.liveCourseCategoryAppService = liveCourseCategoryAppService;
    }
 
    @GetMapping("/live-course-categories")
    public ApiResponse<PageResponse<LiveCourseCategoryItemVO>> page(@RequestParam(required = false, defaultValue = "1") int page,
                                                                    @RequestParam(required = false, defaultValue = "10") int pageSize,
                                                                    @RequestParam String type) {
        return ApiResponse.ok(liveCourseCategoryAppService.page(page, pageSize, type));
    }
 
    @GetMapping("/live-course-categories/{id}")
    public ApiResponse<LiveCourseCategoryDetailVO> detail(@PathVariable("id") Long id) {
        return ApiResponse.ok(liveCourseCategoryAppService.detail(id));
    }
 
    @PostMapping("/live-course-categories")
    public ApiResponse<LiveCourseCategoryDetailVO> create(@RequestParam String type,
                                                          @Valid @RequestBody LiveCourseCategorySaveRequest req) {
        return ApiResponse.ok(liveCourseCategoryAppService.create(type, req));
    }
 
    @PutMapping("/live-course-categories/{id}")
    public ApiResponse<LiveCourseCategoryDetailVO> update(@PathVariable("id") Long id,
                                                          @Valid @RequestBody LiveCourseCategorySaveRequest req) {
        return ApiResponse.ok(liveCourseCategoryAppService.update(id, req));
    }
 
    @DeleteMapping("/live-course-categories/{id}")
    public ApiResponse<Void> delete(@PathVariable("id") Long id) {
        liveCourseCategoryAppService.delete(id);
        return ApiResponse.ok(null);
    }
}