-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
...java/com/heachi/housework/api/controller/group/info/request/GroupInfoRegisterRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.heachi.housework.api.controller.group.info.request; | ||
|
||
import jakarta.validation.constraints.NotEmpty; | ||
import jakarta.validation.constraints.NotNull; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.ToString; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class GroupInfoRegisterRequest { | ||
private Long groupMemberId; | ||
private Long groupId; | ||
@NotEmpty | ||
private boolean status; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
|
||
import com.heachi.admin.common.exception.ExceptionMessage; | ||
import com.heachi.admin.common.exception.group.info.GroupInfoException; | ||
import com.heachi.admin.common.exception.group.member.GroupMemberException; | ||
import com.heachi.housework.api.controller.group.info.request.GroupInfoRegisterRequest; | ||
import com.heachi.housework.api.service.group.info.response.GroupInfoUserGroupServiceResponse; | ||
import com.heachi.mysql.define.group.info.repository.GroupInfoRepository; | ||
import com.heachi.mysql.define.group.info.repository.response.GroupInfoUserGroupResponse; | ||
|
@@ -28,6 +30,9 @@ | |
import java.util.Optional; | ||
import java.util.stream.Collectors; | ||
|
||
import static com.heachi.mysql.define.group.info.QGroupInfo.groupInfo; | ||
import static com.heachi.mysql.define.user.QUser.user; | ||
|
||
@Slf4j | ||
@Service | ||
@Transactional(readOnly = true) | ||
|
@@ -156,4 +161,55 @@ public void joinGroupInfo(String email, String joinCode) { | |
} | ||
|
||
} | ||
|
||
@Transactional | ||
public void joinRequestHandler(String adminEmail, GroupInfoRegisterRequest request) { | ||
// 그룹 정보 조회 | ||
GroupInfo groupInfo = groupInfoRepository.findById(request.getGroupId()).orElseThrow(() -> { | ||
log.warn(">>>> 해당 groupId를 가진 그룹이 존재하지 않습니다 : [{}]", request.getGroupId()); | ||
|
||
throw new GroupInfoException(ExceptionMessage.GROUP_INFO_NOT_FOUND); | ||
}); | ||
|
||
// 그룹 가입 요청자 조회 | ||
GroupMember requestGroupMember = groupMemberRepository.findByIdAndGroupInfo(request.getGroupMemberId(), groupInfo).orElseThrow(() -> { | ||
This comment has been minimized.
Sorry, something went wrong. |
||
log.warn(">>>> Group Member Not Found : [{}]", request.getGroupMemberId()); | ||
|
||
throw new GroupMemberException(ExceptionMessage.GROUP_MEMBER_NOT_FOUND); | ||
}); | ||
|
||
// 그룹 가입 요청자 상태 확인: WAITING 상태가 아닐경우 예외처리 | ||
if (requestGroupMember.getStatus() != GroupMemberStatus.WAITING) { | ||
log.warn(">>>> Group Member's Status Is Not WAITING : [{}]", requestGroupMember.getStatus()); | ||
|
||
throw new GroupMemberException(ExceptionMessage.GROUP_MEMBER_STATUS_NOT_WAITING); | ||
} | ||
|
||
// adminEmail로 User 정보 조회 | ||
User adminUser = userRepository.findByEmail(adminEmail).orElseThrow(() -> { | ||
log.warn(">>>> USER NOT FOUND : [{}]", adminEmail); | ||
|
||
throw new UserException(ExceptionMessage.USER_NOT_FOUND); | ||
}); | ||
|
||
// User 정보와 GroupInfo 정보로 GROUP_MEMBER 조회 | ||
GroupMember adminGroupMember = groupMemberRepository.findByUserAndGroupInfo(adminUser, groupInfo).orElseThrow(() -> { | ||
This comment has been minimized.
Sorry, something went wrong.
ghdcksgml1
Owner
|
||
log.warn(">>>> 해당 그룹의 구성원이 아닙니다. : [{}]", adminEmail); | ||
|
||
throw new GroupMemberException(ExceptionMessage.GROUP_MEMBER_NOT_FOUND); | ||
}); | ||
|
||
// role이 GROUP_ADMIN(그룹장)인지 확인 | ||
if (adminGroupMember.getRole() != GroupMemberRole.GROUP_ADMIN) { | ||
log.warn(">>>> 해당 그룹의 그룹장이 아닙니다. : [role: {}]", adminGroupMember.getRole()); | ||
|
||
throw new GroupMemberException(ExceptionMessage.GROUP_MEMBER_ROLE_NOT_ADMIN); | ||
} | ||
|
||
// status에 따른 그룹 가입 요청 핸들링 | ||
GroupMemberStatus updateStatus = request.isStatus() ? GroupMemberStatus.ACCEPT : GroupMemberStatus.WAITING; | ||
|
||
// requestGroupMember update | ||
requestGroupMember.updateStatus(updateStatus); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
groupMemberId, groupInfoId를 모두 조건 걸어서 한번의 쿼리로 줄일 수 있지 않을까요??