From e0415f984bbdba5a16f2809b459bdee66e50e4af Mon Sep 17 00:00:00 2001 From: soyoung Date: Sun, 4 May 2025 13:01:34 +0900 Subject: [PATCH 1/4] =?UTF-8?q?feat(notification):=20=EC=95=8C=EB=A6=BC=20?= =?UTF-8?q?=EC=9D=BC=EA=B4=84=20=EC=82=AD=EC=A0=9C=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../notification/NotificationRepository.java | 2 ++ .../service/notification/NotificationService.java | 13 +++++++++++++ .../notification/NotificationController.java | 9 +++++++++ 3 files changed, 24 insertions(+) diff --git a/src/main/java/com/dreamypatisiel/devdevdev/domain/repository/notification/NotificationRepository.java b/src/main/java/com/dreamypatisiel/devdevdev/domain/repository/notification/NotificationRepository.java index a8959b78..31d71ca5 100644 --- a/src/main/java/com/dreamypatisiel/devdevdev/domain/repository/notification/NotificationRepository.java +++ b/src/main/java/com/dreamypatisiel/devdevdev/domain/repository/notification/NotificationRepository.java @@ -13,4 +13,6 @@ public interface NotificationRepository extends JpaRepository findAllByMemberId(Long memberId); Long countByMemberAndIsReadIsFalse(Member member); + + void deleteAllByMember(Member member); } diff --git a/src/main/java/com/dreamypatisiel/devdevdev/domain/service/notification/NotificationService.java b/src/main/java/com/dreamypatisiel/devdevdev/domain/service/notification/NotificationService.java index d01f99c9..f95ffd14 100644 --- a/src/main/java/com/dreamypatisiel/devdevdev/domain/service/notification/NotificationService.java +++ b/src/main/java/com/dreamypatisiel/devdevdev/domain/service/notification/NotificationService.java @@ -367,4 +367,17 @@ public Long getUnreadNotificationCount(Authentication authentication) { // 회원이 읽지 않은 알림 개수 조회 return notificationRepository.countByMemberAndIsReadFalse(findMember); } + + /** + * @Note: 회원의 모든 알림 삭제 + * @Author: 유소영 + */ + @Transactional + public void deleteAllByMember(Authentication authentication) { + // 회원 조회 + Member findMember = memberProvider.getMemberByAuthentication(authentication); + + // 회원의 모든 알림 삭제 + notificationRepository.deleteAllByMember(findMember); + } } diff --git a/src/main/java/com/dreamypatisiel/devdevdev/web/controller/notification/NotificationController.java b/src/main/java/com/dreamypatisiel/devdevdev/web/controller/notification/NotificationController.java index 4eb9250e..bf5c9537 100644 --- a/src/main/java/com/dreamypatisiel/devdevdev/web/controller/notification/NotificationController.java +++ b/src/main/java/com/dreamypatisiel/devdevdev/web/controller/notification/NotificationController.java @@ -119,4 +119,13 @@ public ResponseEntity> publish( return ResponseEntity.ok(BasicResponse.success()); } + + // TODO: 개발용 API -> 추후 제거 필요 + @Operation(summary = "알림 제거", description = "회원에게 생성된 모든 알림을 제거") + @DeleteMapping("/notifications") + public ResponseEntity> delete() { + Authentication authentication = AuthenticationMemberUtils.getAuthentication(); + notificationService.deleteAllByMember(authentication); + return ResponseEntity.ok(BasicResponse.success()); + } } From 573f77bd18d2ffc718f45b1af6b0fc8ed8170c28 Mon Sep 17 00:00:00 2001 From: soyoung Date: Sun, 4 May 2025 13:07:36 +0900 Subject: [PATCH 2/4] =?UTF-8?q?test(notification):=20=EC=95=8C=EB=A6=BC=20?= =?UTF-8?q?=EC=9D=BC=EA=B4=84=20=EC=82=AD=EC=A0=9C=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../notification/NotificationServiceTest.java | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/test/java/com/dreamypatisiel/devdevdev/domain/service/notification/NotificationServiceTest.java b/src/test/java/com/dreamypatisiel/devdevdev/domain/service/notification/NotificationServiceTest.java index 7fcad7b4..5ba792d3 100644 --- a/src/test/java/com/dreamypatisiel/devdevdev/domain/service/notification/NotificationServiceTest.java +++ b/src/test/java/com/dreamypatisiel/devdevdev/domain/service/notification/NotificationServiceTest.java @@ -609,6 +609,53 @@ void getUnreadNotificationCount() { assertThat(response).isEqualTo(7); } + @Test + @DisplayName("회원이 알림을 전체 삭제한다.") + void deleteAllByMember() { + // given + SocialMemberDto socialMemberDto = createSocialDto( + "dreamy", "꿈빛파티시엘", "행복한 꿈빛", "pass123", "dreamy@kakao.com", "KAKAO", "ROLE_USER" + ); + Member member = Member.createMemberBy(socialMemberDto); + memberRepository.save(member); + + UserPrincipal principal = UserPrincipal.createByMember(member); + SecurityContext context = SecurityContextHolder.getContext(); + context.setAuthentication(new OAuth2AuthenticationToken( + principal, principal.getAuthorities(), principal.getSocialType().name() + )); + Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); + + // 알림 10개 저장 + Company company = createCompany("꿈빛 파티시엘", "https://example.com/company.png", "https://example.com", + "https://example.com"); + companyRepository.save(company); + + List techArticles = new ArrayList<>(); + List notifications = new ArrayList<>(); + + for (int i = 0; i < 10; i++) { + TechArticle techArticle = TechArticle.createTechArticle(new Title("기술블로그 제목 "+i), new Url("https://example.com"), + new Count(1L), new Count(1L), new Count(1L), new Count(1L), null, company); + + techArticles.add(techArticle); + notifications.add(createNotification(member, "알림 메시지 " + i, NotificationType.SUBSCRIPTION, false, techArticle)); + } + + techArticleRepository.saveAll(techArticles); + notificationRepository.saveAll(notifications); + + em.flush(); + em.clear(); + + // when + notificationService.deleteAllByMember(authentication); + + // then + long response = notificationService.getUnreadNotificationCount(authentication); + assertThat(response).isEqualTo(0); + } + private static Subscription createSubscription(Company company, Member member) { return Subscription.builder() .company(company) From e771fe09f74e8210cfc6e80d04f3410ec794dd1f Mon Sep 17 00:00:00 2001 From: soyoung Date: Sun, 4 May 2025 13:53:41 +0900 Subject: [PATCH 3/4] =?UTF-8?q?fix(notification):=20=EC=BD=94=EB=93=9C?= =?UTF-8?q?=EB=A6=AC=EB=B7=B0=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../devdevdev/test/TestController.java | 16 ++++++++++++++++ .../notification/NotificationController.java | 11 ----------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/dreamypatisiel/devdevdev/test/TestController.java b/src/main/java/com/dreamypatisiel/devdevdev/test/TestController.java index a84f0a7a..81c5564f 100644 --- a/src/main/java/com/dreamypatisiel/devdevdev/test/TestController.java +++ b/src/main/java/com/dreamypatisiel/devdevdev/test/TestController.java @@ -1,9 +1,14 @@ package com.dreamypatisiel.devdevdev.test; import com.dreamypatisiel.devdevdev.domain.repository.pick.PickRepository; +import com.dreamypatisiel.devdevdev.domain.service.notification.NotificationService; +import com.dreamypatisiel.devdevdev.global.utils.AuthenticationMemberUtils; import com.dreamypatisiel.devdevdev.openai.embeddings.EmbeddingRequestHandler; import com.dreamypatisiel.devdevdev.openai.embeddings.EmbeddingsService; import java.util.List; + +import com.dreamypatisiel.devdevdev.web.dto.response.BasicResponse; +import io.swagger.v3.oas.annotations.Operation; import lombok.Data; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -12,6 +17,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -27,6 +33,16 @@ public class TestController { private final EmbeddingRequestHandler embeddingRequestHandler; private final EmbeddingsService embeddingsService; private final PickRepository pickRepository; + private final NotificationService notificationService; + + @Operation(summary = "알림 제거", description = "회원에게 생성된 모든 알림을 제거") + @DeleteMapping("/notifications") + @Profile("dev") + public ResponseEntity> delete() { + Authentication authentication = AuthenticationMemberUtils.getAuthentication(); + notificationService.deleteAllByMember(authentication); + return ResponseEntity.ok(com.dreamypatisiel.devdevdev.web.dto.response.BasicResponse.success()); + } @GetMapping("/members") public BasicResponse getMembers() { diff --git a/src/main/java/com/dreamypatisiel/devdevdev/web/controller/notification/NotificationController.java b/src/main/java/com/dreamypatisiel/devdevdev/web/controller/notification/NotificationController.java index bf5c9537..d42a4a61 100644 --- a/src/main/java/com/dreamypatisiel/devdevdev/web/controller/notification/NotificationController.java +++ b/src/main/java/com/dreamypatisiel/devdevdev/web/controller/notification/NotificationController.java @@ -25,8 +25,6 @@ import org.springframework.web.bind.annotation.*; import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; -import org.springframework.security.core.Authentication; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PatchMapping; @@ -119,13 +117,4 @@ public ResponseEntity> publish( return ResponseEntity.ok(BasicResponse.success()); } - - // TODO: 개발용 API -> 추후 제거 필요 - @Operation(summary = "알림 제거", description = "회원에게 생성된 모든 알림을 제거") - @DeleteMapping("/notifications") - public ResponseEntity> delete() { - Authentication authentication = AuthenticationMemberUtils.getAuthentication(); - notificationService.deleteAllByMember(authentication); - return ResponseEntity.ok(BasicResponse.success()); - } } From 82091a477b912cb8599b44e19969e89f2cf67752 Mon Sep 17 00:00:00 2001 From: soyoung Date: Sun, 4 May 2025 13:55:38 +0900 Subject: [PATCH 4/4] =?UTF-8?q?fix(notification):=20=EC=BD=94=EB=93=9C?= =?UTF-8?q?=EB=A6=AC=EB=B7=B0=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/dreamypatisiel/devdevdev/test/TestController.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/dreamypatisiel/devdevdev/test/TestController.java b/src/main/java/com/dreamypatisiel/devdevdev/test/TestController.java index 81c5564f..294e7929 100644 --- a/src/main/java/com/dreamypatisiel/devdevdev/test/TestController.java +++ b/src/main/java/com/dreamypatisiel/devdevdev/test/TestController.java @@ -37,7 +37,6 @@ public class TestController { @Operation(summary = "알림 제거", description = "회원에게 생성된 모든 알림을 제거") @DeleteMapping("/notifications") - @Profile("dev") public ResponseEntity> delete() { Authentication authentication = AuthenticationMemberUtils.getAuthentication(); notificationService.deleteAllByMember(authentication);