From 7919a81e5a006f8d8af3378ff5f374f6ce75172e Mon Sep 17 00:00:00 2001 From: joonghyun Date: Wed, 29 May 2024 15:53:12 +0900 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=EA=B7=B8=EB=A3=B9=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20=EC=8B=9C=20joinCode=20=EB=B0=98=ED=99=98=ED=95=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../neverland/group/application/GroupService.java | 12 +++--------- .../group/presentation/GroupController.java | 2 +- 2 files changed, 4 insertions(+), 10 deletions(-) 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/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) { From 58f3ed1df0d85bd4ea871e7635cf33ccc5ccb72b Mon Sep 17 00:00:00 2001 From: joonghyun Date: Wed, 29 May 2024 16:04:56 +0900 Subject: [PATCH 2/2] =?UTF-8?q?#87=20fix:=20=ED=8D=BC=EC=A6=90=20=EC=83=81?= =?UTF-8?q?=EC=84=B8=20=EC=A1=B0=ED=9A=8C=20=EC=8B=9C=20=EC=9E=91=EC=84=B1?= =?UTF-8?q?=EC=9E=90=20=EC=97=AC=EB=B6=80,=20=ED=8D=BC=EC=A6=90=ED=94=BC?= =?UTF-8?q?=EC=8A=A4=20=EC=9E=91=EC=84=B1=20=EC=97=AC=EB=B6=80,=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1=20=EC=9D=B8=EC=9B=90=EC=88=98=20=ED=94=BC?= =?UTF-8?q?=EB=93=9C=20=EC=B6=94=EA=B0=80=20=EB=B0=98=ED=99=98=ED=95=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../neverland/group/dto/CreateGroupResponse.java | 3 +++ .../neverland/puzzle/application/PuzzleService.java | 11 ++++++++--- .../neverland/puzzle/dto/PuzzleDetailResponse.java | 3 +++ .../puzzle/repository/PuzzlePieceRepository.java | 3 +++ 4 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/lesso/neverland/group/dto/CreateGroupResponse.java 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/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); }