Skip to content

Commit

Permalink
fix: 편지 생성시 토큰에서 사용자 정보 받아와서 생성하도록 수정 #3
Browse files Browse the repository at this point in the history
  • Loading branch information
623nana committed Aug 21, 2021
1 parent bcce1fe commit 0a66018
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public BaseResponse<List<QuestionResponse>> findQuestionsByOptionId(
}

@PostMapping("/letters")
public BaseResponse<LetterResponse> saveLetter(@RequestBody LetterRequest letterRequest) {
LetterResponse letter = letterService.saveLetter(letterRequest);
public BaseResponse<LetterResponse> saveLetter(@RequestBody LetterRequest letterRequest, Authentication authentication) {
LetterResponse letter = letterService.saveLetter(letterRequest, authentication.getName());
return new BaseResponse<>(200, 0, "", letter);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class LetterRequest {

private String contents;

private String email;
// private String letterTo;

private Sticker sticker;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/nexters/covid/letter/domain/Letter.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public class Letter extends BaseEntity {

public Letter(LetterRequest request, User user, SendOption sendOption) {
this.user = user;
this.letterTo = request.getEmail();
this.letterTo = user.getEmail();
this.title = request.getTitle();
this.contents = encodeContents(request.getContents());
this.email = user.getEmail();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ public List<QuestionResponse> findQuestionsByOptionId(Long optionId) {
}

@Transactional
public LetterResponse saveLetter(LetterRequest letterRequest) {
User user = userRepository.findUserByEmail(letterRequest.getEmail())
public LetterResponse saveLetter(LetterRequest letterRequest, String email) {
User user = userRepository.findUserByEmail(email)
.orElseThrow(() -> new RuntimeException("사용자가 없습니다."));
SendOption option = findSendOptionById(letterRequest.markLetterSendOptionId());

Expand Down

0 comments on commit 0a66018

Please sign in to comment.