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.HealthCourseOptionVO; 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 org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; import java.io.IOException; import java.util.List; @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); } @GetMapping("/health-courses/options") public ApiResponse> options(@RequestParam(required = false) String keyword) { return ApiResponse.ok(healthCourseAppService.options(keyword)); } @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 priceType) { return ApiResponse.ok(healthCourseAppService.pageVideos(courseId, page, pageSize, chapterName, priceType)); } @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); } @GetMapping("/health-course-video-resources") public ApiResponse> pageVideoResources(@RequestParam(required = false, defaultValue = "1") int page, @RequestParam(required = false, defaultValue = "10") int pageSize, @RequestParam(required = false) String courseKeyword, @RequestParam(required = false) Long courseId, @RequestParam(required = false) Integer courseType, @RequestParam(required = false) String chapterName, @RequestParam(required = false) Integer priceType, @RequestParam(required = false) Integer status) { return ApiResponse.ok(healthCourseAppService.pageVideoResources(page, pageSize, courseKeyword, courseId, courseType, chapterName, priceType, status)); } @GetMapping("/health-course-video-resources/import-template") public void downloadVideoResourceTemplate(HttpServletResponse response) throws IOException { healthCourseAppService.downloadVideoResourceTemplate(response); } @GetMapping("/health-course-video-resources/{id}") public ApiResponse detailVideoResource(@PathVariable("id") Long id) { return ApiResponse.ok(healthCourseAppService.detailVideoResource(id)); } @PostMapping("/health-course-video-resources") public ApiResponse createVideoResource(@Valid @RequestBody HealthCourseVideoSaveRequest req) { return ApiResponse.ok(healthCourseAppService.createVideoResource(req)); } @PutMapping("/health-course-video-resources/{id}") public ApiResponse updateVideoResource(@PathVariable("id") Long id, @Valid @RequestBody HealthCourseVideoSaveRequest req) { return ApiResponse.ok(healthCourseAppService.updateVideoResource(id, req)); } @DeleteMapping("/health-course-video-resources/{id}") public ApiResponse deleteVideoResource(@PathVariable("id") Long id) { healthCourseAppService.deleteVideoResource(id); return ApiResponse.ok(null); } @PostMapping("/health-course-video-resources/import") public ApiResponse importVideoResources(@RequestParam("file") MultipartFile file) throws IOException { healthCourseAppService.importVideoResources(file); return ApiResponse.ok(null); } }