Skip to content

Commit

Permalink
fix : final 추가, group_member -> member_group, 픽스처로 분리
Browse files Browse the repository at this point in the history
  • Loading branch information
seokho-1116 committed May 15, 2024
1 parent 7e5c408 commit d87d0c4
Show file tree
Hide file tree
Showing 28 changed files with 167 additions and 152 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class GroupCommandApiController implements GroupCommandApi {
@PostMapping
public ResponseEntity<ApiSpec<String>> createGroup(
@AuthenticationPrincipal final Long memberId,
@Valid @RequestBody GroupCreateRequest request
@Valid @RequestBody final GroupCreateRequest request
) {
final String groupProfileUrl = s3UrlGenerator.generateFileName(memberId,
request.groupDirectory(), request.groupImage());
Expand Down Expand Up @@ -60,9 +60,9 @@ public ResponseEntity<ApiSpec<String>> deleteGroupById(
@PatchMapping(value = "/{group_id}", consumes = {"application/json"})
@Override
public ResponseEntity<ApiSpec<String>> updateGroupById(
@AuthenticationPrincipal Long memberId,
@PathVariable("group_id") Long groupId,
@RequestBody GroupUpdateRequest request
@AuthenticationPrincipal final Long memberId,
@PathVariable("group_id") final Long groupId,
@Valid @RequestBody final GroupUpdateRequest request
) {
groupCommandService.updateGroup(memberId, groupId, request.toDto());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import static com.querydsl.core.group.GroupBy.groupBy;
import static com.querydsl.core.group.GroupBy.list;
import static site.timecapsulearchive.core.domain.group.entity.QGroup.group;
import static site.timecapsulearchive.core.domain.group_member.entity.QMemberGroup.memberGroup;
import static site.timecapsulearchive.core.domain.member_group.entity.QMemberGroup.memberGroup;
import static site.timecapsulearchive.core.domain.member.entity.QMember.member;

import com.querydsl.core.types.Projections;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
import site.timecapsulearchive.core.domain.group.exception.GroupDeleteFailException;
import site.timecapsulearchive.core.domain.group.exception.GroupNotFoundException;
import site.timecapsulearchive.core.domain.group.repository.GroupRepository;
import site.timecapsulearchive.core.domain.group_member.entity.MemberGroup;
import site.timecapsulearchive.core.domain.group_member.exception.GroupMemberNotFoundException;
import site.timecapsulearchive.core.domain.group_member.exception.NoGroupAuthorityException;
import site.timecapsulearchive.core.domain.group_member.repository.groupInviteRepository.GroupInviteRepository;
import site.timecapsulearchive.core.domain.group_member.repository.memberGroupRepository.MemberGroupRepository;
import site.timecapsulearchive.core.domain.member_group.entity.MemberGroup;
import site.timecapsulearchive.core.domain.member_group.exception.MemberGroupNotFoundException;
import site.timecapsulearchive.core.domain.member_group.exception.NoGroupAuthorityException;
import site.timecapsulearchive.core.domain.member_group.repository.groupInviteRepository.GroupInviteRepository;
import site.timecapsulearchive.core.domain.member_group.repository.memberGroupRepository.MemberGroupRepository;
import site.timecapsulearchive.core.domain.member.entity.Member;
import site.timecapsulearchive.core.domain.member.exception.MemberNotFoundException;
import site.timecapsulearchive.core.domain.member.repository.MemberRepository;
Expand Down Expand Up @@ -84,7 +84,7 @@ public void deleteGroup(final Long memberId, final Long groupId) {
checkGroupMemberExist(groupMembers);
checkGroupCapsuleExist(groupId);

List<Long> groupInviteIds = groupInviteRepository.findGroupInviteIdsByGroupIdAndGroupOwnerId(
final List<Long> groupInviteIds = groupInviteRepository.findGroupInviteIdsByGroupIdAndGroupOwnerId(
groupId, memberId);
groupInviteRepository.bulkDelete(groupInviteIds);

Expand All @@ -95,23 +95,23 @@ public void deleteGroup(final Long memberId, final Long groupId) {
s3ObjectManager.deleteObject(groupProfilePath);
}

private void checkGroupOwnership(Long memberId, List<MemberGroup> groupMembers) {
private void checkGroupOwnership(final Long memberId, final List<MemberGroup> groupMembers) {
final boolean isGroupOwner = groupMembers.stream()
.anyMatch(mg -> mg.getMember().getId().equals(memberId) && mg.getIsOwner());
if (!isGroupOwner) {
throw new NoGroupAuthorityException();
}
}

private void checkGroupMemberExist(List<MemberGroup> groupMembers) {
private void checkGroupMemberExist(final List<MemberGroup> groupMembers) {
final boolean groupMemberExist = groupMembers.size() > 1;
if (groupMemberExist) {
throw new GroupDeleteFailException(ErrorCode.GROUP_MEMBER_EXIST_ERROR);
}
groupMembers.forEach(memberGroupRepository::delete);
}

private void checkGroupCapsuleExist(Long groupId) {
private void checkGroupCapsuleExist(final Long groupId) {
final boolean groupCapsuleExist = groupCapsuleQueryRepository.findGroupCapsuleExistByGroupId(
groupId);
if (groupCapsuleExist) {
Expand All @@ -131,10 +131,10 @@ private void checkGroupCapsuleExist(Long groupId) {
* @param dto 업데이트할 그룹 정보
*/
@Transactional
public void updateGroup(Long groupOwnerId, Long groupId, GroupUpdateDto dto) {
public void updateGroup(final Long groupOwnerId, final Long groupId, final GroupUpdateDto dto) {
checkGroupOwnership(groupOwnerId, groupId);

Group group = groupRepository.findGroupById(groupId)
final Group group = groupRepository.findGroupById(groupId)
.orElseThrow(GroupNotFoundException::new);

group.updateGroupName(dto.groupName());
Expand All @@ -148,11 +148,11 @@ public void updateGroup(Long groupOwnerId, Long groupId, GroupUpdateDto dto) {
group.updateGroupProfileUrl(groupProfileUrl);
}

private void checkGroupOwnership(Long groupOwnerId, Long groupId) {
private void checkGroupOwnership(final Long groupOwnerId, final Long groupId) {
final Boolean isOwner = memberGroupRepository.findIsOwnerByMemberIdAndGroupId(
groupOwnerId,
groupId)
.orElseThrow(GroupMemberNotFoundException::new);
.orElseThrow(MemberGroupNotFoundException::new);
if (!isOwner) {
throw new NoGroupAuthorityException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import site.timecapsulearchive.core.domain.capsule.entity.Capsule;
import site.timecapsulearchive.core.domain.friend.entity.FriendInvite;
import site.timecapsulearchive.core.domain.friend.entity.MemberFriend;
import site.timecapsulearchive.core.domain.group_member.entity.MemberGroup;
import site.timecapsulearchive.core.domain.member_group.entity.MemberGroup;
import site.timecapsulearchive.core.domain.history.entity.History;
import site.timecapsulearchive.core.global.entity.BaseEntity;
import site.timecapsulearchive.core.global.util.NullCheck;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package site.timecapsulearchive.core.domain.member.repository;

import static site.timecapsulearchive.core.domain.friend.entity.QMemberFriend.memberFriend;
import static site.timecapsulearchive.core.domain.group_member.entity.QMemberGroup.memberGroup;
import static site.timecapsulearchive.core.domain.member_group.entity.QMemberGroup.memberGroup;
import static site.timecapsulearchive.core.domain.member.entity.QMember.member;
import static site.timecapsulearchive.core.domain.member.entity.QNotification.notification;
import static site.timecapsulearchive.core.domain.member.entity.QNotificationCategory.notificationCategory;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package site.timecapsulearchive.core.domain.group_member.api.command;
package site.timecapsulearchive.core.domain.member_group.api.command;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
Expand All @@ -9,12 +9,10 @@
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import site.timecapsulearchive.core.global.common.response.ApiSpec;
import site.timecapsulearchive.core.global.error.ErrorResponse;

public interface GroupMemberCommandApi {
public interface MemberGroupCommandApi {

@Operation(
summary = "그룹 탈퇴",
Expand All @@ -26,7 +24,7 @@ public interface GroupMemberCommandApi {
</ul>
""",
security = {@SecurityRequirement(name = "user_token")},
tags = {"group member"}
tags = {"member group"}
)
@ApiResponses(value = {
@ApiResponse(
Expand Down Expand Up @@ -59,7 +57,7 @@ ResponseEntity<ApiSpec<String>> quitGroup(
summary = "그룹 요청",
description = "그룹장인 경우 친구에게 그룹 가입 요청을 할 수 있다.",
security = {@SecurityRequirement(name = "user_token")},
tags = {"group member"}
tags = {"member group"}
)
@ApiResponses(value = {
@ApiResponse(
Expand All @@ -81,7 +79,7 @@ ResponseEntity<ApiSpec<String>> inviteGroup(
summary = "그룹 요청 수락",
description = "특정 그룹으로부터 그룹 요청을 수락한다.",
security = {@SecurityRequirement(name = "user_token")},
tags = {"group member"}
tags = {"member group"}
)
@ApiResponses(value = {
@ApiResponse(
Expand Down Expand Up @@ -111,7 +109,7 @@ ResponseEntity<ApiSpec<String>> acceptGroupInvitation(
summary = "그룹 요청 거부",
description = "특정 그룹으로부터 초대 요청을 거부한다.",
security = {@SecurityRequirement(name = "user_token")},
tags = {"group member"}
tags = {"member group"}
)
@ApiResponses(value = {
@ApiResponse(
Expand All @@ -132,7 +130,7 @@ ResponseEntity<ApiSpec<String>> rejectGroupInvitation(
summary = "그룹원 추방",
description = "요청한 사용자가 그룹장인 경우 특정 그룹원을 그룹에서 추방한다.",
security = {@SecurityRequirement(name = "user_token")},
tags = {"group member"}
tags = {"member group"}
)
@ApiResponses(value = {
@ApiResponse(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package site.timecapsulearchive.core.domain.group_member.api.command;
package site.timecapsulearchive.core.domain.member_group.api.command;

import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
Expand All @@ -8,24 +8,24 @@
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import site.timecapsulearchive.core.domain.group_member.service.GroupMemberCommandService;
import site.timecapsulearchive.core.domain.member_group.service.MemberGroupCommandService;
import site.timecapsulearchive.core.global.common.response.ApiSpec;
import site.timecapsulearchive.core.global.common.response.SuccessCode;

@RestController
@RequestMapping("/groups")
@RequiredArgsConstructor
public class GroupMemberCommandApiController implements GroupMemberCommandApi {
public class MemberGroupCommandApiController implements MemberGroupCommandApi {

private final GroupMemberCommandService groupMemberCommandService;
private final MemberGroupCommandService MemberGroupCommandService;

@DeleteMapping(value = "/{group_id}/members/quit")
@Override
public ResponseEntity<ApiSpec<String>> quitGroup(
@AuthenticationPrincipal final Long memberId,
@PathVariable("group_id") final Long groupId
) {
groupMemberCommandService.quitGroup(memberId, groupId);
MemberGroupCommandService.quitGroup(memberId, groupId);

return ResponseEntity.ok(ApiSpec.empty(SuccessCode.SUCCESS));
}
Expand All @@ -37,7 +37,7 @@ public ResponseEntity<ApiSpec<String>> inviteGroup(
@PathVariable("group_id") final Long groupId,
@PathVariable("target_id") final Long targetId
) {
groupMemberCommandService.inviteGroup(memberId, groupId, targetId);
MemberGroupCommandService.inviteGroup(memberId, groupId, targetId);

return ResponseEntity.ok(
ApiSpec.empty(
Expand All @@ -53,7 +53,7 @@ public ResponseEntity<ApiSpec<String>> acceptGroupInvitation(
@PathVariable("group_id") final Long groupId,
@PathVariable("target_id") final Long targetId
) {
groupMemberCommandService.acceptGroupInvite(memberId, groupId, targetId);
MemberGroupCommandService.acceptGroupInvite(memberId, groupId, targetId);

return ResponseEntity.ok(
ApiSpec.empty(
Expand All @@ -68,7 +68,7 @@ public ResponseEntity<ApiSpec<String>> rejectGroupInvitation(
@PathVariable("group_id") final Long groupId,
@PathVariable("target_id") final Long targetId) {

groupMemberCommandService.rejectRequestGroup(memberId, groupId, targetId);
MemberGroupCommandService.rejectRequestGroup(memberId, groupId, targetId);

return ResponseEntity.ok(
ApiSpec.empty(
Expand All @@ -84,7 +84,7 @@ public ResponseEntity<ApiSpec<String>> kickGroupMember(
@PathVariable("group_id") final Long groupId,
@PathVariable("group_member_id") final Long groupMemberId
) {
groupMemberCommandService.kickGroupMember(memberId, groupId, groupMemberId);
MemberGroupCommandService.kickGroupMember(memberId, groupId, groupMemberId);

return ResponseEntity.ok(ApiSpec.empty(SuccessCode.SUCCESS));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package site.timecapsulearchive.core.domain.group_member.data;
package site.timecapsulearchive.core.domain.member_group.data;

public record GroupOwnerSummaryDto(
String nickname,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package site.timecapsulearchive.core.domain.group_member.entity;
package site.timecapsulearchive.core.domain.member_group.entity;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package site.timecapsulearchive.core.domain.group_member.entity;
package site.timecapsulearchive.core.domain.member_group.entity;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package site.timecapsulearchive.core.domain.group_member.exception;
package site.timecapsulearchive.core.domain.member_group.exception;

import site.timecapsulearchive.core.global.error.ErrorCode;
import site.timecapsulearchive.core.global.error.exception.BusinessException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package site.timecapsulearchive.core.domain.group_member.exception;
package site.timecapsulearchive.core.domain.member_group.exception;

import site.timecapsulearchive.core.global.error.ErrorCode;
import site.timecapsulearchive.core.global.error.exception.BusinessException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package site.timecapsulearchive.core.domain.group_member.exception;
package site.timecapsulearchive.core.domain.member_group.exception;

import site.timecapsulearchive.core.global.error.ErrorCode;
import site.timecapsulearchive.core.global.error.exception.BusinessException;

public class GroupMemberDuplicatedIdException extends BusinessException {
public class MemberGroupKickDuplicatedIdException extends BusinessException {

public GroupMemberDuplicatedIdException() {
public MemberGroupKickDuplicatedIdException() {
super(ErrorCode.GROUP_MEMBER_DUPLICATED_ID_ERROR);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package site.timecapsulearchive.core.domain.group_member.exception;
package site.timecapsulearchive.core.domain.member_group.exception;

import site.timecapsulearchive.core.global.error.ErrorCode;
import site.timecapsulearchive.core.global.error.exception.BusinessException;

public class GroupMemberNotFoundException extends BusinessException {
public class MemberGroupNotFoundException extends BusinessException {

public GroupMemberNotFoundException() {
public MemberGroupNotFoundException() {
super(ErrorCode.GROUP_MEMBER_NOT_FOUND_ERROR);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package site.timecapsulearchive.core.domain.group_member.exception;
package site.timecapsulearchive.core.domain.member_group.exception;

import site.timecapsulearchive.core.global.error.ErrorCode;
import site.timecapsulearchive.core.global.error.exception.BusinessException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package site.timecapsulearchive.core.domain.group_member.repository.groupInviteRepository;
package site.timecapsulearchive.core.domain.member_group.repository.groupInviteRepository;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package site.timecapsulearchive.core.domain.group_member.repository.groupInviteRepository;
package site.timecapsulearchive.core.domain.member_group.repository.groupInviteRepository;


import static site.timecapsulearchive.core.domain.group_member.entity.QGroupInvite.groupInvite;
import static site.timecapsulearchive.core.domain.member_group.entity.QGroupInvite.groupInvite;

import com.querydsl.jpa.impl.JPAQueryFactory;
import java.sql.PreparedStatement;
Expand All @@ -23,7 +23,7 @@ public class GroupInviteQueryRepositoryImpl implements GroupInviteQueryRepositor
private final JPAQueryFactory jpaQueryFactory;

@Override
public void bulkSave(Long groupOwnerId, List<Long> groupMemberIds) {
public void bulkSave(final Long groupOwnerId, final List<Long> groupMemberIds) {
jdbcTemplate.batchUpdate(
"""
INSERT INTO group_invite (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package site.timecapsulearchive.core.domain.group_member.repository.groupInviteRepository;
package site.timecapsulearchive.core.domain.member_group.repository.groupInviteRepository;

import java.util.List;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.query.Param;
import site.timecapsulearchive.core.domain.group_member.entity.GroupInvite;
import site.timecapsulearchive.core.domain.member_group.entity.GroupInvite;

public interface GroupInviteRepository extends Repository<GroupInvite, Long>,
GroupInviteQueryRepository {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package site.timecapsulearchive.core.domain.group_member.repository.memberGroupRepository;
package site.timecapsulearchive.core.domain.member_group.repository.memberGroupRepository;

import java.util.Optional;
import site.timecapsulearchive.core.domain.group_member.data.GroupOwnerSummaryDto;
import site.timecapsulearchive.core.domain.member_group.data.GroupOwnerSummaryDto;

public interface MemberGroupQueryRepository {

Expand Down
Loading

0 comments on commit d87d0c4

Please sign in to comment.