-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…github.com/woowacourse-teams/2023-emmsale into Feature/#664-행사_DTO의_imageUrl을_S3의_데이터로_대체
- Loading branch information
Showing
17 changed files
with
405 additions
and
13 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
backend/emm-sale/src/main/java/com/emmsale/event_publisher/CommentNotificationEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.emmsale.event_publisher; | ||
|
||
import com.emmsale.comment.domain.Comment; | ||
import com.emmsale.member.domain.Member; | ||
import java.time.LocalDateTime; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
@Getter | ||
public class CommentNotificationEvent { | ||
|
||
private static final String UPDATE_NOTIFICATION_COMMENT_TYPE = "COMMENT"; | ||
|
||
private final Long receiverId; | ||
private final Long redirectId; | ||
private final LocalDateTime createdAt; | ||
private final String notificationType; | ||
private final String content; | ||
private final String writer; | ||
private final String writerImageUrl; | ||
|
||
public static CommentNotificationEvent of(final Comment comment, final Comment trigger) { | ||
final Member member = comment.getMember(); | ||
final Member triggerMember = trigger.getMember(); | ||
|
||
return new CommentNotificationEvent( | ||
member.getId(), | ||
trigger.getId(), | ||
LocalDateTime.now(), | ||
UPDATE_NOTIFICATION_COMMENT_TYPE, | ||
trigger.getContent(), | ||
triggerMember.getName(), | ||
triggerMember.getImageUrl() | ||
); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
backend/emm-sale/src/main/java/com/emmsale/event_publisher/EventNotificationEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.emmsale.event_publisher; | ||
|
||
import com.emmsale.event.domain.Event; | ||
import java.time.LocalDateTime; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
@Getter | ||
public class EventNotificationEvent { | ||
|
||
private static final String UPDATE_NOTIFICATION_EVENT_TYPE = "EVENT"; | ||
|
||
private final Long receiverId; | ||
private final Long redirectId; | ||
private final String notificationType; | ||
private final LocalDateTime createdAt; | ||
private final String title; | ||
|
||
public static EventNotificationEvent of(final Event event, final Long receiverId) { | ||
return new EventNotificationEvent( | ||
receiverId, | ||
event.getId(), | ||
UPDATE_NOTIFICATION_EVENT_TYPE, | ||
LocalDateTime.now(), | ||
event.getName() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...le/src/main/java/com/emmsale/notification/application/dto/CommentNotificationMessage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.emmsale.notification.application.dto; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
@Getter | ||
public class CommentNotificationMessage { | ||
|
||
@JsonProperty("validate_only") | ||
private final boolean validateOnly; | ||
private final Message message; | ||
|
||
@RequiredArgsConstructor | ||
@Getter | ||
public static class Message { | ||
|
||
private final Data data; | ||
private final String token; | ||
} | ||
|
||
@RequiredArgsConstructor | ||
@Getter | ||
public static class Data { | ||
|
||
private final String receiverId; | ||
private final String redirectId; | ||
private final String notificationType; | ||
private final String createdAt; | ||
private final String content; | ||
private final String writer; | ||
private final String writerImageUrl; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...sale/src/main/java/com/emmsale/notification/application/dto/EventNotificationMessage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.emmsale.notification.application.dto; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
@Getter | ||
public class EventNotificationMessage { | ||
|
||
@JsonProperty("validate_only") | ||
private final boolean validateOnly; | ||
private final Message message; | ||
|
||
@RequiredArgsConstructor | ||
@Getter | ||
public static class Message { | ||
|
||
private final Data data; | ||
private final String token; | ||
} | ||
|
||
@RequiredArgsConstructor | ||
@Getter | ||
public static class Data { | ||
|
||
private final String receiverId; | ||
private final String redirectId; | ||
private final String notificationType; | ||
private final String createdAt; | ||
private final String title; | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
...a/com/emmsale/notification/application/generator/CommentNotificationMessageGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.emmsale.notification.application.generator; | ||
|
||
import static com.emmsale.notification.exception.NotificationExceptionType.BAD_REQUEST_MEMBER_ID; | ||
import static com.emmsale.notification.exception.NotificationExceptionType.CONVERTING_JSON_ERROR; | ||
|
||
import com.emmsale.member.domain.MemberRepository; | ||
import com.emmsale.notification.application.dto.CommentNotificationMessage; | ||
import com.emmsale.notification.application.dto.CommentNotificationMessage.Data; | ||
import com.emmsale.notification.application.dto.CommentNotificationMessage.Message; | ||
import com.emmsale.notification.domain.Notification; | ||
import com.emmsale.notification.exception.NotificationException; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
public class CommentNotificationMessageGenerator implements NotificationMessageGenerator { | ||
|
||
private final Notification notification; | ||
|
||
@Override | ||
public String makeMessage( | ||
final String targetToken, | ||
final ObjectMapper objectMapper, | ||
final MemberRepository memberRepository | ||
) { | ||
|
||
final String jsonData = notification.getJsonData(); | ||
|
||
try { | ||
|
||
final Data data = objectMapper.readValue(jsonData, Data.class); | ||
|
||
validateIsExistedReceiver(memberRepository, Long.valueOf(data.getReceiverId())); | ||
|
||
final CommentNotificationMessage message = new CommentNotificationMessage( | ||
DEFAULT_VALIDATE_ONLY, new Message(data, targetToken) | ||
); | ||
|
||
return objectMapper.writeValueAsString(message); | ||
|
||
} catch (JsonProcessingException e) { | ||
throw new NotificationException(CONVERTING_JSON_ERROR); | ||
} | ||
} | ||
|
||
private void validateIsExistedReceiver(final MemberRepository memberRepository, | ||
final Long receiverId) { | ||
if (!memberRepository.existsById(receiverId)) { | ||
throw new NotificationException(BAD_REQUEST_MEMBER_ID); | ||
} | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
...ava/com/emmsale/notification/application/generator/EventNotificationMessageGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.emmsale.notification.application.generator; | ||
|
||
import static com.emmsale.notification.application.dto.EventNotificationMessage.Data; | ||
import static com.emmsale.notification.exception.NotificationExceptionType.BAD_REQUEST_MEMBER_ID; | ||
import static com.emmsale.notification.exception.NotificationExceptionType.CONVERTING_JSON_ERROR; | ||
|
||
import com.emmsale.member.domain.MemberRepository; | ||
import com.emmsale.notification.application.dto.EventNotificationMessage; | ||
import com.emmsale.notification.application.dto.EventNotificationMessage.Message; | ||
import com.emmsale.notification.domain.Notification; | ||
import com.emmsale.notification.exception.NotificationException; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
public class EventNotificationMessageGenerator implements NotificationMessageGenerator { | ||
|
||
private final Notification notification; | ||
|
||
@Override | ||
public String makeMessage( | ||
final String targetToken, | ||
final ObjectMapper objectMapper, | ||
final MemberRepository memberRepository | ||
) { | ||
final String jsonData = notification.getJsonData(); | ||
|
||
try { | ||
|
||
final Data data = objectMapper.readValue(jsonData, Data.class); | ||
|
||
validateIsExistedReceiver(memberRepository, Long.valueOf(data.getReceiverId())); | ||
|
||
final EventNotificationMessage message = new EventNotificationMessage( | ||
DEFAULT_VALIDATE_ONLY, new Message(data, targetToken) | ||
); | ||
|
||
return objectMapper.writeValueAsString(message); | ||
|
||
} catch (JsonProcessingException e) { | ||
throw new NotificationException(CONVERTING_JSON_ERROR); | ||
} | ||
} | ||
|
||
private void validateIsExistedReceiver(final MemberRepository memberRepository, | ||
final Long receiverId) { | ||
if (!memberRepository.existsById(receiverId)) { | ||
throw new NotificationException(BAD_REQUEST_MEMBER_ID); | ||
} | ||
} | ||
} |
Oops, something went wrong.