Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ public interface NotificationRepository extends JpaRepository<Notification, Long
List<Notification> findAllByMemberId(Long memberId);

Long countByMemberAndIsReadIsFalse(Member member);

void deleteAllByMember(Member member);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -27,6 +33,15 @@ public class TestController {
private final EmbeddingRequestHandler embeddingRequestHandler;
private final EmbeddingsService embeddingsService;
private final PickRepository pickRepository;
private final NotificationService notificationService;

@Operation(summary = "알림 제거", description = "회원에게 생성된 모든 알림을 제거")
@DeleteMapping("/notifications")
public ResponseEntity<com.dreamypatisiel.devdevdev.web.dto.response.BasicResponse<Void>> delete() {
Authentication authentication = AuthenticationMemberUtils.getAuthentication();
notificationService.deleteAllByMember(authentication);
return ResponseEntity.ok(com.dreamypatisiel.devdevdev.web.dto.response.BasicResponse.success());
}

@GetMapping("/members")
public BasicResponse<Member> getMembers() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,53 @@ void getUnreadNotificationCount() {
assertThat(response).isEqualTo(7);
}

@Test
@DisplayName("회원이 알림을 전체 삭제한다.")
void deleteAllByMember() {
// given
SocialMemberDto socialMemberDto = createSocialDto(
"dreamy", "꿈빛파티시엘", "행복한 꿈빛", "pass123", "[email protected]", "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<TechArticle> techArticles = new ArrayList<>();
List<Notification> 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)
Expand Down
Loading