-
Notifications
You must be signed in to change notification settings - Fork 0
Feat: [FN-323] 가입 신청 응답 #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
83e39ab
Feat: 가입 신청 응답
stoneTiger0912 d1dd20e
Feat: 가입 신청 응답
stoneTiger0912 a96fa3f
Merge: 충돌해결
stoneTiger0912 a734eb2
Merge: 충돌 해결
stoneTiger0912 a9ffc26
Fix: 낙관적 락 해결
stoneTiger0912 2d4589a
Fix: 200으로 반환으로 수정
stoneTiger0912 2e2b3cd
Fix: 요청값 검증 추가
stoneTiger0912 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
15 changes: 15 additions & 0 deletions
15
src/main/java/flipnote/group/api/dto/request/JoinRespondRequestDto.java
This file contains hidden or 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,15 @@ | ||
| package flipnote.group.api.dto.request; | ||
|
|
||
| import flipnote.group.domain.model.join.JoinStatus; | ||
| import jakarta.validation.constraints.NotNull; | ||
| import jakarta.validation.constraints.Pattern; | ||
|
|
||
| public record JoinRespondRequestDto( | ||
| @NotNull(message = "그룹 신청 상태를 선택해주세요.") | ||
| @Pattern(regexp = "ACCEPT|REJECT", message = "ACCEPT 또는 REJECT만 입력 가능합니다.") | ||
| String status | ||
| ) { | ||
| public JoinStatus joinStatus() { | ||
| return JoinStatus.valueOf(status); | ||
| } | ||
| } |
17 changes: 17 additions & 0 deletions
17
src/main/java/flipnote/group/api/dto/response/JoinRespondResponseDto.java
This file contains hidden or 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,17 @@ | ||
| package flipnote.group.api.dto.response; | ||
|
|
||
| import flipnote.group.application.port.in.result.JoinRespondResult; | ||
| import flipnote.group.domain.model.join.JoinStatus; | ||
|
|
||
| public record JoinRespondResponseDto( | ||
| Long joinId, | ||
| JoinStatus status | ||
| ) { | ||
| public static JoinRespondResponseDto of(JoinRespondResult result) { | ||
|
|
||
| Long joinId = result.join().getId(); | ||
| JoinStatus status = result.join().getStatus(); | ||
|
|
||
| return new JoinRespondResponseDto(joinId, status); | ||
| } | ||
| } |
8 changes: 8 additions & 0 deletions
8
src/main/java/flipnote/group/application/port/in/JoinRespondUseCase.java
This file contains hidden or 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,8 @@ | ||
| package flipnote.group.application.port.in; | ||
|
|
||
| import flipnote.group.application.port.in.command.JoinRespondCommand; | ||
| import flipnote.group.application.port.in.result.JoinRespondResult; | ||
|
|
||
| public interface JoinRespondUseCase { | ||
| JoinRespondResult joinRespond(JoinRespondCommand cmd); | ||
| } |
11 changes: 11 additions & 0 deletions
11
src/main/java/flipnote/group/application/port/in/command/JoinRespondCommand.java
This file contains hidden or 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,11 @@ | ||
| package flipnote.group.application.port.in.command; | ||
|
|
||
| import flipnote.group.domain.model.join.JoinStatus; | ||
|
|
||
| public record JoinRespondCommand( | ||
| Long groupId, | ||
| Long userId, | ||
| Long joinId, | ||
| JoinStatus status | ||
| ) { | ||
| } |
11 changes: 11 additions & 0 deletions
11
src/main/java/flipnote/group/application/port/in/result/JoinRespondResult.java
This file contains hidden or 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,11 @@ | ||
| package flipnote.group.application.port.in.result; | ||
|
|
||
| import flipnote.group.adapter.out.entity.JoinEntity; | ||
|
|
||
| public record JoinRespondResult( | ||
| JoinEntity join | ||
| ) { | ||
| public static JoinRespondResult of(JoinEntity join) { | ||
| return new JoinRespondResult(join); | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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
83 changes: 83 additions & 0 deletions
83
src/main/java/flipnote/group/application/service/JoinRespondService.java
This file contains hidden or 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,83 @@ | ||
| package flipnote.group.application.service; | ||
|
|
||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| import flipnote.group.adapter.out.entity.GroupMemberEntity; | ||
| import flipnote.group.adapter.out.entity.JoinEntity; | ||
| import flipnote.group.adapter.out.entity.RoleEntity; | ||
| import flipnote.group.application.port.in.JoinRespondUseCase; | ||
| import flipnote.group.application.port.in.command.JoinRespondCommand; | ||
| import flipnote.group.application.port.in.result.JoinRespondResult; | ||
| import flipnote.group.application.port.out.GroupMemberRepositoryPort; | ||
| import flipnote.group.application.port.out.GroupRepositoryPort; | ||
| import flipnote.group.application.port.out.GroupRoleRepositoryPort; | ||
| import flipnote.group.application.port.out.JoinRepositoryPort; | ||
| import flipnote.group.domain.model.join.JoinStatus; | ||
| import flipnote.group.domain.model.member.GroupMemberRole; | ||
| import flipnote.group.domain.model.permission.GroupPermission; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| public class JoinRespondService implements JoinRespondUseCase { | ||
|
|
||
| private final JoinRepositoryPort joinRepository; | ||
| private final GroupRoleRepositoryPort groupRoleRepository; | ||
| private final GroupRepositoryPort groupRepository; | ||
| private final GroupMemberRepositoryPort groupMemberRepository; | ||
|
|
||
| private static final GroupPermission MANAGE = GroupPermission.JOIN_REQUEST_MANAGE; | ||
|
|
||
| /** | ||
| * 가입 신청 응답 | ||
| * @param cmd | ||
| * @return | ||
| */ | ||
| @Override | ||
| @Transactional | ||
| public JoinRespondResult joinRespond(JoinRespondCommand cmd) { | ||
|
|
||
| //권한 체크 | ||
| boolean existPermission = groupRoleRepository.checkPermission(cmd.userId(), cmd.groupId(), MANAGE); | ||
|
|
||
| if(!existPermission) { | ||
| throw new IllegalArgumentException("not permission"); | ||
| } | ||
|
|
||
| JoinEntity join = joinRepository.findJoin(cmd.joinId()); | ||
|
|
||
| if(join.getStatus().equals(JoinStatus.ACCEPT)) { | ||
| throw new IllegalArgumentException("already accept"); | ||
| } | ||
stoneTiger0912 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| join.updateStatus(cmd.status()); | ||
|
|
||
| //거절일 경우 | ||
| if(cmd.status().equals(JoinStatus.REJECT)) { | ||
| JoinEntity response = joinRepository.updateJoin(join); | ||
|
|
||
| return new JoinRespondResult(response); | ||
| } | ||
|
|
||
| //수락일 경우 | ||
| boolean joinable = groupRepository.checkJoinable(cmd.groupId()); | ||
|
|
||
| //꽉찼을 경우 | ||
| if(!joinable) { | ||
| throw new IllegalArgumentException("max member"); | ||
| } | ||
|
|
||
| //가입 가능한 경우 | ||
| RoleEntity role = groupRoleRepository.findByIdAndRole(cmd.groupId(), GroupMemberRole.MEMBER); | ||
|
|
||
| //주의: cmd의 유저가 아닌 join의 아이디로 해야함 | ||
| GroupMemberEntity groupMember = GroupMemberEntity.create(cmd.groupId(), join.getUserId(), role); | ||
|
|
||
| groupMemberRepository.save(groupMember); | ||
|
|
||
| JoinEntity response = joinRepository.updateJoin(join); | ||
|
|
||
| return new JoinRespondResult(response); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.