Skip to content

Commit

Permalink
Merge pull request #194 from PawWithU/feat/193-notification-type-add
Browse files Browse the repository at this point in the history
알림 Entity NotificationType 필드 추가 및 수정
  • Loading branch information
kyeong-hyeok authored May 15, 2024
2 parents 57a8d4d + 46155b5 commit 7a428b7
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ public ResponseEntity<ApplicationVolunteerGetOneResponse> getVolunteerOneApplica
, content = @Content(schema = @Schema(implementation = ErrorResponse.class)))
})
@DeleteMapping( "/volunteers/applications/{applicationId}")
public ResponseEntity<ApplicationSuccessResponse> deleteApplication(@AuthenticationPrincipal UserDetails loginUser,
public ResponseEntity<ApplicationSuccessResponse> cancelApplication(@AuthenticationPrincipal UserDetails loginUser,
@PathVariable Long applicationId) {
ApplicationSuccessResponse response = applicationService.deleteApplication(loginUser.getUsername(), applicationId);
ApplicationSuccessResponse response = applicationService.cancelApplication(loginUser.getUsername(), applicationId);
return ResponseEntity.ok(response);
}

Expand All @@ -115,9 +115,9 @@ public ResponseEntity<ApplicationSuccessResponse> confirmApplication(@Authentica
, content = @Content(schema = @Schema(implementation = ErrorResponse.class)))
})
@DeleteMapping( "/intermediaries/applications/{applicationId}")
public ResponseEntity<ApplicationSuccessResponse> cancelApplication(@AuthenticationPrincipal UserDetails loginUser,
@PathVariable Long applicationId) {
ApplicationSuccessResponse response = applicationService.cancelApplication(loginUser.getUsername(), applicationId);
public ResponseEntity<ApplicationSuccessResponse> rejectApplication(@AuthenticationPrincipal UserDetails loginUser,
@PathVariable Long applicationId) {
ApplicationSuccessResponse response = applicationService.rejectApplication(loginUser.getUsername(), applicationId);
return ResponseEntity.ok(response);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.pawwithu.connectdog.domain.fcm.service.FcmService;
import com.pawwithu.connectdog.domain.intermediary.entity.Intermediary;
import com.pawwithu.connectdog.domain.intermediary.repository.IntermediaryRepository;
import com.pawwithu.connectdog.domain.notification.entity.NotificationType;
import com.pawwithu.connectdog.domain.post.entity.Post;
import com.pawwithu.connectdog.domain.post.entity.PostStatus;
import com.pawwithu.connectdog.domain.post.repository.PostRepository;
Expand Down Expand Up @@ -64,7 +65,8 @@ public void volunteerApply(String email, Long postId, VolunteerApplyRequest requ
// 알림 전송
IntermediaryFcm intermediaryFcm = intermediaryFcmRepository.findByIntermediaryId(intermediary.getId()).orElse(null);
if (intermediaryFcm != null) {
fcmService.sendMessageToIntermediary(intermediaryFcm.getFcmToken(), intermediary, volunteer.getProfileImageNum() + "", APPLICATION.getTitle(), APPLICATION.getBodyWithName(volunteer.getNickname()));
fcmService.sendMessageToIntermediary(intermediaryFcm.getFcmToken(), intermediary, volunteer.getProfileImageNum() + "",
NotificationType.APPLICATION, APPLICATION.getTitle(), APPLICATION.getBodyWithName(volunteer.getNickname()));
} else {
log.info("----------이동봉사 신청 알림 전송 실패----------");
}
Expand Down Expand Up @@ -96,7 +98,7 @@ public ApplicationVolunteerGetOneResponse getVolunteerOneApplication(String emai
return oneApplication;
}

public ApplicationSuccessResponse deleteApplication(String email, Long applicationId) {
public ApplicationSuccessResponse cancelApplication(String email, Long applicationId) {
// 이동봉사자
Volunteer volunteer = volunteerRepository.findByEmail(email).orElseThrow(() -> new BadRequestException(VOLUNTEER_NOT_FOUND));
// 신청 내역 + post
Expand All @@ -108,7 +110,8 @@ public ApplicationSuccessResponse deleteApplication(String email, Long applicati
// 알림 전송
IntermediaryFcm intermediaryFcm = intermediaryFcmRepository.findByIntermediaryId(application.getIntermediary().getId()).orElse(null);
if (intermediaryFcm != null) {
fcmService.sendMessageToIntermediary(intermediaryFcm.getFcmToken(), application.getIntermediary(), volunteer.getProfileImageNum() + "", CANCELED.getTitle(), CANCELED.getBodyWithName(volunteer.getNickname()));
fcmService.sendMessageToIntermediary(intermediaryFcm.getFcmToken(), application.getIntermediary(), volunteer.getProfileImageNum() + "",
NotificationType.CANCELED, CANCELED.getTitle(), CANCELED.getBodyWithName(volunteer.getNickname()));
} else {
log.info("----------이동봉사 신청 취소 알림 전송 실패----------");
}
Expand All @@ -128,15 +131,16 @@ public ApplicationSuccessResponse confirmApplication(String email, Long applicat
// 알림 전송
VolunteerFcm volunteerFcm = volunteerFcmRepository.findByVolunteerId(application.getVolunteer().getId()).orElse(null);
if (volunteerFcm != null) {
fcmService.sendMessageToVolunteer(volunteerFcm.getFcmToken(), application.getVolunteer(), post.getMainImage().getImage(), CONFIRM.getTitle(), CONFIRM.getBody());
fcmService.sendMessageToVolunteer(volunteerFcm.getFcmToken(), application.getVolunteer(), post.getMainImage().getImage(),
NotificationType.CONFIRMED, CONFIRM.getTitle(), CONFIRM.getBody());
} else {
log.info("----------이동봉사 승인 알림 전송 실패----------");
}
ApplicationSuccessResponse isSuccess = ApplicationSuccessResponse.of(true);
return isSuccess;
}

public ApplicationSuccessResponse cancelApplication(String email, Long applicationId) {
public ApplicationSuccessResponse rejectApplication(String email, Long applicationId) {
// 이동봉사 중개
Intermediary intermediary = intermediaryRepository.findByEmail(email).orElseThrow(() -> new BadRequestException(INTERMEDIARY_NOT_FOUND));
// 신청 내역 + post
Expand All @@ -148,7 +152,8 @@ public ApplicationSuccessResponse cancelApplication(String email, Long applicati
// 알림 전송
VolunteerFcm volunteerFcm = volunteerFcmRepository.findByVolunteerId(application.getVolunteer().getId()).orElse(null);
if (volunteerFcm != null) {
fcmService.sendMessageToVolunteer(volunteerFcm.getFcmToken(), application.getVolunteer(), post.getMainImage().getImage(), REJECT.getTitle(), REJECT.getBody());
fcmService.sendMessageToVolunteer(volunteerFcm.getFcmToken(), application.getVolunteer(), post.getMainImage().getImage(),
NotificationType.REJECTED, REJECT.getTitle(), REJECT.getBody());
} else {
log.info("----------이동봉사 반려 알림 전송 실패----------");
}
Expand Down Expand Up @@ -218,7 +223,8 @@ public ApplicationSuccessResponse completeApplication(String email, Long applica
// 알림 전송
VolunteerFcm volunteerFcm = volunteerFcmRepository.findByVolunteerId(application.getVolunteer().getId()).orElse(null);
if (volunteerFcm != null) {
fcmService.sendMessageToVolunteer(volunteerFcm.getFcmToken(), application.getVolunteer(), post.getMainImage().getImage(), COMPLETED.getTitle(), COMPLETED.getBody());
fcmService.sendMessageToVolunteer(volunteerFcm.getFcmToken(), application.getVolunteer(), post.getMainImage().getImage(),
NotificationType.COMPLETED, COMPLETED.getTitle(), COMPLETED.getBody());
} else {
log.info("----------이동봉사 완료 알림 전송 실패----------");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.pawwithu.connectdog.domain.fcm.dto.request.IntermediaryFcmRequest;
import com.pawwithu.connectdog.domain.fcm.dto.request.VolunteerFcmRequest;
import com.pawwithu.connectdog.domain.fcm.service.FcmService;
import com.pawwithu.connectdog.domain.notification.entity.NotificationType;
import com.pawwithu.connectdog.error.dto.ErrorResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
Expand Down Expand Up @@ -64,7 +65,7 @@ public ResponseEntity<Void> saveIntermediaryFcm(@AuthenticationPrincipal UserDet
})
@PostMapping("/fcm-test")
public ResponseEntity<Void> testFcmToken(@Valid @RequestBody FcmTokenRequest request) {
fcmService.sendMessageToVolunteer(request.fcmToken(), null, null, APPLICATION.getTitleWithLoc("서울 강남구", "서울 도봉구"), APPLICATION.getBodyWithName("포윗유"));
fcmService.sendMessageToVolunteer(request.fcmToken(), null, null, NotificationType.APPLICATION, APPLICATION.getTitleWithLoc("서울 강남구", "서울 도봉구"), APPLICATION.getBodyWithName("포윗유"));
return ResponseEntity.noContent().build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.pawwithu.connectdog.domain.intermediary.entity.Intermediary;
import com.pawwithu.connectdog.domain.intermediary.repository.IntermediaryRepository;
import com.pawwithu.connectdog.domain.notification.entity.IntermediaryNotification;
import com.pawwithu.connectdog.domain.notification.entity.NotificationType;
import com.pawwithu.connectdog.domain.notification.entity.VolunteerNotification;
import com.pawwithu.connectdog.domain.notification.repository.IntermediaryNotificationRepository;
import com.pawwithu.connectdog.domain.notification.repository.VolunteerNotificationRepository;
Expand Down Expand Up @@ -97,7 +98,8 @@ public String makeMessage(String targetToken, String title, String body) throws
* 알림 푸쉬를 보내는 역할을 하는 메서드
* @param targetToken : 푸쉬 알림을 받을 클라이언트 앱의 식별 토큰
* */
public void sendMessageToVolunteer(String targetToken, Volunteer volunteer, String image, String title, String body) {
public void sendMessageToVolunteer(String targetToken, Volunteer volunteer, String image,
NotificationType notificationType, String title, String body) {

try {
String message = makeMessage(targetToken, title, body);
Expand All @@ -118,6 +120,7 @@ public void sendMessageToVolunteer(String targetToken, Volunteer volunteer, Stri
volunteerNotificationRepository.save(
VolunteerNotification.builder()
.image(image)
.notificationType(notificationType)
.title(title)
.body(body)
.volunteer(volunteer)
Expand All @@ -135,7 +138,8 @@ public void sendMessageToVolunteer(String targetToken, Volunteer volunteer, Stri
}
}

public void sendMessageToIntermediary(String targetToken, Intermediary intermediary, String image, String title, String body) {
public void sendMessageToIntermediary(String targetToken, Intermediary intermediary, String image,
NotificationType notificationType, String title, String body) {

try {
String message = makeMessage(targetToken, title, body);
Expand All @@ -156,6 +160,7 @@ public void sendMessageToIntermediary(String targetToken, Intermediary intermedi
intermediaryNotificationRepository.save(
IntermediaryNotification.builder()
.image(image)
.notificationType(notificationType)
.title(title)
.body(body)
.intermediary(intermediary)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public class IntermediaryNotification extends BaseTimeEntity {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String image;
@Enumerated(EnumType.STRING)
@Column(nullable = false)
private NotificationType notificationType;
@Column(nullable = false)
private String title;
@Column(nullable = false)
Expand All @@ -26,11 +29,12 @@ public class IntermediaryNotification extends BaseTimeEntity {
private Boolean isRead;

@Builder
public IntermediaryNotification(String image, String title, String body, Intermediary intermediary, Boolean isRead) {
this.image = image;
this.title = title;
this.body = body;
this.intermediary = intermediary;
this.isRead = isRead;
}
public IntermediaryNotification(String image, NotificationType notificationType, String title, String body, Intermediary intermediary, Boolean isRead) {
this.image = image;
this.notificationType = notificationType;
this.title = title;
this.body = body;
this.intermediary = intermediary;
this.isRead = isRead;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.pawwithu.connectdog.domain.notification.entity;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
public enum NotificationType {

// 봉사자
REJECTED("반려 확인"), CONFIRMED("승인 확인"), COMPLETED("봉사 완료"), BADGE("배지 확득"),

// 모집자
APPLICATION("신청 확인"), CANCELED("봉사 취소"), REVIEW_REGISTERED("후기 확인"), EXPIRED("모집 마감"), COMPLETED_REQUEST("봉사 완료 요청");

private final String key;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public class VolunteerNotification extends BaseTimeEntity {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String image;
@Enumerated(EnumType.STRING)
@Column(nullable = false)
private NotificationType notificationType;
@Column(nullable = false)
private String title;
@Column(nullable = false)
Expand All @@ -26,8 +29,9 @@ public class VolunteerNotification extends BaseTimeEntity {
private Boolean isRead;

@Builder
public VolunteerNotification(String image, String title, String body, Volunteer volunteer, Boolean isRead) {
public VolunteerNotification(String image, NotificationType notificationType, String title, String body, Volunteer volunteer, Boolean isRead) {
this.image = image;
this.notificationType = notificationType;
this.title = title;
this.body = body;
this.volunteer = volunteer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.pawwithu.connectdog.domain.fcm.entity.IntermediaryFcm;
import com.pawwithu.connectdog.domain.fcm.repository.IntermediaryFcmRepository;
import com.pawwithu.connectdog.domain.fcm.service.FcmService;
import com.pawwithu.connectdog.domain.notification.entity.NotificationType;
import com.pawwithu.connectdog.domain.post.entity.Post;
import com.pawwithu.connectdog.domain.post.repository.PostRepository;
import com.pawwithu.connectdog.domain.review.dto.request.ReviewCreateRequest;
Expand Down Expand Up @@ -81,7 +82,8 @@ public void createReview(String email, Long postId, ReviewCreateRequest request,
// 알림 전송
IntermediaryFcm intermediaryFcm = intermediaryFcmRepository.findByIntermediaryId(post.getIntermediary().getId()).orElse(null);
if (intermediaryFcm != null) {
fcmService.sendMessageToIntermediary(intermediaryFcm.getFcmToken(), post.getIntermediary(), post.getMainImage().getImage(), REVIEW_REGISTERED.getTitle(), REVIEW_REGISTERED.getBody());
fcmService.sendMessageToIntermediary(intermediaryFcm.getFcmToken(), post.getIntermediary(), post.getMainImage().getImage(),
NotificationType.REVIEW_REGISTERED, REVIEW_REGISTERED.getTitle(), REVIEW_REGISTERED.getBody());
} else {
log.info("----------이동봉사 후기 등록 알림 전송 실패----------");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,14 @@ void setUp() {
ApplicationSuccessResponse response = new ApplicationSuccessResponse(true);

//when
given(applicationService.deleteApplication(anyString(), anyLong())).willReturn(response);
given(applicationService.cancelApplication(anyString(), anyLong())).willReturn(response);
ResultActions result = mockMvc.perform(
delete("/volunteers/applications/{applicationId}", applicationId)
);

//then
result.andExpect(status().isOk());
verify(applicationService, times(1)).deleteApplication(anyString(), anyLong());
verify(applicationService, times(1)).cancelApplication(anyString(), anyLong());
}

@Test
Expand All @@ -173,14 +173,14 @@ void setUp() {
ApplicationSuccessResponse response = new ApplicationSuccessResponse(true);

//when
given(applicationService.cancelApplication(anyString(), anyLong())).willReturn(response);
given(applicationService.rejectApplication(anyString(), anyLong())).willReturn(response);
ResultActions result = mockMvc.perform(
delete("/intermediaries/applications/{applicationId}", applicationId)
);

//then
result.andExpect(status().isOk());
verify(applicationService, times(1)).cancelApplication(anyString(), anyLong());
verify(applicationService, times(1)).rejectApplication(anyString(), anyLong());
}

@Test
Expand Down

0 comments on commit 7a428b7

Please sign in to comment.