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> 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 create(@Valid @RequestBody HealthCourseSaveRequest req) { return ApiResponse.ok(healthCourseAppService.create(req)); } @GetMapping("/health-courses/{id}") public ApiResponse detail(@PathVariable("id") Long id) { return ApiResponse.ok(healthCourseAppService.detail(id)); } @PutMapping("/health-courses/{id}") public ApiResponse update(@PathVariable("id") Long id, @Valid @RequestBody HealthCourseSaveRequest req) { return ApiResponse.ok(healthCourseAppService.update(id, req)); } @PatchMapping("/health-courses/{id}/status") public ApiResponse patchStatus(@PathVariable("id") Long id, @Valid @RequestBody HealthCourseStatusRequest req) { return ApiResponse.ok(healthCourseAppService.patchStatus(id, req)); } @DeleteMapping("/health-courses/{id}") public ApiResponse delete(@PathVariable("id") Long id) { healthCourseAppService.delete(id); return ApiResponse.ok(null); } @GetMapping("/health-courses/{courseId}/videos") public ApiResponse> 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 detailVideo(@PathVariable("courseId") Long courseId, @PathVariable("videoId") Long videoId) { return ApiResponse.ok(healthCourseAppService.detailVideo(courseId, videoId)); } @PostMapping("/health-courses/{courseId}/videos") public ApiResponse createVideo(@PathVariable("courseId") Long courseId, @Valid @RequestBody HealthCourseVideoSaveRequest req) { return ApiResponse.ok(healthCourseAppService.createVideo(courseId, req)); } @PutMapping("/health-courses/{courseId}/videos/{videoId}") public ApiResponse 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 deleteVideo(@PathVariable("courseId") Long courseId, @PathVariable("videoId") Long videoId) { healthCourseAppService.deleteVideo(courseId, videoId); return ApiResponse.ok(null); } }