From 3d31d539fb45a50a1fd61f6160bc61eebdc2f634 Mon Sep 17 00:00:00 2001 From: mummhy0811 Date: Tue, 14 Nov 2023 23:00:05 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[#83]Fix:=20=EC=AA=BD=EC=A7=80=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1=20user=20null=EC=A0=80=EC=9E=A5=20=ED=98=84=EC=83=81?= =?UTF-8?q?=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/controller/letter/LetterController.java | 3 ++- .../onestep/server/entity/letter/WriteLetterDto.java | 12 ++++++++++++ .../onestep/server/service/letter/LetterService.java | 12 +++++++++++- 3 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/onestep/server/entity/letter/WriteLetterDto.java diff --git a/src/main/java/com/onestep/server/controller/letter/LetterController.java b/src/main/java/com/onestep/server/controller/letter/LetterController.java index f28fe1c..9e09192 100644 --- a/src/main/java/com/onestep/server/controller/letter/LetterController.java +++ b/src/main/java/com/onestep/server/controller/letter/LetterController.java @@ -2,6 +2,7 @@ import com.onestep.server.entity.Letter; import com.onestep.server.entity.letter.LetterListDTO; +import com.onestep.server.entity.letter.WriteLetterDto; import com.onestep.server.service.letter.LetterService; import com.onestep.server.service.question.GptService; import lombok.RequiredArgsConstructor; @@ -17,7 +18,7 @@ public class LetterController { //익명 쪽지 작성 @PostMapping(value = "/letter/write") - public Letter writeLetter(@RequestBody Letter letter){ + public WriteLetterDto writeLetter(@RequestBody WriteLetterDto letter){ letterService.writeLetter(letter); return letter; } diff --git a/src/main/java/com/onestep/server/entity/letter/WriteLetterDto.java b/src/main/java/com/onestep/server/entity/letter/WriteLetterDto.java new file mode 100644 index 0000000..31c4afc --- /dev/null +++ b/src/main/java/com/onestep/server/entity/letter/WriteLetterDto.java @@ -0,0 +1,12 @@ +package com.onestep.server.entity.letter; + +import lombok.Getter; +import lombok.Setter; + +@Setter +@Getter +public class WriteLetterDto { + private String writer_id; + private String letter_title; + private String letter_txt; +} diff --git a/src/main/java/com/onestep/server/service/letter/LetterService.java b/src/main/java/com/onestep/server/service/letter/LetterService.java index 80bb7c5..26081a6 100644 --- a/src/main/java/com/onestep/server/service/letter/LetterService.java +++ b/src/main/java/com/onestep/server/service/letter/LetterService.java @@ -4,6 +4,7 @@ import com.onestep.server.entity.Letter; import com.onestep.server.entity.User; import com.onestep.server.entity.letter.LetterListDTO; +import com.onestep.server.entity.letter.WriteLetterDto; import com.onestep.server.repository.IFamilyRepository; import com.onestep.server.repository.ILetterRepository; import com.onestep.server.repository.IUserRepository; @@ -14,6 +15,7 @@ import org.springframework.transaction.annotation.Transactional; import java.util.ArrayList; +import java.util.Date; import java.util.List; import java.util.Optional; @@ -32,7 +34,15 @@ public void changeLetterState(){ } //익명 쪽지 작성 - public void writeLetter(Letter letter){ + public void writeLetter(WriteLetterDto letterDto){ + Optional optionalUser = iUserRepository.findById(letterDto.getWriter_id()); + if(optionalUser.isEmpty()) throw new IllegalArgumentException("아이디를 찾을 수 없습니다."); + Letter letter = new Letter(); + letter.setLetter_id(null); + letter.setLetter_txt(letterDto.getLetter_txt()); + letter.setLetter_title(letterDto.getLetter_title()); + letter.setWrite_date(new Date()); + letter.setUser(optionalUser.get()); iLetterRepository.save(letter); } From d7b0a1b0e9ee50925f82fbb190c2f659a6d0478e Mon Sep 17 00:00:00 2001 From: mummhy0811 Date: Tue, 14 Nov 2023 23:07:22 +0900 Subject: [PATCH 2/2] =?UTF-8?q?Refactor:=20=EC=AA=BD=EC=A7=80=20=EA=B3=B5?= =?UTF-8?q?=EA=B0=9C=20cron=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/onestep/server/service/letter/LetterService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/onestep/server/service/letter/LetterService.java b/src/main/java/com/onestep/server/service/letter/LetterService.java index 26081a6..fd56e36 100644 --- a/src/main/java/com/onestep/server/service/letter/LetterService.java +++ b/src/main/java/com/onestep/server/service/letter/LetterService.java @@ -28,7 +28,7 @@ public class LetterService { private final IUserRepository iUserRepository; private final IFamilyRepository iFamilyRepository; - @Scheduled(cron = "0 0 6 ? * 5", zone = "Asia/Seoul") //매주 금요일 오전 6시마다 + @Scheduled(cron = "0 0 6 ? * FRI", zone = "Asia/Seoul") //매주 금요일 오전 6시마다 public void changeLetterState(){ iLetterRepository.changeLetterState(); }