Skip to content

Commit

Permalink
Merge pull request #169 from lemonssoju/fix/105-completePuzzle
Browse files Browse the repository at this point in the history
[fix/105-completePuzzle] DB에 저장된 퍼즐 데이터로 요청을 보내도록 수정
  • Loading branch information
JoongHyun-Kim authored Jun 3, 2024
2 parents a0bf3e0 + 5e29760 commit 37d8827
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
6 changes: 4 additions & 2 deletions src/main/java/com/lesso/neverland/album/domain/Album.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,17 @@ public class Album extends BaseEntity {

private String albumImage;

@Column(nullable = false)
@Column(nullable = false, length = 1000)
private String content;

@OneToMany(mappedBy = "album")
private List<Comment> comments = new ArrayList<>();

@Builder
public Album(Puzzle puzzle, String content) {
public Album(Puzzle puzzle, String albumImage, Team team, String content) {
this.puzzle = puzzle;
this.albumImage = albumImage;
this.team = team;
this.content = content;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import com.lesso.neverland.gpt.application.GptService;
import com.lesso.neverland.gpt.dto.GptResponseDto;
import com.lesso.neverland.puzzle.domain.PuzzleLocation;
import com.lesso.neverland.puzzle.dto.CompletePuzzleRequest;
import com.lesso.neverland.puzzle.dto.CompletePuzzleResponse;
import com.lesso.neverland.gpt.dto.GptResponse;
import com.lesso.neverland.group.domain.Team;
Expand Down Expand Up @@ -45,6 +44,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.stream.Collectors;

import static com.lesso.neverland.common.base.BaseResponseStatus.*;
import static com.lesso.neverland.common.constants.Constants.ACTIVE;
Expand Down Expand Up @@ -288,18 +288,24 @@ private void validatePuzzler(User user, Puzzle puzzle) {

// [작성자] 퍼즐 완성하기
@Transactional(rollbackFor = Exception.class)
public BaseResponse<CompletePuzzleResponse> completePuzzle(Long groupIdx, Long puzzleIdx, CompletePuzzleRequest completePuzzleRequest) {
public BaseResponse<CompletePuzzleResponse> completePuzzle(Long groupIdx, Long puzzleIdx) {
User user = userRepository.findById(userService.getUserIdxWithValidation()).orElseThrow(() -> new BaseException(INVALID_USER_IDX));
Puzzle puzzle = puzzleRepository.findById(puzzleIdx).orElseThrow(() -> new BaseException(INVALID_PUZZLE_IDX));
validateWriter(user, puzzle);

List<String> puzzleTextList = puzzle.getPuzzlePieces().stream()
.map(PuzzlePiece::getContent).collect(Collectors.toList());
puzzleTextList.add(puzzle.getContent());

// GPT 요약 수행
GptResponse response = gptService.completion(gptService.toText(completePuzzleRequest.puzzleTextList()));
GptResponse response = gptService.completion(gptService.toText(puzzleTextList));
GptResponseDto gptResponseDto = gptService.parseResponse(response.messages().get(0).message());

// Album 생성
Album newAlbum = Album.builder()
.puzzle(puzzle)
.albumImage("")
.team(puzzle.getTeam())
.content(gptResponseDto.description()).build();
albumRepository.save(newAlbum);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import com.lesso.neverland.common.base.BaseException;
import com.lesso.neverland.common.base.BaseResponse;
import com.lesso.neverland.gpt.application.GptService;
import com.lesso.neverland.puzzle.dto.CompletePuzzleRequest;
import com.lesso.neverland.puzzle.dto.CompletePuzzleResponse;
import com.lesso.neverland.group.dto.GroupPuzzleListResponse;
import com.lesso.neverland.puzzle.application.PuzzleService;
Expand All @@ -22,7 +20,6 @@
@RequestMapping(puzzle)
public class PuzzleController {
private final PuzzleService puzzleService;
private final GptService gptService;

// 퍼즐 목록 조회
@GetMapping("")
Expand Down Expand Up @@ -72,11 +69,8 @@ public BaseResponse<String> addPuzzlePiece(@PathVariable("groupIdx") Long groupI

// [작성자] 퍼즐 완성하기
@PostMapping("/{puzzleIdx}")
public BaseResponse<CompletePuzzleResponse> completePuzzle(@PathVariable("groupIdx") Long groupIdx,
@PathVariable("puzzleIdx") Long puzzleIdx,
@RequestBody CompletePuzzleRequest completePuzzleRequest)
{
return puzzleService.completePuzzle(groupIdx, puzzleIdx, completePuzzleRequest);
public BaseResponse<CompletePuzzleResponse> completePuzzle(@PathVariable("groupIdx") Long groupIdx, @PathVariable("puzzleIdx") Long puzzleIdx) {
return puzzleService.completePuzzle(groupIdx, puzzleIdx);
}

}

0 comments on commit 37d8827

Please sign in to comment.