“mitao”
2026-03-24 1c77e3491aaaffec3ada7721c231d72ead578588
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
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.HealthCourseSaveRequest;
import com.tcm.training.admin.live.dto.HealthCourseStatusRequest;
import com.tcm.training.admin.live.dto.HealthCourseVideoSaveRequest;
import com.tcm.training.admin.live.service.HealthCourseAppService;
import com.tcm.training.admin.live.vo.HealthCourseDetailVO;
import com.tcm.training.admin.live.vo.HealthCourseListItemVO;
import com.tcm.training.admin.live.vo.HealthCourseStatusVO;
import com.tcm.training.admin.live.vo.HealthCourseVideoDetailVO;
import com.tcm.training.admin.live.vo.HealthCourseVideoItemVO;
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.PatchMapping;
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.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
 
@Validated
@RestController
@RequestMapping({"/api/v1", "/api"})
public class HealthCourseController {
 
    private final HealthCourseAppService healthCourseAppService;
 
    public HealthCourseController(HealthCourseAppService healthCourseAppService) {
        this.healthCourseAppService = healthCourseAppService;
    }
 
    @GetMapping("/health-courses")
    public ApiResponse<PageResponse<HealthCourseListItemVO>> page(@RequestParam(required = false, defaultValue = "1") int page,
                                                                  @RequestParam(required = false, defaultValue = "10") int pageSize,
                                                                  @RequestParam(required = false) String keyword,
                                                                  @RequestParam(required = false) Long levelCategoryId,
                                                                  @RequestParam(required = false) Long difficultyCategoryId,
                                                                  @RequestParam(required = false) Integer status) {
        return ApiResponse.ok(healthCourseAppService.page(page, pageSize, keyword, levelCategoryId, difficultyCategoryId, status));
    }
 
    @GetMapping("/health-courses/export")
    public void export(HttpServletResponse response,
                       @RequestParam(required = false) String keyword,
                       @RequestParam(required = false) Long levelCategoryId,
                       @RequestParam(required = false) Long difficultyCategoryId,
                       @RequestParam(required = false) Integer status) throws IOException {
        healthCourseAppService.export(response, keyword, levelCategoryId, difficultyCategoryId, status);
    }
 
    @PostMapping("/health-courses")
    public ApiResponse<HealthCourseDetailVO> create(@Valid @RequestBody HealthCourseSaveRequest req) {
        return ApiResponse.ok(healthCourseAppService.create(req));
    }
 
    @GetMapping("/health-courses/{id}")
    public ApiResponse<HealthCourseDetailVO> detail(@PathVariable("id") Long id) {
        return ApiResponse.ok(healthCourseAppService.detail(id));
    }
 
    @PutMapping("/health-courses/{id}")
    public ApiResponse<HealthCourseDetailVO> update(@PathVariable("id") Long id, @Valid @RequestBody HealthCourseSaveRequest req) {
        return ApiResponse.ok(healthCourseAppService.update(id, req));
    }
 
    @PatchMapping("/health-courses/{id}/status")
    public ApiResponse<HealthCourseStatusVO> patchStatus(@PathVariable("id") Long id, @Valid @RequestBody HealthCourseStatusRequest req) {
        return ApiResponse.ok(healthCourseAppService.patchStatus(id, req));
    }
 
    @DeleteMapping("/health-courses/{id}")
    public ApiResponse<Void> delete(@PathVariable("id") Long id) {
        healthCourseAppService.delete(id);
        return ApiResponse.ok(null);
    }
 
    @GetMapping("/health-courses/{courseId}/videos")
    public ApiResponse<PageResponse<HealthCourseVideoItemVO>> pageVideos(@PathVariable("courseId") Long courseId,
                                                                         @RequestParam(required = false, defaultValue = "1") int page,
                                                                         @RequestParam(required = false, defaultValue = "10") int pageSize,
                                                                         @RequestParam(required = false) String chapterName,
                                                                         @RequestParam(required = false) Integer saleType) {
        return ApiResponse.ok(healthCourseAppService.pageVideos(courseId, page, pageSize, chapterName, saleType));
    }
 
    @GetMapping("/health-courses/{courseId}/videos/{videoId}")
    public ApiResponse<HealthCourseVideoDetailVO> detailVideo(@PathVariable("courseId") Long courseId,
                                                              @PathVariable("videoId") Long videoId) {
        return ApiResponse.ok(healthCourseAppService.detailVideo(courseId, videoId));
    }
 
    @PostMapping("/health-courses/{courseId}/videos")
    public ApiResponse<HealthCourseVideoDetailVO> createVideo(@PathVariable("courseId") Long courseId,
                                                              @Valid @RequestBody HealthCourseVideoSaveRequest req) {
        return ApiResponse.ok(healthCourseAppService.createVideo(courseId, req));
    }
 
    @PutMapping("/health-courses/{courseId}/videos/{videoId}")
    public ApiResponse<HealthCourseVideoDetailVO> updateVideo(@PathVariable("courseId") Long courseId,
                                                              @PathVariable("videoId") Long videoId,
                                                              @Valid @RequestBody HealthCourseVideoSaveRequest req) {
        return ApiResponse.ok(healthCourseAppService.updateVideo(courseId, videoId, req));
    }
 
    @DeleteMapping("/health-courses/{courseId}/videos/{videoId}")
    public ApiResponse<Void> deleteVideo(@PathVariable("courseId") Long courseId,
                                         @PathVariable("videoId") Long videoId) {
        healthCourseAppService.deleteVideo(courseId, videoId);
        return ApiResponse.ok(null);
    }
}