diff --git a/src/main/java/UMC/career_mate/domain/content/controller/ContentController.java b/src/main/java/UMC/career_mate/domain/content/controller/ContentController.java index e6df6cc..0258f92 100644 --- a/src/main/java/UMC/career_mate/domain/content/controller/ContentController.java +++ b/src/main/java/UMC/career_mate/domain/content/controller/ContentController.java @@ -43,31 +43,43 @@ public ApiResponse uploadContent(@RequestBody ContentRequest return ApiResponse.onSuccess(contentService.uploadContent(contentRequestDTO)); } + @DeleteMapping("/{contentId}") + @Operation( + summary = "컨텐츠 삭제 API", + description = """ + 특정 컨텐츠를 삭제합니다. (관리자용) + Path Parameters: + - 'contentId': 삭제할 콘텐츠 ID + """ + ) + public ApiResponse deleteContent(@PathVariable Long contentId) { + contentService.deleteContent(contentId); + return ApiResponse.onSuccess("컨텐츠 삭제 완료"); + } + @GetMapping @Operation( - summary = "직무별 컨텐츠 조회 API", + summary = "로그인한 사용자의 직무별 컨텐츠 조회 API", description = """ - 특정 직무 ID에 해당하는 컨텐츠를 조회합니다. + 로그인한 사용자의 직무 ID에 해당하는 컨텐츠를 조회합니다. 이때 사용자가 해당 컨텐츠를 스크랩했는지 여부가 담겨 조회됩니다. Query Parameters: - - `jobId`: 직무 ID (필수) - `page`: 페이지 번호 (기본값: 1) - `size`: 페이지 크기 (기본값: 10) """ ) public ApiResponse>> getContentsByJobId( - @RequestParam Long jobId, @RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10") int size, @LoginMember Member member) { - return ApiResponse.onSuccess(contentService.getContentsByJobId(jobId, page, size, member)); + return ApiResponse.onSuccess(contentService.getContentsByJobId(page, size, member)); } @PostMapping("/{contentId}/scrap") @Operation( summary = "컨텐츠 스크랩 API", description = """ - 컨텐츠를 스크랩합니다. + 컨텐츠를 스크랩합니다. Path Parameters: - 'contentId': 스크랩할 콘텐츠 ID """ diff --git a/src/main/java/UMC/career_mate/domain/content/service/ContentService.java b/src/main/java/UMC/career_mate/domain/content/service/ContentService.java index 147321d..4539a4c 100644 --- a/src/main/java/UMC/career_mate/domain/content/service/ContentService.java +++ b/src/main/java/UMC/career_mate/domain/content/service/ContentService.java @@ -1,6 +1,5 @@ package UMC.career_mate.domain.content.service; - import UMC.career_mate.domain.content.Content; import UMC.career_mate.domain.content.converter.ContentConverter; import UMC.career_mate.domain.content.dto.request.ContentRequestDTO; @@ -11,6 +10,8 @@ import UMC.career_mate.domain.job.Service.JobService; import UMC.career_mate.domain.member.Member; import UMC.career_mate.global.common.PageResponseDTO; +import UMC.career_mate.global.response.exception.GeneralException; +import UMC.career_mate.global.response.exception.code.CommonErrorCode; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; @@ -39,10 +40,22 @@ public ContentResponseDTO uploadContent(ContentRequestDTO contentRequestDTO) { return ContentConverter.toContentResponseDTO(content); } + public void deleteContent(Long contentId) { + // 컨텐츠 존재 여부 확인 + Content content = contentRepository.findById(contentId) + .orElseThrow(() -> new GeneralException(CommonErrorCode.NOT_FOUND_CONTENT)); + + contentRepository.delete(content); + } + @Transactional(readOnly = true) - public PageResponseDTO> getContentsByJobId(Long jobId, int page, int size, Member member) { - // Job ID 유효성 확인 - jobService.findJobById(jobId); + public PageResponseDTO> getContentsByJobId(int page, int size, Member member) { + + // 로그인한 사용자의 직무 ID 확인 + Long jobId = member.getJob().getId(); + if (jobId == null) { + throw new GeneralException(CommonErrorCode.NOT_FOUND_JOB); + } PageRequest pageRequest = PageRequest.of(page - 1, size); Page contentPage = contentRepository.findByJobId(jobId, pageRequest); diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 3d7808a..caf4dfc 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,3 +1,3 @@ spring: profiles: - active: dev + active: dev \ No newline at end of file