diff --git a/src/main/java/com/lesso/neverland/album/domain/Album.java b/src/main/java/com/lesso/neverland/album/domain/Album.java index 4868954..139c414 100644 --- a/src/main/java/com/lesso/neverland/album/domain/Album.java +++ b/src/main/java/com/lesso/neverland/album/domain/Album.java @@ -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 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; } diff --git a/src/main/java/com/lesso/neverland/album/repository/AlbumRepository.java b/src/main/java/com/lesso/neverland/album/repository/AlbumRepository.java index cc7cbd1..15d1860 100644 --- a/src/main/java/com/lesso/neverland/album/repository/AlbumRepository.java +++ b/src/main/java/com/lesso/neverland/album/repository/AlbumRepository.java @@ -2,10 +2,12 @@ import com.lesso.neverland.album.domain.Album; import com.lesso.neverland.group.domain.Team; +import com.lesso.neverland.puzzle.domain.Puzzle; import org.springframework.data.jpa.repository.JpaRepository; import java.util.List; public interface AlbumRepository extends JpaRepository { List findByTeamOrderByCreatedDateDesc(Team team); + boolean existsByPuzzle(Puzzle puzzle); } diff --git a/src/main/java/com/lesso/neverland/group/application/GroupService.java b/src/main/java/com/lesso/neverland/group/application/GroupService.java index e76bfc6..ca3ae7c 100644 --- a/src/main/java/com/lesso/neverland/group/application/GroupService.java +++ b/src/main/java/com/lesso/neverland/group/application/GroupService.java @@ -46,7 +46,9 @@ public BaseResponse getGroupList() { User user = userRepository.findById(userService.getUserIdxWithValidation()).orElseThrow(() -> new BaseException(INVALID_USER_IDX)); List groupList_admin = groupRepository.findByAdminAndStatusEquals(user, ACTIVE); - List groupList_member = user.getUserTeams().stream().map(UserTeam::getTeam).toList(); + List groupList_member = user.getUserTeams().stream() + .filter(userTeam -> "active".equals(userTeam.getStatus())) + .map(UserTeam::getTeam).toList(); List combinedGroupList = Stream.concat(groupList_admin.stream(), groupList_member.stream()).distinct().toList(); List groupListDto = combinedGroupList.stream() @@ -99,7 +101,7 @@ public BaseResponse getGroupProfile(Long groupIdx) { long dayCount = ChronoUnit.DAYS.between(startLocalDate, today); - GroupProfileResponse profile = new GroupProfileResponse(group.getName(), group.getStartDate().getYear(), memberImageList, + GroupProfileResponse profile = new GroupProfileResponse(group.getName(), group.getAdmin().getProfile().getNickname(), group.getStartDate().getYear(), memberImageList, group.getUserTeams().size(), puzzleCount, dayCount); return new BaseResponse<>(profile); } @@ -186,6 +188,8 @@ public BaseResponse withdrawGroup(Long groupIdx) { UserTeam userTeam = validateMember(user, group); userTeam.delete(); + userTeam.removeTeam(group); + userTeam.removeUser(user); userTeamRepository.save(userTeam); return new BaseResponse<>(SUCCESS); diff --git a/src/main/java/com/lesso/neverland/group/dto/GroupProfileResponse.java b/src/main/java/com/lesso/neverland/group/dto/GroupProfileResponse.java index 2100d0e..620077f 100644 --- a/src/main/java/com/lesso/neverland/group/dto/GroupProfileResponse.java +++ b/src/main/java/com/lesso/neverland/group/dto/GroupProfileResponse.java @@ -3,6 +3,7 @@ import java.util.List; public record GroupProfileResponse(String groupName, + String admin, Integer startYear, List memberImageList, // 3개만 조회 Integer memberCount, // 멤버수 diff --git a/src/main/java/com/lesso/neverland/puzzle/application/PuzzleService.java b/src/main/java/com/lesso/neverland/puzzle/application/PuzzleService.java index fba6a7b..47504c0 100644 --- a/src/main/java/com/lesso/neverland/puzzle/application/PuzzleService.java +++ b/src/main/java/com/lesso/neverland/puzzle/application/PuzzleService.java @@ -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; @@ -42,8 +41,10 @@ import java.io.IOException; import java.time.LocalDate; import java.time.format.DateTimeFormatter; +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; @@ -101,10 +102,11 @@ public BaseResponse getPuzzleDetail(Long groupIdx, Long pu boolean isWriter = puzzle.getUser().equals(user); boolean hasWrite = puzzlePieceRepository.existsByPuzzleAndUser(puzzle, user); + boolean hasAlbum = albumRepository.existsByPuzzle(puzzle); PuzzleDetailResponse puzzleDetail = new PuzzleDetailResponse(puzzle.getLocation().getLocation(), puzzle.getPuzzleImage(), - puzzle.getPuzzleDate().toString(), puzzle.getUser().getProfile().getNickname(), puzzle.getTitle(), puzzle.getContent(), - getMemberImageList(puzzle), puzzle.getPuzzleMembers().size(), puzzle.getPuzzlePieces().size()+1, isWriter, hasWrite, + puzzle.getPuzzleDate().toString(), puzzle.getCreatedDate().toString(), puzzle.getUser().getProfile().getNickname(), puzzle.getTitle(), puzzle.getContent(), + getMemberImageList(puzzle), getMemberNicknameList(puzzle), puzzle.getPuzzleMembers().size(), puzzle.getPuzzlePieces().size()+1, isWriter, hasWrite, hasAlbum, getPuzzlePieceList(puzzle)); return new BaseResponse<>(puzzleDetail); } @@ -121,15 +123,24 @@ private List getPuzzlePieceList(Puzzle puzzle) { // puzzleMember 3명의 프로필 이미지 조회 private List getMemberImageList(Puzzle puzzle) { - return puzzle.getPuzzleMembers().stream() + List imageList = new ArrayList<>(); + imageList.add(puzzle.getUser().getProfile().getProfileImage()); + + List memberImages = puzzle.getPuzzleMembers().stream() .map(puzzleMember -> puzzleMember.getUser().getProfile().getProfileImage()) - .limit(3) - .toList(); + .limit(2).toList(); + imageList.addAll(memberImages); + return imageList; + } + + private List getMemberNicknameList(Puzzle puzzle) { + return puzzle.getPuzzleMembers().stream() + .map(puzzleMember -> puzzleMember.getUser().getProfile().getNickname()).toList(); } // 퍼즐 생성 @Transactional(rollbackFor = Exception.class) - public BaseResponse createPuzzle(Long groupIdx, MultipartFile image, CreatePuzzleRequest createPuzzleRequest) throws IOException { + public BaseResponse createPuzzle(Long groupIdx, MultipartFile image, CreatePuzzleRequest createPuzzleRequest) throws IOException { Team group = groupRepository.findById(groupIdx).orElseThrow(() -> new BaseException(INVALID_GROUP_IDX)); User writer = userRepository.findById(userService.getUserIdxWithValidation()).orElseThrow(() -> new BaseException(INVALID_USER_IDX)); @@ -139,7 +150,7 @@ public BaseResponse createPuzzle(Long groupIdx, MultipartFile image, Cre Puzzle newPuzzle = createPuzzle(createPuzzleRequest, group, writer, imagePath, puzzleDate); addPuzzleMember(createPuzzleRequest, newPuzzle); - return new BaseResponse<>(SUCCESS); + return new BaseResponse<>(new CreatePuzzleResponse(newPuzzle.getPuzzleIdx())); } // Puzzle 생성 시 PuzzleMember entity 함께 생성 @@ -278,18 +289,24 @@ private void validatePuzzler(User user, Puzzle puzzle) { // [작성자] 퍼즐 완성하기 @Transactional(rollbackFor = Exception.class) - public BaseResponse completePuzzle(Long groupIdx, Long puzzleIdx, CompletePuzzleRequest completePuzzleRequest) { + public BaseResponse 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 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); diff --git a/src/main/java/com/lesso/neverland/puzzle/dto/CreatePuzzleResponse.java b/src/main/java/com/lesso/neverland/puzzle/dto/CreatePuzzleResponse.java new file mode 100644 index 0000000..339c76a --- /dev/null +++ b/src/main/java/com/lesso/neverland/puzzle/dto/CreatePuzzleResponse.java @@ -0,0 +1,4 @@ +package com.lesso.neverland.puzzle.dto; + +public record CreatePuzzleResponse(Long puzzleIdx) { +} diff --git a/src/main/java/com/lesso/neverland/puzzle/dto/PuzzleDetailResponse.java b/src/main/java/com/lesso/neverland/puzzle/dto/PuzzleDetailResponse.java index 039d18c..cdb2fb7 100644 --- a/src/main/java/com/lesso/neverland/puzzle/dto/PuzzleDetailResponse.java +++ b/src/main/java/com/lesso/neverland/puzzle/dto/PuzzleDetailResponse.java @@ -4,12 +4,15 @@ public record PuzzleDetailResponse(String location, String puzzleImage, String puzzleDate, + String createdDate, String writer, String title, String content, List memberImageList, // 3명만 + List memberNicknameList, Integer memberCount, Integer writeCount, // PuzzlePieceCount+1 boolean isWriter, boolean hasWrite, // 해당 user가 퍼즐피스 작성했는지 여부 + boolean hasAlbum, List puzzlePieces) {} diff --git a/src/main/java/com/lesso/neverland/puzzle/presentation/PuzzleController.java b/src/main/java/com/lesso/neverland/puzzle/presentation/PuzzleController.java index e8be954..620ec52 100644 --- a/src/main/java/com/lesso/neverland/puzzle/presentation/PuzzleController.java +++ b/src/main/java/com/lesso/neverland/puzzle/presentation/PuzzleController.java @@ -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; @@ -22,7 +20,6 @@ @RequestMapping(puzzle) public class PuzzleController { private final PuzzleService puzzleService; - private final GptService gptService; // 퍼즐 목록 조회 @GetMapping("") @@ -38,7 +35,7 @@ public BaseResponse getPuzzleDetail(@PathVariable("groupId // 퍼즐 생성 @PostMapping("") - public BaseResponse createPuzzle(@PathVariable Long groupIdx, @RequestPart MultipartFile image, @RequestPart CreatePuzzleRequest createPuzzleRequest) { + public BaseResponse createPuzzle(@PathVariable Long groupIdx, @RequestPart MultipartFile image, @RequestPart CreatePuzzleRequest createPuzzleRequest) { try { return puzzleService.createPuzzle(groupIdx, image, createPuzzleRequest); } catch (IOException e) { @@ -72,11 +69,8 @@ public BaseResponse addPuzzlePiece(@PathVariable("groupIdx") Long groupI // [작성자] 퍼즐 완성하기 @PostMapping("/{puzzleIdx}") - public BaseResponse completePuzzle(@PathVariable("groupIdx") Long groupIdx, - @PathVariable("puzzleIdx") Long puzzleIdx, - @RequestBody CompletePuzzleRequest completePuzzleRequest) - { - return puzzleService.completePuzzle(groupIdx, puzzleIdx, completePuzzleRequest); + public BaseResponse completePuzzle(@PathVariable("groupIdx") Long groupIdx, @PathVariable("puzzleIdx") Long puzzleIdx) { + return puzzleService.completePuzzle(groupIdx, puzzleIdx); } } diff --git a/src/main/java/com/lesso/neverland/user/domain/UserTeam.java b/src/main/java/com/lesso/neverland/user/domain/UserTeam.java index 1151038..88b0500 100644 --- a/src/main/java/com/lesso/neverland/user/domain/UserTeam.java +++ b/src/main/java/com/lesso/neverland/user/domain/UserTeam.java @@ -39,6 +39,16 @@ public void setTeam(Team team) { team.getUserTeams().add(this); } + public void removeUser(User user) { + this.user = user; + user.getUserTeams().remove(this); + } + + public void removeTeam(Team team) { + this.team = team; + team.getUserTeams().remove(this); + } + @Builder public UserTeam(User user, Team team) { this.user = user;