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 44da444..1754756 100644 --- a/src/main/java/com/lesso/neverland/group/application/GroupService.java +++ b/src/main/java/com/lesso/neverland/group/application/GroupService.java @@ -170,7 +170,7 @@ public BaseResponse withdrawGroup(Long groupIdx) { // 그룹 생성 @Transactional(rollbackFor = Exception.class) - public BaseResponse createGroup(MultipartFile image, CreateGroupRequest createGroupRequest) throws IOException { + public BaseResponse createGroup(MultipartFile image, CreateGroupRequest createGroupRequest) throws IOException { User admin = userRepository.findById(userService.getUserIdxWithValidation()).orElseThrow(() -> new BaseException(INVALID_USER_IDX)); // upload image @@ -192,14 +192,8 @@ public BaseResponse createGroup(MultipartFile image, CreateGroupRequest newUserTeam.setTeam(group); userTeamRepository.save(newUserTeam); -// for (Long memberIdx : createGroupRequest.memberList()) { -// User member = userRepository.findById(memberIdx).orElseThrow(() -> new BaseException(INVALID_USER_IDX)); -// UserTeam userTeam = new UserTeam(member, group); -// userTeam.setUser(member); -// userTeam.setTeam(group); -// userTeamRepository.save(userTeam); -// } - return new BaseResponse<>(SUCCESS); + CreateGroupResponse createGroupResponse = new CreateGroupResponse(joinCode); + return new BaseResponse<>(createGroupResponse); } // [관리자] 그룹 초대하기 diff --git a/src/main/java/com/lesso/neverland/group/dto/CreateGroupResponse.java b/src/main/java/com/lesso/neverland/group/dto/CreateGroupResponse.java new file mode 100644 index 0000000..00a32ef --- /dev/null +++ b/src/main/java/com/lesso/neverland/group/dto/CreateGroupResponse.java @@ -0,0 +1,3 @@ +package com.lesso.neverland.group.dto; + +public record CreateGroupResponse(Integer joinCode) {} diff --git a/src/main/java/com/lesso/neverland/group/presentation/GroupController.java b/src/main/java/com/lesso/neverland/group/presentation/GroupController.java index bb8cd25..7a35e45 100644 --- a/src/main/java/com/lesso/neverland/group/presentation/GroupController.java +++ b/src/main/java/com/lesso/neverland/group/presentation/GroupController.java @@ -62,7 +62,7 @@ public BaseResponse withdrawGroup(@PathVariable Long groupIdx) { // 그룹 생성 @PostMapping("/create") - public BaseResponse createGroup(@RequestPart MultipartFile image, @RequestPart CreateGroupRequest createGroupRequest) { + public BaseResponse createGroup(@RequestPart MultipartFile image, @RequestPart CreateGroupRequest createGroupRequest) { try { return groupService.createGroup(image, createGroupRequest); } catch (IOException e) { 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 a2861fb..ed42786 100644 --- a/src/main/java/com/lesso/neverland/puzzle/application/PuzzleService.java +++ b/src/main/java/com/lesso/neverland/puzzle/application/PuzzleService.java @@ -79,13 +79,19 @@ private static List getGroupPuzzleDtos(List groupPuzzleL // 퍼즐 상세 조회 public BaseResponse getPuzzleDetail(Long groupIdx, Long puzzleIdx) { Team group = groupRepository.findById(groupIdx).orElseThrow(() -> new BaseException(INVALID_GROUP_IDX)); + User user = userRepository.findById(userService.getUserIdxWithValidation()).orElseThrow(() -> new BaseException(INVALID_USER_IDX)); Puzzle puzzle = puzzleRepository.findById(puzzleIdx).orElseThrow(() -> new BaseException(INVALID_PUZZLE_IDX)); + if (!puzzle.getTeam().equals(group)) throw new BaseException(NO_GROUP_PUZZLE); if (puzzle.getStatus().equals(INACTIVE)) throw new BaseException(ALREADY_DELETED_PUZZLE); + boolean isWriter = puzzle.getUser().equals(user); + boolean hasWrite = puzzlePieceRepository.existsByPuzzleAndUser(puzzle, user); + PuzzleDetailResponse puzzleDetail = new PuzzleDetailResponse(puzzle.getLocation(), puzzle.getPuzzleImage(), puzzle.getPuzzleDate().toString(), puzzle.getUser().getProfile().getNickname(), puzzle.getTitle(), puzzle.getContent(), - getMemberImageList(puzzle), puzzle.getPuzzleMembers().size(), getPuzzlePieceList(puzzle)); + getMemberImageList(puzzle), puzzle.getPuzzleMembers().size(), puzzle.getPuzzlePieces().size()+1, isWriter, hasWrite, + getPuzzlePieceList(puzzle)); return new BaseResponse<>(puzzleDetail); } @@ -160,13 +166,12 @@ private Puzzle createPuzzle(CreatePuzzleRequest createPuzzleRequest, Team group, } // [작성자] 퍼즐 수정 - public BaseResponse editPuzzle(Long groupIdx, Long puzzleIdx, MultipartFile image, EditPuzzleRequest editPuzzleRequest) { + public BaseResponse editPuzzle(Long groupIdx, Long puzzleIdx, MultipartFile newImage, EditPuzzleRequest editPuzzleRequest) { 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); - return new BaseResponse<>(SUCCESS); } 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 292c804..039d18c 100644 --- a/src/main/java/com/lesso/neverland/puzzle/dto/PuzzleDetailResponse.java +++ b/src/main/java/com/lesso/neverland/puzzle/dto/PuzzleDetailResponse.java @@ -9,4 +9,7 @@ public record PuzzleDetailResponse(String location, String content, List memberImageList, // 3명만 Integer memberCount, + Integer writeCount, // PuzzlePieceCount+1 + boolean isWriter, + boolean hasWrite, // 해당 user가 퍼즐피스 작성했는지 여부 List puzzlePieces) {} diff --git a/src/main/java/com/lesso/neverland/puzzle/repository/PuzzlePieceRepository.java b/src/main/java/com/lesso/neverland/puzzle/repository/PuzzlePieceRepository.java index c1b9581..428ab28 100644 --- a/src/main/java/com/lesso/neverland/puzzle/repository/PuzzlePieceRepository.java +++ b/src/main/java/com/lesso/neverland/puzzle/repository/PuzzlePieceRepository.java @@ -1,7 +1,10 @@ package com.lesso.neverland.puzzle.repository; +import com.lesso.neverland.puzzle.domain.Puzzle; import com.lesso.neverland.puzzle.domain.PuzzlePiece; +import com.lesso.neverland.user.domain.User; import org.springframework.data.jpa.repository.JpaRepository; public interface PuzzlePieceRepository extends JpaRepository { + boolean existsByPuzzleAndUser(Puzzle puzzle, User user); }