Skip to content

Commit

Permalink
Merge pull request #85 from mummhy0811/main
Browse files Browse the repository at this point in the history
[#83]Fix: 쪽지 작성 user null저장 현상 해결
  • Loading branch information
mummhy0811 authored Nov 14, 2023
2 parents 2be5eed + d7b0a1b commit c9dd1c1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/onestep/server/entity/letter/WriteLetterDto.java
Original file line number Diff line number Diff line change
@@ -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;
}
14 changes: 12 additions & 2 deletions src/main/java/com/onestep/server/service/letter/LetterService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -26,13 +28,21 @@ 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();
}

//익명 쪽지 작성
public void writeLetter(Letter letter){
public void writeLetter(WriteLetterDto letterDto){
Optional<User> 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);
}

Expand Down

0 comments on commit c9dd1c1

Please sign in to comment.