diff --git a/src/main/java/project/backend/domain/culturalevent/controller/CulturalEventController.java b/src/main/java/project/backend/domain/culturalevent/controller/CulturalEventController.java index 33eb046..e9fc402 100644 --- a/src/main/java/project/backend/domain/culturalevent/controller/CulturalEventController.java +++ b/src/main/java/project/backend/domain/culturalevent/controller/CulturalEventController.java @@ -143,6 +143,13 @@ public ResponseEntity> getCulturalEventR return ResponseEntity.status(HttpStatus.OK).body(culturalEventSearchKeywordListDtoList); } + + @ApiOperation(value = "문화생활 최근 검색어 삭제") + @DeleteMapping("/recent-keywords/{id}") + public ResponseEntity deleteCulturalEventRecentKeyword(@Positive @PathVariable Long id) { + culturalEventSearchKeywordService.deleteCulturalEventSearchKeyword(id); + return ResponseEntity.status(HttpStatus.NO_CONTENT).body(null); + } } diff --git a/src/main/java/project/backend/domain/keyword/service/CulturalEventSearchKeywordService.java b/src/main/java/project/backend/domain/keyword/service/CulturalEventSearchKeywordService.java index 0ba4bc0..0cefca9 100644 --- a/src/main/java/project/backend/domain/keyword/service/CulturalEventSearchKeywordService.java +++ b/src/main/java/project/backend/domain/keyword/service/CulturalEventSearchKeywordService.java @@ -6,6 +6,7 @@ import project.backend.domain.keyword.entity.CulturalEventSearchKeyword; import project.backend.domain.keyword.repository.CulturalEventSearchKeywordRepository; import project.backend.domain.member.entity.Member; +import project.backend.domain.member.service.MemberJwtService; import project.backend.global.error.exception.BusinessException; import project.backend.global.error.exception.ErrorCode; @@ -21,6 +22,7 @@ public class CulturalEventSearchKeywordService { private final CulturalEventSearchKeywordRepository culturalEventSearchKeywordRepository; + private final MemberJwtService memberJwtService; /** @@ -68,10 +70,20 @@ public List getCulturalEventRecentKeywordList(Member return culturalEventSearchKeywordRepository.findByIsRecentTrueAndMemberOrderByUpdatedDateDesc(member); } - // 키워드 삭제 + /** + * 최근 검색어 삭제 + * + * @param id + */ public void deleteCulturalEventSearchKeyword(Long id) { + // 내가 검색한 키워드인지 확인 + Member member = memberJwtService.getMember(); CulturalEventSearchKeyword culturalEventSearchKeyword = verifiedCulturalEventSearchKeyword(id); - culturalEventSearchKeyword.isRecent = true; + + if (member != culturalEventSearchKeyword.getMember()) { + throw new BusinessException(ErrorCode.CULTURAL_EVENT_SEARCH_KEYWORD_DELETE_FAIL); + } + culturalEventSearchKeyword.isRecent = false; } diff --git a/src/main/java/project/backend/global/error/exception/ErrorCode.java b/src/main/java/project/backend/global/error/exception/ErrorCode.java index 5fdd11d..fb0b23f 100644 --- a/src/main/java/project/backend/global/error/exception/ErrorCode.java +++ b/src/main/java/project/backend/global/error/exception/ErrorCode.java @@ -48,10 +48,10 @@ public enum ErrorCode { CULTURAL_EVENT_CATEGORY_NOT_FOUND(404, "CEC001", "문화생활 카테고리를 찾을 수 없습니다."), // Traffic - VERSION_NOT_FOUND(404, "V001", "버전을 찾을 수 없습니다.") + VERSION_NOT_FOUND(404, "V001", "버전을 찾을 수 없습니다."), - - ; + // Cultural Event Search Keyword + CULTURAL_EVENT_SEARCH_KEYWORD_DELETE_FAIL(400, "CESK001", "내 최근 검색어만 삭제할 수 있습니다."); private final String code; private final String message;