Skip to content

Commit

Permalink
Fix : 정적 답변 생성 로직 수정 (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
hyunw9 authored Jul 19, 2024
1 parent e2171b1 commit 70fdfc4
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

0 comments on commit 70fdfc4

Please sign in to comment.