From d2f797c287d7388e023008abf9a16b9daeaeb0c7 Mon Sep 17 00:00:00 2001 From: stoneTiger0912 Date: Wed, 13 Aug 2025 23:50:16 +0900 Subject: [PATCH 1/9] =?UTF-8?q?Refactor:=20CURRENT=5FTIMESTAMP=EB=A1=9C=20?= =?UTF-8?q?=ED=86=B5=EC=9D=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/project/flipnote/group/entity/Group.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/project/flipnote/group/entity/Group.java b/src/main/java/project/flipnote/group/entity/Group.java index ee138a75..9e2c4f7b 100644 --- a/src/main/java/project/flipnote/group/entity/Group.java +++ b/src/main/java/project/flipnote/group/entity/Group.java @@ -29,7 +29,7 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) @Table(name = "app_groups") @Entity -@SQLDelete(sql = "UPDATE app_groups SET deleted_at = now() WHERE id = ?") +@SQLDelete(sql = "UPDATE app_groups SET deleted_at = CURRENT_TIMESTAMP WHERE id = ?") @SQLRestriction("deleted_at IS NULL") public class Group extends BaseEntity { @Id From aae6bf467c12022a2d7b546bcbe7a587ce64cdad Mon Sep 17 00:00:00 2001 From: stoneTiger0912 Date: Wed, 13 Aug 2025 23:50:31 +0900 Subject: [PATCH 2/9] =?UTF-8?q?Feat:=20=EA=B7=B8=EB=A3=B9=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=20API=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../group/controller/GroupController.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/main/java/project/flipnote/group/controller/GroupController.java b/src/main/java/project/flipnote/group/controller/GroupController.java index f10b21a9..4c57d98c 100644 --- a/src/main/java/project/flipnote/group/controller/GroupController.java +++ b/src/main/java/project/flipnote/group/controller/GroupController.java @@ -3,6 +3,7 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.security.core.annotation.AuthenticationPrincipal; +import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; @@ -24,6 +25,7 @@ public class GroupController { private final GroupService groupService; + //그룹 생성 API @PostMapping("") public ResponseEntity create( @AuthenticationPrincipal AuthPrinciple authPrinciple, @@ -32,6 +34,7 @@ public ResponseEntity create( return ResponseEntity.status(HttpStatus.CREATED).body(res); } + //그룹 상세 API @GetMapping("/{groupId}") public ResponseEntity findGroupDetail( @AuthenticationPrincipal AuthPrinciple authPrinciple, @@ -40,4 +43,16 @@ public ResponseEntity findGroupDetail( return ResponseEntity.ok(res); } + + //그룹 삭제 API + @DeleteMapping("/{groupId}") + public ResponseEntity deleteGroup( + @AuthenticationPrincipal AuthPrinciple authPrinciple, + @PathVariable("groupId") Long groupId + ) { + + groupService.deleteGroup(authPrinciple, groupId); + + return ResponseEntity.noContent().build(); + } } From 2c4fca1216ee789734f7d32cddc382da3de7d5d4 Mon Sep 17 00:00:00 2001 From: stoneTiger0912 Date: Wed, 13 Aug 2025 23:50:43 +0900 Subject: [PATCH 3/9] =?UTF-8?q?Feat:=20=EA=B7=B8=EB=A3=B9=20=EC=97=90?= =?UTF-8?q?=EB=9F=AC=20=EC=BD=94=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../project/flipnote/group/exception/GroupErrorCode.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/project/flipnote/group/exception/GroupErrorCode.java b/src/main/java/project/flipnote/group/exception/GroupErrorCode.java index 5617905c..2902aa74 100644 --- a/src/main/java/project/flipnote/group/exception/GroupErrorCode.java +++ b/src/main/java/project/flipnote/group/exception/GroupErrorCode.java @@ -10,9 +10,10 @@ @Getter @RequiredArgsConstructor public enum GroupErrorCode implements ErrorCode { - GROUP_NOT_FOUND(HttpStatus.NOT_FOUND, "GROUP_002", "그룹이 존재하지 않습니다."), - INVALID_MAX_MEMBER(HttpStatus.BAD_REQUEST, "GROUP_001", "최대 인원 수는 1 이상 100 이하여야 합니다."), - USER_NOT_IN_GROUP(HttpStatus.NOT_FOUND, "GROUP_003", "그룹에 유저가 존재하지 않습니다."); + GROUP_NOT_FOUND(HttpStatus.NOT_FOUND, "GROUP_001", "그룹이 존재하지 않습니다."), + INVALID_MAX_MEMBER(HttpStatus.BAD_REQUEST, "GROUP_002", "최대 인원 수는 1 이상 100 이하여야 합니다."), + USER_NOT_PERMISSION(HttpStatus.FORBIDDEN, "GROUP_003", "그룹 내 권한이 없습니다."), + USER_NOT_IN_GROUP(HttpStatus.NOT_FOUND, "GROUP_004", "그룹에 유저가 존재하지 않습니다."); private final HttpStatus httpStatus; private final String code; From 5822ec074023d4a3c610288fdf2342786eecfc13 Mon Sep 17 00:00:00 2001 From: stoneTiger0912 Date: Wed, 13 Aug 2025 23:50:59 +0900 Subject: [PATCH 4/9] =?UTF-8?q?Fix:=20=EC=A7=80=EC=97=B0=20=EC=83=81?= =?UTF-8?q?=ED=83=9C=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/project/flipnote/group/entity/GroupMember.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/project/flipnote/group/entity/GroupMember.java b/src/main/java/project/flipnote/group/entity/GroupMember.java index c5bc9aea..86a02c52 100644 --- a/src/main/java/project/flipnote/group/entity/GroupMember.java +++ b/src/main/java/project/flipnote/group/entity/GroupMember.java @@ -7,6 +7,7 @@ import jakarta.persistence.Entity; import jakarta.persistence.EnumType; import jakarta.persistence.Enumerated; +import jakarta.persistence.FetchType; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; @@ -31,11 +32,11 @@ public class GroupMember extends BaseEntity { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @ManyToOne + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "group_id", nullable = false) private Group group; - @ManyToOne + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "user_id", nullable = false) private UserProfile user; From 86023238df2d466b2a68971c814882fab1cd72e4 Mon Sep 17 00:00:00 2001 From: stoneTiger0912 Date: Wed, 13 Aug 2025 23:51:34 +0900 Subject: [PATCH 5/9] =?UTF-8?q?Fix:=20=EA=B7=B8=EB=A3=B9=20=EC=9C=A0?= =?UTF-8?q?=EC=A0=80=20=EC=A1=B0=ED=9A=8C=EC=8B=9C=20boolean=EC=9D=B4=20?= =?UTF-8?q?=EC=95=84=EB=8B=8C=20=EA=B0=9D=EC=B2=B4=20=EA=B0=80=EC=A0=B8?= =?UTF-8?q?=EC=98=A4=EA=B8=B0=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../flipnote/group/service/GroupService.java | 35 +++++++++++++------ 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/src/main/java/project/flipnote/group/service/GroupService.java b/src/main/java/project/flipnote/group/service/GroupService.java index 2990dbcd..03ade701 100644 --- a/src/main/java/project/flipnote/group/service/GroupService.java +++ b/src/main/java/project/flipnote/group/service/GroupService.java @@ -54,8 +54,10 @@ public UserProfile validateUser(AuthPrinciple authPrinciple) { /* 그룹 내 유저 조회 */ - public boolean validateGroupInUser(UserProfile user, Long groupId) { - return groupMemberRepository.existsByGroup_idAndUser_id(groupId, user.getId()); + public GroupMember validateGroupInUser(UserProfile user, Long groupId) { + return groupMemberRepository.findByGroup_IdAndUser_Id(groupId, user.getId()).orElseThrow( + () -> new BizException(GroupJoinErrorCode.USER_NOT_IN_GROUP) + ); } /* @@ -67,7 +69,6 @@ public Group validateGroup(Long groupId) { ); } - /* 그룹 생성 */ @@ -138,11 +139,7 @@ private Group createGroup(GroupCreateRequest req) { .imageUrl(req.image()) .build(); - Group saveGroup = groupRepository.save(group); - - log.info("생성 시간: {}", group.getCreatedAt()); - - return saveGroup; + return groupRepository.save(group); } /* @@ -179,14 +176,30 @@ public GroupDetailResponse findGroupDetail(AuthPrinciple authPrinciple, Long gro UserProfile user = validateUser(authPrinciple); //3. 그룹 내 유저 조회 - if (!validateGroupInUser(user, groupId)) { - throw new BizException(GroupJoinErrorCode.USER_NOT_IN_GROUP); - } + validateGroupInUser(user, groupId); return GroupDetailResponse.from(group); } + //그룹 삭제 메서드 + @Transactional public void deleteGroup(AuthPrinciple authPrinciple, Long groupId) { + //1. 그룹 조회 + Group group = validateGroup(groupId); + + //2. 유저 조회 + UserProfile user = validateUser(authPrinciple); + + //3. 그룹 내 유저 조회 + GroupMember groupMember = validateGroupInUser(user, groupId); + + if (!groupMember.getRole().equals(GroupMemberRole.OWNER)) { + throw new BizException(GroupErrorCode.USER_NOT_PERMISSION); + } + + groupMemberRepository.delete(groupMember); + + groupRepository.delete(group); } } From f3105cd6cb1bd1405d87335ecc678915ef20cab0 Mon Sep 17 00:00:00 2001 From: stoneTiger0912 Date: Wed, 20 Aug 2025 21:56:31 +0900 Subject: [PATCH 6/9] =?UTF-8?q?Feat:=20=EA=B7=B8=EB=A3=B9=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=20API=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../group/controller/GroupController.java | 1 - .../flipnote/group/entity/GroupMember.java | 2 - .../group/exception/GroupErrorCode.java | 3 +- .../repository/GroupMemberRepository.java | 2 + .../flipnote/group/service/GroupService.java | 17 +++- .../group/service/GroupServiceTest.java | 93 +++++++++++++++++++ 6 files changed, 113 insertions(+), 5 deletions(-) diff --git a/src/main/java/project/flipnote/group/controller/GroupController.java b/src/main/java/project/flipnote/group/controller/GroupController.java index 4c57d98c..e706783c 100644 --- a/src/main/java/project/flipnote/group/controller/GroupController.java +++ b/src/main/java/project/flipnote/group/controller/GroupController.java @@ -50,7 +50,6 @@ public ResponseEntity deleteGroup( @AuthenticationPrincipal AuthPrinciple authPrinciple, @PathVariable("groupId") Long groupId ) { - groupService.deleteGroup(authPrinciple, groupId); return ResponseEntity.noContent().build(); diff --git a/src/main/java/project/flipnote/group/entity/GroupMember.java b/src/main/java/project/flipnote/group/entity/GroupMember.java index 86a02c52..ec4949fd 100644 --- a/src/main/java/project/flipnote/group/entity/GroupMember.java +++ b/src/main/java/project/flipnote/group/entity/GroupMember.java @@ -25,8 +25,6 @@ @Entity @Table(name = "group_members") @NoArgsConstructor(access = AccessLevel.PROTECTED) -@SQLDelete(sql = "UPDATE group_members SET deleted_at = CURRENT_TIMESTAMP WHERE id = ?") -@SQLRestriction("deleted_at IS NULL") public class GroupMember extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) diff --git a/src/main/java/project/flipnote/group/exception/GroupErrorCode.java b/src/main/java/project/flipnote/group/exception/GroupErrorCode.java index 2902aa74..d9e6353f 100644 --- a/src/main/java/project/flipnote/group/exception/GroupErrorCode.java +++ b/src/main/java/project/flipnote/group/exception/GroupErrorCode.java @@ -13,7 +13,8 @@ public enum GroupErrorCode implements ErrorCode { GROUP_NOT_FOUND(HttpStatus.NOT_FOUND, "GROUP_001", "그룹이 존재하지 않습니다."), INVALID_MAX_MEMBER(HttpStatus.BAD_REQUEST, "GROUP_002", "최대 인원 수는 1 이상 100 이하여야 합니다."), USER_NOT_PERMISSION(HttpStatus.FORBIDDEN, "GROUP_003", "그룹 내 권한이 없습니다."), - USER_NOT_IN_GROUP(HttpStatus.NOT_FOUND, "GROUP_004", "그룹에 유저가 존재하지 않습니다."); + USER_NOT_IN_GROUP(HttpStatus.NOT_FOUND, "GROUP_004", "그룹에 유저가 존재하지 않습니다."), + OTHER_USER_EXIST_IN_GROUP(HttpStatus.CONFLICT, "GROUP_005", "그룹내 오너 제외 유저가 존재합니다."); private final HttpStatus httpStatus; private final String code; diff --git a/src/main/java/project/flipnote/group/repository/GroupMemberRepository.java b/src/main/java/project/flipnote/group/repository/GroupMemberRepository.java index c5001b75..ed51055a 100644 --- a/src/main/java/project/flipnote/group/repository/GroupMemberRepository.java +++ b/src/main/java/project/flipnote/group/repository/GroupMemberRepository.java @@ -20,4 +20,6 @@ public interface GroupMemberRepository extends JpaRepository Optional findByGroup_IdAndUser_Id(Long groupId, Long userId); + long countByGroup_idAndUser_idNot(Long groupId, Long userId); + } diff --git a/src/main/java/project/flipnote/group/service/GroupService.java b/src/main/java/project/flipnote/group/service/GroupService.java index 03ade701..d14fb06d 100644 --- a/src/main/java/project/flipnote/group/service/GroupService.java +++ b/src/main/java/project/flipnote/group/service/GroupService.java @@ -164,6 +164,17 @@ private void validateMaxMember(int maxMember) { } } + /* + 그룹 내 오너를 제외한 인원이 존재하는 경우 체크 + */ + private boolean checkUserNotExistInGroup(UserProfile user, Long groupId) { + long count = groupMemberRepository.countByGroup_idAndUser_idNot(groupId, user.getId()); + if (count > 0) { + return false; + } + return true; + } + /* 그룹 상세 정보 조회 */ @@ -193,11 +204,15 @@ public void deleteGroup(AuthPrinciple authPrinciple, Long groupId) { //3. 그룹 내 유저 조회 GroupMember groupMember = validateGroupInUser(user, groupId); + //4. 유저 권환 조회 if (!groupMember.getRole().equals(GroupMemberRole.OWNER)) { throw new BizException(GroupErrorCode.USER_NOT_PERMISSION); } - groupMemberRepository.delete(groupMember); + //5. 오너를 제외한 모든 유저가 없어야 삭제 가능 + if (!checkUserNotExistInGroup(user, groupId)) { + throw new BizException(GroupErrorCode.OTHER_USER_EXIST_IN_GROUP); + } groupRepository.delete(group); diff --git a/src/test/java/project/flipnote/group/service/GroupServiceTest.java b/src/test/java/project/flipnote/group/service/GroupServiceTest.java index cee94539..e3c77845 100644 --- a/src/test/java/project/flipnote/group/service/GroupServiceTest.java +++ b/src/test/java/project/flipnote/group/service/GroupServiceTest.java @@ -25,6 +25,8 @@ import project.flipnote.fixture.UserFixture; import project.flipnote.group.entity.Category; import project.flipnote.group.entity.Group; +import project.flipnote.group.entity.GroupMember; +import project.flipnote.group.entity.GroupMemberRole; import project.flipnote.group.entity.GroupPermission; import project.flipnote.group.entity.GroupPermissionStatus; import project.flipnote.group.exception.GroupErrorCode; @@ -205,4 +207,95 @@ void before() { assertEquals(GroupErrorCode.GROUP_NOT_FOUND, exception.getErrorCode()); } + + @Test + public void 그룹_삭제_성공() throws Exception { + //given + Group group = Group.builder() + .name("그룹1") + .category(Category.IT) + .description("설명1") + .publicVisible(true) + .applicationRequired(true) + .maxMember(100) + .imageUrl("www.~~~") + .build(); + + GroupMember groupMember = GroupMember.builder() + .group(group) + .role(GroupMemberRole.OWNER) + .user(userProfile) + .build(); + + given(groupRepository.findByIdAndDeletedAtIsNull(1L)).willReturn(Optional.ofNullable(group)); + given(userProfileRepository.findByIdAndStatus(1L, UserStatus.ACTIVE)).willReturn(Optional.ofNullable(userProfile)); + given(groupMemberRepository.findByGroup_IdAndUser_Id(1L,1L)).willReturn(Optional.ofNullable(groupMember)); + given(groupMemberRepository.countByGroup_idAndUser_idNot(1L,1L)).willReturn(0L); + //when + groupService.deleteGroup(authPrinciple, 1L); + + //then + } + + @Test + public void 그룹_삭제_실패_오너아닌경우() throws Exception { + //given + Group group = Group.builder() + .name("그룹1") + .category(Category.IT) + .description("설명1") + .publicVisible(true) + .applicationRequired(true) + .maxMember(100) + .imageUrl("www.~~~") + .build(); + + GroupMember groupMember = GroupMember.builder() + .group(group) + .role(GroupMemberRole.MEMBER) + .user(userProfile) + .build(); + + given(groupRepository.findByIdAndDeletedAtIsNull(1L)).willReturn(Optional.ofNullable(group)); + given(userProfileRepository.findByIdAndStatus(1L, UserStatus.ACTIVE)).willReturn(Optional.ofNullable(userProfile)); + given(groupMemberRepository.findByGroup_IdAndUser_Id(1L,1L)).willReturn(Optional.ofNullable(groupMember)); + // given(groupMemberRepository.countByGroup_idAndUser_idNot(1L,1L)).willReturn(0L); + + //when & then + BizException exception = + assertThrows(BizException.class, () -> groupService.deleteGroup(authPrinciple, 1L)); + + assertEquals(GroupErrorCode.USER_NOT_PERMISSION, exception.getErrorCode()); + } + + @Test + public void 그룹_삭제_실패_유저존재하는경우() throws Exception { + //given + Group group = Group.builder() + .name("그룹1") + .category(Category.IT) + .description("설명1") + .publicVisible(true) + .applicationRequired(true) + .maxMember(100) + .imageUrl("www.~~~") + .build(); + + GroupMember groupMember = GroupMember.builder() + .group(group) + .role(GroupMemberRole.OWNER) + .user(userProfile) + .build(); + + given(groupRepository.findByIdAndDeletedAtIsNull(1L)).willReturn(Optional.ofNullable(group)); + given(userProfileRepository.findByIdAndStatus(1L, UserStatus.ACTIVE)).willReturn(Optional.ofNullable(userProfile)); + given(groupMemberRepository.findByGroup_IdAndUser_Id(1L,1L)).willReturn(Optional.ofNullable(groupMember)); + given(groupMemberRepository.countByGroup_idAndUser_idNot(1L,1L)).willReturn(2L); + + //when & then + BizException exception = + assertThrows(BizException.class, () -> groupService.deleteGroup(authPrinciple, 1L)); + + assertEquals(GroupErrorCode.OTHER_USER_EXIST_IN_GROUP, exception.getErrorCode()); + } } From bffc57767bdf4f1bd537496f204dbc7acc141cee Mon Sep 17 00:00:00 2001 From: stoneTiger0912 Date: Wed, 20 Aug 2025 22:45:52 +0900 Subject: [PATCH 7/9] =?UTF-8?q?Fix:=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=ED=95=98=EB=93=9C=EC=BD=94=EB=94=A9=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../group/service/GroupServiceTest.java | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/test/java/project/flipnote/group/service/GroupServiceTest.java b/src/test/java/project/flipnote/group/service/GroupServiceTest.java index e3c77845..ed74757c 100644 --- a/src/test/java/project/flipnote/group/service/GroupServiceTest.java +++ b/src/test/java/project/flipnote/group/service/GroupServiceTest.java @@ -220,6 +220,7 @@ void before() { .maxMember(100) .imageUrl("www.~~~") .build(); + ReflectionTestUtils.setField(group, "id", 1L); GroupMember groupMember = GroupMember.builder() .group(group) @@ -227,12 +228,12 @@ void before() { .user(userProfile) .build(); - given(groupRepository.findByIdAndDeletedAtIsNull(1L)).willReturn(Optional.ofNullable(group)); - given(userProfileRepository.findByIdAndStatus(1L, UserStatus.ACTIVE)).willReturn(Optional.ofNullable(userProfile)); - given(groupMemberRepository.findByGroup_IdAndUser_Id(1L,1L)).willReturn(Optional.ofNullable(groupMember)); + given(groupRepository.findByIdAndDeletedAtIsNull(1L)).willReturn(Optional.of(group)); + given(userProfileRepository.findByIdAndStatus(userProfile.getId(), UserStatus.ACTIVE)).willReturn(Optional.of(userProfile)); + given(groupMemberRepository.findByGroup_IdAndUser_Id(1L,1L)).willReturn(Optional.of(groupMember)); given(groupMemberRepository.countByGroup_idAndUser_idNot(1L,1L)).willReturn(0L); //when - groupService.deleteGroup(authPrinciple, 1L); + groupService.deleteGroup(authPrinciple, group.getId()); //then } @@ -249,6 +250,7 @@ void before() { .maxMember(100) .imageUrl("www.~~~") .build(); + ReflectionTestUtils.setField(group, "id", 1L); GroupMember groupMember = GroupMember.builder() .group(group) @@ -256,9 +258,9 @@ void before() { .user(userProfile) .build(); - given(groupRepository.findByIdAndDeletedAtIsNull(1L)).willReturn(Optional.ofNullable(group)); - given(userProfileRepository.findByIdAndStatus(1L, UserStatus.ACTIVE)).willReturn(Optional.ofNullable(userProfile)); - given(groupMemberRepository.findByGroup_IdAndUser_Id(1L,1L)).willReturn(Optional.ofNullable(groupMember)); + given(groupRepository.findByIdAndDeletedAtIsNull(group.getId())).willReturn(Optional.ofNullable(group)); + given(userProfileRepository.findByIdAndStatus(userProfile.getId(), UserStatus.ACTIVE)).willReturn(Optional.ofNullable(userProfile)); + given(groupMemberRepository.findByGroup_IdAndUser_Id(group.getId(),userProfile.getId())).willReturn(Optional.ofNullable(groupMember)); // given(groupMemberRepository.countByGroup_idAndUser_idNot(1L,1L)).willReturn(0L); //when & then @@ -287,14 +289,14 @@ void before() { .user(userProfile) .build(); - given(groupRepository.findByIdAndDeletedAtIsNull(1L)).willReturn(Optional.ofNullable(group)); - given(userProfileRepository.findByIdAndStatus(1L, UserStatus.ACTIVE)).willReturn(Optional.ofNullable(userProfile)); - given(groupMemberRepository.findByGroup_IdAndUser_Id(1L,1L)).willReturn(Optional.ofNullable(groupMember)); - given(groupMemberRepository.countByGroup_idAndUser_idNot(1L,1L)).willReturn(2L); + given(groupRepository.findByIdAndDeletedAtIsNull(group.getId())).willReturn(Optional.ofNullable(group)); + given(userProfileRepository.findByIdAndStatus(userProfile.getId(), UserStatus.ACTIVE)).willReturn(Optional.ofNullable(userProfile)); + given(groupMemberRepository.findByGroup_IdAndUser_Id(group.getId(),userProfile.getId())).willReturn(Optional.ofNullable(groupMember)); + given(groupMemberRepository.countByGroup_idAndUser_idNot(group.getId(),userProfile.getId())).willReturn(2L); //when & then BizException exception = - assertThrows(BizException.class, () -> groupService.deleteGroup(authPrinciple, 1L)); + assertThrows(BizException.class, () -> groupService.deleteGroup(authPrinciple, group.getId())); assertEquals(GroupErrorCode.OTHER_USER_EXIST_IN_GROUP, exception.getErrorCode()); } From c06e4ccece361d1bc15b48f8aee596f785afe5d9 Mon Sep 17 00:00:00 2001 From: stoneTiger0912 Date: Thu, 21 Aug 2025 14:11:55 +0900 Subject: [PATCH 8/9] =?UTF-8?q?Fix:=20=EC=98=A4=ED=83=80=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/project/flipnote/group/exception/GroupErrorCode.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/project/flipnote/group/exception/GroupErrorCode.java b/src/main/java/project/flipnote/group/exception/GroupErrorCode.java index fe59142e..c927d8ef 100644 --- a/src/main/java/project/flipnote/group/exception/GroupErrorCode.java +++ b/src/main/java/project/flipnote/group/exception/GroupErrorCode.java @@ -13,7 +13,7 @@ public enum GroupErrorCode implements ErrorCode { INVALID_MAX_MEMBER(HttpStatus.BAD_REQUEST, "GROUP_002", "최대 인원 수는 1 이상 100 이하여야 합니다."), USER_NOT_PERMISSION(HttpStatus.FORBIDDEN, "GROUP_003", "그룹 내 권한이 없습니다."), USER_NOT_IN_GROUP(HttpStatus.NOT_FOUND, "GROUP_004", "그룹에 유저가 존재하지 않습니다."), - OTHER_USER_EXIST_IN_GROUP(HttpStatus.CONFLICT, "GROUP_005", "그룹내 오너 제외 유저가 존재합니다."); + OTHER_USER_EXIST_IN_GROUP(HttpStatus.CONFLICT, "GROUP_005", "그룹내 오너 제외 유저가 존재합니다."), GROUP_IS_ALREADY_MAX_MEMBER(HttpStatus.CONFLICT, "GROUP_006", "그룹 정원이 가득 찼습니다."), ALREADY_GROUP_MEMBER(HttpStatus.CONFLICT, "GROUP_007", "이미 그룹 회원입니다."); From 60bb01ab86796871a00ecde0efc46bfac406e1f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=84=9D=EB=B2=94?= Date: Thu, 21 Aug 2025 15:46:14 +0900 Subject: [PATCH 9/9] =?UTF-8?q?Fix:=20=EC=82=AC=EC=9A=A9=ED=95=98=EB=8A=94?= =?UTF-8?q?=20=EB=A9=94=EC=84=9C=EB=93=9C=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../flipnote/group/service/GroupServiceTest.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/test/java/project/flipnote/group/service/GroupServiceTest.java b/src/test/java/project/flipnote/group/service/GroupServiceTest.java index ed74757c..a59116f6 100644 --- a/src/test/java/project/flipnote/group/service/GroupServiceTest.java +++ b/src/test/java/project/flipnote/group/service/GroupServiceTest.java @@ -148,8 +148,14 @@ void before() { .imageUrl("www.~~~") .build(); + GroupMember groupMember = GroupMember.builder() + .group(group) + .user(userProfile) + .role(GroupMemberRole.MEMBER) + .build(); + given(groupRepository.findByIdAndDeletedAtIsNull(any())).willReturn(Optional.ofNullable(group)); - given(groupMemberRepository.existsByGroup_idAndUser_id(any(), any())).willReturn(true); + given(groupMemberRepository.findByGroup_IdAndUser_Id(any(), any())).willReturn(Optional.of(groupMember)); // 사용자 검증 로직 given(userProfileRepository.findByIdAndStatus(userProfile.getId(), UserStatus.ACTIVE)) .willReturn(Optional.of(userProfile)); @@ -176,7 +182,7 @@ void before() { given(groupRepository.findByIdAndDeletedAtIsNull(any())).willReturn(Optional.ofNullable(group)); given(userProfileRepository.findByIdAndStatus(userProfile.getId(), UserStatus.ACTIVE)).willReturn(Optional.ofNullable(userProfile)); - given(groupMemberRepository.existsByGroup_idAndUser_id(any(), any())).willReturn(false); + given(groupMemberRepository.findByGroup_IdAndUser_Id(any(), any())).willReturn(Optional.empty()); //when BizException exception =