From 70fdfc471b6d57fad2c28eaccdf093cdc61b7ed8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=ED=98=84=EC=9A=B1?= <43662405+hyunw9@users.noreply.github.com> Date: Fri, 19 Jul 2024 20:17:21 +0900 Subject: [PATCH] =?UTF-8?q?Fix=20:=20=EC=A0=95=EC=A0=81=20=EB=8B=B5?= =?UTF-8?q?=EB=B3=80=20=EC=83=9D=EC=84=B1=20=EB=A1=9C=EC=A7=81=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20(#124)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/application/diary/DiaryService.java | 11 +++++------ .../donkeys_today/server/domain/reply/Reply.java | 6 +++++- .../server/support/config/ReplyProperty.java | 13 ++++--------- .../support/config/YamlPropertySourceFactory.java | 15 ++++++++++----- 4 files changed, 24 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/donkeys_today/server/application/diary/DiaryService.java b/src/main/java/com/donkeys_today/server/application/diary/DiaryService.java index d94f1e4..ca41c40 100644 --- a/src/main/java/com/donkeys_today/server/application/diary/DiaryService.java +++ b/src/main/java/com/donkeys_today/server/application/diary/DiaryService.java @@ -118,8 +118,8 @@ public DiaryCreatedResponse createDiary(DiaryRequest request) { // 욕설을 포함한 일기를 작성한 경우, 정적 답변을 생성함 (기존 일기만 업데이트) if (diaryPolicy.containsProfanity(request.content())) { diaryCreator.saveAllDiary(user, request.content(), createdAt); - createStaticReply(user, request.date()); - return DiaryCreatedResponse.createDiaryWithStaticReply(LocalDateTime.now()); + Reply reply = createStaticReply(user, request.date()); + return DiaryCreatedResponse.createDiaryWithStaticReply(reply.getCreatedAt()); } log.info("diary ; {}", request.content()); @@ -136,10 +136,8 @@ public DiaryCreatedResponse createDiary(DiaryRequest request) { return DiaryCreatedResponse.createDiaryWithDynamicReply(LocalDateTime.now()); } - public void createStaticReply(User user, String date) { - replyService.createStaticReply(user, date); - - // 정적 답변 생성시 어떻게 되는지 ? + public Reply createStaticReply(User user, String date) { + return replyService.createStaticReply(user, date); } @Transactional @@ -160,6 +158,7 @@ public DiaryResponse deleteDiary(int year, int month, int date) { if (replyService.isReplyExist(user.getId(), year, month, date)) { replyService.removeReply(user.getId(), year, month, date); + //답변이 있고, 읽은 상태면, CloverCount 1 감소 } return DiaryResponse.of(List.of()); diff --git a/src/main/java/com/donkeys_today/server/domain/reply/Reply.java b/src/main/java/com/donkeys_today/server/domain/reply/Reply.java index ec7c90b..c4dff31 100644 --- a/src/main/java/com/donkeys_today/server/domain/reply/Reply.java +++ b/src/main/java/com/donkeys_today/server/domain/reply/Reply.java @@ -47,7 +47,11 @@ public void readReply() { this.is_read = true; } - public boolean isRead() { + public boolean isNotRead(){ + return !this.is_read; + } + + public boolean isRead(){ return this.is_read; } diff --git a/src/main/java/com/donkeys_today/server/support/config/ReplyProperty.java b/src/main/java/com/donkeys_today/server/support/config/ReplyProperty.java index 24b4f11..80cfde0 100644 --- a/src/main/java/com/donkeys_today/server/support/config/ReplyProperty.java +++ b/src/main/java/com/donkeys_today/server/support/config/ReplyProperty.java @@ -1,22 +1,17 @@ package com.donkeys_today.server.support.config; import lombok.Getter; -import lombok.Setter; +import lombok.RequiredArgsConstructor; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.PropertySource; -import org.springframework.stereotype.Component; -@Setter @Getter -@Component +@RequiredArgsConstructor @ConfigurationProperties(prefix = "app") @EnableConfigurationProperties(ReplyProperty.class) -@PropertySource(value = "classpath:reply.yml", factory = YamlPropertySourceFactory.class) -@Configuration +@PropertySource(value = "classpath:reply.yaml", factory = YamlPropertySourceFactory.class) public class ReplyProperty { - private String comment; - + private final String content; } diff --git a/src/main/java/com/donkeys_today/server/support/config/YamlPropertySourceFactory.java b/src/main/java/com/donkeys_today/server/support/config/YamlPropertySourceFactory.java index 8ed1a5c..0745513 100644 --- a/src/main/java/com/donkeys_today/server/support/config/YamlPropertySourceFactory.java +++ b/src/main/java/com/donkeys_today/server/support/config/YamlPropertySourceFactory.java @@ -2,21 +2,26 @@ import java.util.Objects; import java.util.Properties; +import javax.annotation.Nullable; import org.springframework.beans.factory.config.YamlPropertiesFactoryBean; import org.springframework.core.env.PropertiesPropertySource; import org.springframework.core.env.PropertySource; import org.springframework.core.io.support.EncodedResource; import org.springframework.core.io.support.PropertySourceFactory; +import org.springframework.util.StringUtils; public class YamlPropertySourceFactory implements PropertySourceFactory { @Override - public PropertySource createPropertySource(String name, EncodedResource resource) { + public PropertySource createPropertySource(@Nullable String name, EncodedResource resource) { + Properties yamlProperties = loadYamlProperties(resource); + String sourceName = StringUtils.hasText(name) ? name : resource.getResource().getFilename(); + return new PropertiesPropertySource(Objects.requireNonNull(sourceName), Objects.requireNonNull(yamlProperties)); + } + + private Properties loadYamlProperties(EncodedResource resource) { YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean(); factory.setResources(resource.getResource()); - - Properties properties = factory.getObject(); - return new PropertiesPropertySource( - Objects.requireNonNull(resource.getResource().getFilename()), properties); + return factory.getObject(); } }