Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HotFix : 일기 작성 알림 요청 메세지 수정 #194

Merged
merged 12 commits into from
Sep 5, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class FirstAlarmDelayStrategy implements ScheduleTimeStrategy{

@Override
public Optional<RelativeTime> calculateAlarmDelayTime() {
return Optional.of(new RelativeTime(1, TimeUnit.MINUTES));
return Optional.of(new RelativeTime(20, TimeUnit.SECONDS));
}

}
34 changes: 28 additions & 6 deletions clody-domain/src/main/java/com/clody/domain/reply/Reply.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,39 @@ public static Reply createFastDynamicReply(User user, LocalDate createdDate) {
}

public void readReply() {
this.is_read = true;
if (this.replyInfo.checkReadable()) {
this.is_read = true;
}
}

public boolean isNotRead() {
public boolean userNotRead() {
return !this.is_read;
}

public boolean isRead() {
public boolean checkUserReadReply() {
return this.is_read;
}

public UserReplyReadStatus processReadStatus(Reply reply) {

//답변이 빈 경우, 읽지 못함
if (reply.getContent() == null) {
return UserReplyReadStatus.UNREADY;
}

//정적 답변은 컨텐츠가 이미 존재함
if (reply.getReplyType().equals(ReplyType.STATIC) && reply.userNotRead()) {
return UserReplyReadStatus.UNREADY;
}
//답변은 준비되었고, 읽지 않은 상태
if (reply.userNotRead()) {
return UserReplyReadStatus.READY_NOT_READ;
}

//답변도 존재하고, 읽은 상태
return UserReplyReadStatus.READY_READ;
}

public Integer getVersion() {
return this.replyInfo.getVersion();
}
Expand All @@ -102,7 +124,7 @@ private ReplyProcessStatus getProcessStatus() {
}

public void insertContentFromRody(String content, Integer messageVersion) {
if (messageVersion < getVersion() && getProcessStatus()== ReplyProcessStatus.UPDATED) {
if (messageVersion < getVersion() && getProcessStatus() == ReplyProcessStatus.UPDATED) {
throw new BusinessException(ErrorType.USER_UPDATED_DIARY);
}
// 내용 업데이트
Expand All @@ -114,11 +136,11 @@ public boolean checkReplyDeleted() {
return this.replyInfo.isDeleted();
}

public void delete(){
public void delete() {
this.replyInfo = replyInfo.delete();
}

public boolean checkIfFirstReply(){
public boolean checkIfFirstReply() {
return this.replyType == ReplyType.FIRST;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ public void updateStatus(ReplyProcessStatus replyProcessStatus) {
}
}

public boolean checkReadable(){
return this.replyProcessStatus.equals(ReplyProcessStatus.SUCCEED);
}

public void incrementVersion() {
this.version++;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
package com.clody.domain.reply.dto;

import com.clody.domain.reply.Reply;
import com.clody.domain.reply.ReplyType;

public record ReplyResponse(
String nickname,
String content,
int month,
int date,
ReplyType replyType
) {
Boolean isRead) {

public static ReplyResponse of(String nickName, String content, int month, int date, ReplyType replyType) {
return new ReplyResponse(nickName, content, month, date, replyType);
public static ReplyResponse of(String nickName, String content, int month, int date, boolean isRead) {
return new ReplyResponse(nickName, content, month, date, isRead);
}

public static ReplyResponse from(Reply reply) {
return new ReplyResponse(reply.getUser().getNickName(), reply.getContent(),
reply.getCreatedAt().getMonthValue(), reply.getCreatedAt().getDayOfMonth(), reply.getReplyType());
reply.getCreatedAt().getMonthValue(), reply.getCreatedAt().getDayOfMonth(), reply.checkUserReadReply());
}
}
110 changes: 110 additions & 0 deletions clody-domain/src/test/java/com/clody/domain/reply/ReplyStatusTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package com.clody.domain.reply;

import static org.assertj.core.api.Assertions.assertThat;

import com.clody.domain.user.Platform;
import com.clody.domain.user.User;
import java.time.LocalDate;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;

@ExtendWith(MockitoExtension.class)
public class ReplyStatusTest {


@Test
@DisplayName("답장이 준비되지 않았을 경우, isRead == false를 반환한다.")
public void testReadIfUnready(){
//given
User user = User.createNewUser("1L", Platform.KAKAO, null, "hyunw9", "email");
LocalDate today = LocalDate.now();
Reply dynamicReply = Reply.createDynamicReply(user, today);
Reply staticReply = Reply.createStaticReply(user,"static Reply" ,today);
Reply firstReply = Reply.createFastDynamicReply(user, today);

//when
dynamicReply.readReply();
staticReply.readReply();
firstReply.readReply();

//then
assertThat(dynamicReply.checkUserReadReply()).isEqualTo(false);
assertThat(staticReply.checkUserReadReply()).isEqualTo(true);
assertThat(firstReply.checkUserReadReply()).isEqualTo(false);

}

@Test
@DisplayName("답장이 준비되지 않은 상태에서 status 반환시, UNREAD를 반환한다. ")
public void test1(){

//given
User user = User.createNewUser("1L", Platform.KAKAO, null, "hyunw9", "email");
LocalDate today = LocalDate.now();
Reply dynamicReply = Reply.createDynamicReply(user, today);
Reply staticReply = Reply.createStaticReply(user,"static Reply" ,today);
Reply firstReply = Reply.createFastDynamicReply(user, today);

//when
UserReplyReadStatus dynamicReplyReadStatus = dynamicReply.processReadStatus(dynamicReply);
UserReplyReadStatus staticReplyReadStatus = staticReply.processReadStatus(staticReply);
UserReplyReadStatus firstReplyReadStatus = firstReply.processReadStatus(firstReply);

//then
assertThat(dynamicReplyReadStatus).isEqualTo(UserReplyReadStatus.UNREADY);
assertThat(staticReplyReadStatus).isEqualTo(UserReplyReadStatus.UNREADY);
assertThat(firstReplyReadStatus).isEqualTo(UserReplyReadStatus.UNREADY);
}

@Test
@DisplayName("답장이 준비되었지만 읽지 않은 경우, isRead == False를 반환한다.")
public void test2(){
//given
User user = User.createNewUser("1L", Platform.KAKAO, null, "hyunw9", "email");
LocalDate today = LocalDate.now();
Reply dynamicReply = Reply.createDynamicReply(user, today);
Reply staticReply = Reply.createStaticReply(user,"static Reply" ,today);
Reply firstReply = Reply.createFastDynamicReply(user, today);

//when
boolean dynamicIsRead = dynamicReply.checkUserReadReply();
boolean staticIsRead = staticReply.checkUserReadReply();
boolean firstIsRead = firstReply.checkUserReadReply();

//then
assertThat(dynamicIsRead).isEqualTo(false);
assertThat(staticIsRead).isEqualTo(false);
assertThat(firstIsRead).isEqualTo(false);
}

@Test
@DisplayName("답장이 준비되었고 읽은 경우, isRead == True 반환한다.")
public void test3(){
//given
User user = User.createNewUser("1L", Platform.KAKAO, null, "hyunw9", "email");
LocalDate today = LocalDate.now();
Reply dynamicReply = Reply.createDynamicReply(user, today);
Reply staticReply = Reply.createStaticReply(user,"static Reply" ,today);
Reply firstReply = Reply.createFastDynamicReply(user, today);

//when
dynamicReply.insertContentFromRody("content",1);
staticReply.insertContentFromRody("content",1);
firstReply.insertContentFromRody("content",1);

dynamicReply.readReply();
staticReply.readReply();
firstReply.readReply();

boolean dynamicIsRead = dynamicReply.checkUserReadReply();
boolean staticIsRead = staticReply.checkUserReadReply();
boolean firstIsRead = firstReply.checkUserReadReply();

//then
assertThat(dynamicIsRead).isEqualTo(true);
assertThat(staticIsRead).isEqualTo(true);
assertThat(firstIsRead).isEqualTo(true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class FcmService implements NotificationSender {
private final FirebaseMessaging firebaseMessaging;

public void sendDiaryAlarm(String fcmToken){
MessageContent diaryAlert = MessageContent.REPLY_COMPLETED_REQUEST;
MessageContent diaryAlert = MessageContent.DIARY_WRITE_REQUEST;
Notification notification = Notification.builder()
.setTitle(diaryAlert.getTitle())
.setBody(diaryAlert.getBody())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
@AllArgsConstructor
public class MessageProcessConstants {

public static final Long FIRST_DURATION = 10 * 60L ;
public static final Long FIRST_DURATION = 1 * 60L ;
public static final Long DEFAULT_DURATION = 2* 60 * 60L;
public static final Long STATIC_DURATION = 2 * 60 * 60L;

Expand Down
Loading