From 167cc0c96be220b0945408a716f48d778cbc7856 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A0=84=ED=95=B4=EC=84=B1?= Date: Sat, 30 Sep 2023 14:47:08 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=B5=9C=EA=B7=BC=EA=B2=80=EC=83=89?= =?UTF-8?q?=EC=96=B4=20=EB=AA=A8=EB=91=90=20=EC=82=AD=EC=A0=9C=20(#42)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nplusone/ui/search/SearchHistoryController.kt | 12 +++++++++++- .../domain/search/history/SearchHistoryRepository.kt | 1 + .../domain/search/history/SearchHistoryService.kt | 9 ++++++++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/nplusone-api/src/main/kotlin/com/haeseong/nplusone/ui/search/SearchHistoryController.kt b/nplusone-api/src/main/kotlin/com/haeseong/nplusone/ui/search/SearchHistoryController.kt index dc2d4c4..c355f3d 100644 --- a/nplusone-api/src/main/kotlin/com/haeseong/nplusone/ui/search/SearchHistoryController.kt +++ b/nplusone-api/src/main/kotlin/com/haeseong/nplusone/ui/search/SearchHistoryController.kt @@ -40,4 +40,14 @@ class SearchHistoryController( ) return ApiResponse.success() } -} \ No newline at end of file + + @DeleteMapping + fun deleteAll( + @ApiIgnore authentication: Authentication, + ): ApiResponse<*> { + searchHistoryService.deleteAll( + memberId = authentication.resolveMemberId(), + ) + return ApiResponse.success() + } +} diff --git a/nplusone-domain/src/main/kotlin/com/haeseong/nplusone/domain/search/history/SearchHistoryRepository.kt b/nplusone-domain/src/main/kotlin/com/haeseong/nplusone/domain/search/history/SearchHistoryRepository.kt index b2b0d9b..bb82880 100644 --- a/nplusone-domain/src/main/kotlin/com/haeseong/nplusone/domain/search/history/SearchHistoryRepository.kt +++ b/nplusone-domain/src/main/kotlin/com/haeseong/nplusone/domain/search/history/SearchHistoryRepository.kt @@ -11,6 +11,7 @@ import java.time.LocalDateTime interface SearchHistoryRepository : JpaRepository { fun findByMember_memberId(memberId: Long, pageable: Pageable): List fun findByMember_memberIdAndSearchHistoryId(memberId: Long, searchHistoryId: Long): SearchHistory? + fun findByMember_memberId(memberId: Long): List @Query( value = "SELECT search_word as searchWord, count(search_history_id) AS searchCount " + "FROM search_history " + diff --git a/nplusone-domain/src/main/kotlin/com/haeseong/nplusone/domain/search/history/SearchHistoryService.kt b/nplusone-domain/src/main/kotlin/com/haeseong/nplusone/domain/search/history/SearchHistoryService.kt index 1b8b522..47ce249 100644 --- a/nplusone-domain/src/main/kotlin/com/haeseong/nplusone/domain/search/history/SearchHistoryService.kt +++ b/nplusone-domain/src/main/kotlin/com/haeseong/nplusone/domain/search/history/SearchHistoryService.kt @@ -10,6 +10,7 @@ import org.springframework.transaction.annotation.Transactional interface SearchHistoryService { fun record(searchEvent: SearchEvent): SearchHistoryVo fun delete(memberId: Long, searchHistoryId: Long) + fun deleteAll(memberId: Long) fun getSearchHistories(memberId: Long): List } @@ -48,10 +49,16 @@ class SearchHistoryServiceImpl( ?.run { searchHistoryRepository.delete(this) } } + @Transactional + override fun deleteAll(memberId: Long) { + searchHistoryRepository.findByMember_memberId(memberId) + .forEach { searchHistoryRepository.delete(it) } + } + override fun getSearchHistories(memberId: Long): List { return searchHistoryRepository.findByMember_memberId( memberId = memberId, pageable = PageRequest.of(0, 10, Sort.Direction.DESC, "searchedAt") ).map { SearchHistoryVo.from(it) } } -} \ No newline at end of file +}