Skip to content

Commit

Permalink
perf(#23): 편지 생성시 아이디 반환
Browse files Browse the repository at this point in the history
- 프론트의 요청으로 편지 생성시 아이디를 반환하도록 했어요.
  • Loading branch information
jyj1289 committed Nov 23, 2024
1 parent 39f7bbb commit 2161556
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.bamdoliro.sinabro.infrastructure.persistence.diary.DiaryRepository;
import com.bamdoliro.sinabro.infrastructure.persistence.letter.LetterRepository;
import com.bamdoliro.sinabro.shared.annotation.UseCase;
import com.bamdoliro.sinabro.shared.response.IdResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -26,14 +27,16 @@ public class GenerateLetterUseCase {
private final CharacterFacade characterFacade;

@Transactional
public void execute(User user) {
public IdResponse execute(User user) {
Character character = characterFacade.getCharacter(user);
List<EmotionAndKeyword> emotionAndKeywords = extractEmotionAndKeywords(user);
GenerateLetterResponse response = aiService.generateLetter(character.getType().getId(), character.getFriendship(), emotionAndKeywords);

letterRepository.save(new Letter(response.getContent(), user));
Letter letter = letterRepository.save(new Letter(response.getContent(), user));

character.increaseFriendShip();

return new IdResponse(letter);
}

private List<EmotionAndKeyword> extractEmotionAndKeywords(User user) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.bamdoliro.sinabro.presentation.letter.dto.response.LetterResponse;
import com.bamdoliro.sinabro.presentation.letter.dto.response.ListLetterResponse;
import com.bamdoliro.sinabro.shared.auth.AuthenticationPrincipal;
import com.bamdoliro.sinabro.shared.response.IdResponse;
import com.bamdoliro.sinabro.shared.response.ListCommonResponse;
import com.bamdoliro.sinabro.shared.response.SingleCommonResponse;
import lombok.RequiredArgsConstructor;
Expand All @@ -24,10 +25,10 @@ public class LetterController {

@ResponseStatus(HttpStatus.CREATED)
@PostMapping
public void generateLetter(
public IdResponse generateLetter(
@AuthenticationPrincipal User user
) {
generateLetterUseCase.execute(user);
return generateLetterUseCase.execute(user);
}

@GetMapping
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.bamdoliro.sinabro.shared.response;

import com.bamdoliro.sinabro.domain.diary.domain.Diary;
import com.bamdoliro.sinabro.domain.letter.domain.Letter;
import lombok.AllArgsConstructor;
import lombok.Getter;

Expand All @@ -13,4 +14,8 @@ public class IdResponse {
public IdResponse(Diary diary) {
this.id = diary.getId();
}

public IdResponse(Letter letter) {
this.id = letter.getId();
}
}

0 comments on commit 2161556

Please sign in to comment.