Skip to content

Commit

Permalink
feat: 발송 옵션 설정시 optionId update 기능 #3
Browse files Browse the repository at this point in the history
  • Loading branch information
623nana committed Aug 21, 2021
1 parent c50d4a7 commit a13ec24
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,15 @@ public BaseResponse<LetterResponse> findLetterByEncryptedId(
return new BaseResponse<>(200, 0, "", letter);
}

@PutMapping("/letters/{encryptedId}")
@PutMapping("/letters/{encryptedId}/state")
public BaseResponse<LetterResponse> updateLetterState(@PathVariable("encryptedId") String encryptedId) {
LetterResponse letter = letterService.updateLetterState(encryptedId);
return new BaseResponse<>(200, 0, "", letter);
}

@PutMapping("/letters/{encryptedId}")
public BaseResponse<LetterResponse> updateLetter(@PathVariable("encryptedId") String encryptedId, @RequestBody LetterRequest letterRequest) {
LetterResponse letter = letterService.updateLetter(encryptedId, letterRequest);
return new BaseResponse<>(200, 0, "", letter);
}
}
7 changes: 7 additions & 0 deletions src/main/java/com/nexters/covid/letter/domain/Letter.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,11 @@ public Long markLetterSendOptionId(Long sendOptionId) {
}
return sendOptionId;
}

public void updateLetterSendOption(Long sendOptionId) {
if (this.sendOptionId != 7) {
throw new RuntimeException("발송 옵션이 이미 설정되어 있습니다.");
}
this.sendOptionId = sendOptionId;
}
}
10 changes: 10 additions & 0 deletions src/main/java/com/nexters/covid/letter/service/LetterService.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,14 @@ public LetterResponse updateLetterState(String encryptedId) {
return new LetterResponse(letter);
}

@Transactional
public LetterResponse updateLetter(String encryptedId, LetterRequest letterRequest) {
Letter letter = letterRepository.findLetterByEncryptedId(encryptedId)
.map(l -> {
l.updateLetterSendOption(letterRequest.getSendOptionId());
return l;
}).orElseThrow(() -> new IllegalArgumentException("해당 ID의 편지가 없습니다."));

return new LetterResponse(letter);
}
}

0 comments on commit a13ec24

Please sign in to comment.