-
Notifications
You must be signed in to change notification settings - Fork 1
[feat] 스터디 가입 요청, 수락, 거절 API 추가 #53
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
Open
crtEvent
wants to merge
11
commits into
dev
Choose a base branch
from
feat/#25-impl-join-request-3
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
80d5a8b
feat: JoinRequest 추가
crtEvent 8c2372d
feat: JoinRequestRepository 추가
crtEvent aa7c312
feat: JoinRequest 생성 API 추가
crtEvent c1ccb9a
feat: JoinRequest 수락 API 추가
crtEvent 63fe789
feat: JoinRequest 거절 API 추가
crtEvent a77e49e
refactor: Service 레이어에 interface 적용 및 로직 분리
crtEvent 50e58ca
fix: save 메서드에 누락된Transactional 어노테이션 추가
crtEvent 408872d
chore: schema.sql에 join_request 테이블 추가
crtEvent 7bac0e5
fix: JoinRequest 상태 검증 시 findBy 대신 existBy 사용
crtEvent ea08a7f
fix: 예외 처리 추가
crtEvent 37c26ff
fix: JoinRequestController 200 OK 응답 반환 방식 변경
crtEvent 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
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
.../flytrap/venusplanner/api/join_request/business/service/JoinRequestCurdFacadeService.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,76 @@ | ||
| package com.flytrap.venusplanner.api.join_request.business.service; | ||
|
|
||
| import static com.flytrap.venusplanner.api.join_request.exception.JoinRequestExceptionType.DuplicateJoinRequestException; | ||
| import static com.flytrap.venusplanner.api.join_request.exception.JoinRequestExceptionType.JoinRequestAlreadyHandledException; | ||
| import static com.flytrap.venusplanner.api.study.exception.StudyExceptionType.StudyAlreadyJoinedException; | ||
| import static com.flytrap.venusplanner.api.study.exception.StudyExceptionType.StudyMismatchException; | ||
|
|
||
| import com.flytrap.venusplanner.api.join_request.domain.JoinRequest; | ||
| import com.flytrap.venusplanner.api.member_study.business.service.MemberStudyValidator; | ||
| import com.flytrap.venusplanner.api.study.business.service.StudyValidator; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| @Transactional(readOnly = true) | ||
| public class JoinRequestCurdFacadeService { | ||
|
|
||
| private final JoinRequestUpdater joinRequestUpdater; | ||
| private final JoinRequestValidator joinRequestValidator; | ||
| private final StudyValidator studyValidator; | ||
| private final MemberStudyValidator memberStudyValidator; | ||
|
|
||
| @Transactional | ||
| public JoinRequest createJoinRequest(Long studyId, Long memberId) { | ||
| studyValidator.validateStudyExists(studyId); | ||
|
|
||
| if (memberStudyValidator.validateMemberBelongsToStudy(memberId, studyId)) { | ||
| throw StudyAlreadyJoinedException(); | ||
| } | ||
|
|
||
| if (joinRequestValidator.validateWaitingJoinRequestExists(studyId, memberId)) { | ||
| throw DuplicateJoinRequestException(); | ||
| } | ||
|
|
||
| return joinRequestUpdater.saveJoinRequest(studyId, memberId); | ||
| } | ||
|
|
||
| @Transactional | ||
| public void acceptJoinRequest(Long studyId, Long requestId, Long memberId) { | ||
| studyValidator.validateStudyExists(studyId); | ||
| memberStudyValidator.validateMemberCanAcceptJoinRequest(memberId, studyId); | ||
|
|
||
| JoinRequest joinRequest = joinRequestValidator.findById(requestId); | ||
|
|
||
| if (!joinRequest.validateStudyIdMatch(studyId)) { | ||
| throw StudyMismatchException("요청한 스터디 ID와 가입 요청의 스터디 ID가 일치하지 않습니다."); | ||
| } | ||
|
|
||
| if (!joinRequest.isWaiting()) { | ||
| throw JoinRequestAlreadyHandledException(); | ||
| } | ||
|
|
||
| joinRequest.accept(); | ||
| } | ||
|
|
||
| @Transactional | ||
| public void rejectJoinRequest(Long studyId, Long requestId, Long memberId) { | ||
| studyValidator.validateStudyExists(studyId); | ||
| memberStudyValidator.validateMemberCanRejectJoinRequest(memberId, studyId); | ||
|
|
||
| JoinRequest joinRequest = joinRequestValidator.findById(requestId); | ||
|
|
||
| if (!joinRequest.validateStudyIdMatch(studyId)) { | ||
| throw StudyMismatchException("요청한 스터디 ID와 가입 요청의 스터디 ID가 일치하지 않습니다."); | ||
| } | ||
|
|
||
| if (!joinRequest.isWaiting()) { | ||
| throw JoinRequestAlreadyHandledException(); | ||
| } | ||
|
|
||
| joinRequest.reject(); | ||
| } | ||
|
|
||
| } |
36 changes: 36 additions & 0 deletions
36
...n/java/com/flytrap/venusplanner/api/join_request/business/service/JoinRequestService.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,36 @@ | ||
| package com.flytrap.venusplanner.api.join_request.business.service; | ||
|
|
||
| import static com.flytrap.venusplanner.api.join_request.exception.JoinRequestExceptionType.JoinRequestNotFoundException; | ||
|
|
||
| import com.flytrap.venusplanner.api.join_request.domain.JoinRequest; | ||
| import com.flytrap.venusplanner.api.join_request.domain.JoinRequestState; | ||
| import com.flytrap.venusplanner.api.join_request.infrastructure.repository.JoinRequestRepository; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| @Transactional(readOnly = true) | ||
| public class JoinRequestService implements JoinRequestUpdater, JoinRequestValidator { | ||
|
|
||
| private final JoinRequestRepository joinRequestRepository; | ||
|
|
||
| @Override | ||
| @Transactional | ||
| public JoinRequest saveJoinRequest(Long studyId, Long memberId) { | ||
| return joinRequestRepository.save(JoinRequest.create(studyId, memberId)); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean validateWaitingJoinRequestExists(Long studyId, Long memberId) { | ||
| return joinRequestRepository.existsByMemberIdAndStudyIdAndState( | ||
| memberId, studyId, JoinRequestState.WAIT); | ||
| } | ||
|
|
||
| @Override | ||
| public JoinRequest findById(Long joinRequestId) { | ||
| return joinRequestRepository.findById(joinRequestId) | ||
| .orElseThrow(() -> JoinRequestNotFoundException(joinRequestId)); | ||
| } | ||
| } |
8 changes: 8 additions & 0 deletions
8
...n/java/com/flytrap/venusplanner/api/join_request/business/service/JoinRequestUpdater.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 com.flytrap.venusplanner.api.join_request.business.service; | ||
|
|
||
| import com.flytrap.venusplanner.api.join_request.domain.JoinRequest; | ||
|
|
||
| public interface JoinRequestUpdater { | ||
|
|
||
| JoinRequest saveJoinRequest(Long studyId, Long memberId); | ||
| } |
8 changes: 8 additions & 0 deletions
8
...java/com/flytrap/venusplanner/api/join_request/business/service/JoinRequestValidator.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 com.flytrap.venusplanner.api.join_request.business.service; | ||
|
|
||
| import com.flytrap.venusplanner.api.join_request.domain.JoinRequest; | ||
|
|
||
| public interface JoinRequestValidator { | ||
| boolean validateWaitingJoinRequestExists(Long studyId, Long memberId); | ||
| JoinRequest findById(Long joinRequestId); | ||
| } |
65 changes: 65 additions & 0 deletions
65
src/main/java/com/flytrap/venusplanner/api/join_request/domain/JoinRequest.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,65 @@ | ||
| package com.flytrap.venusplanner.api.join_request.domain; | ||
|
|
||
| import com.flytrap.venusplanner.global.entity.TimeAuditingBaseEntity; | ||
| import jakarta.persistence.Entity; | ||
| import jakarta.persistence.EnumType; | ||
| import jakarta.persistence.Enumerated; | ||
| import jakarta.persistence.GeneratedValue; | ||
| import jakarta.persistence.GenerationType; | ||
| import jakarta.persistence.Id; | ||
| import jakarta.validation.constraints.NotNull; | ||
| import java.util.Objects; | ||
| import lombok.AccessLevel; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @Entity | ||
| @Getter | ||
| @NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
| public class JoinRequest extends TimeAuditingBaseEntity { | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| private Long id; | ||
|
|
||
| @NotNull | ||
| private Long memberId; | ||
|
|
||
| @NotNull | ||
| private Long studyId; | ||
|
|
||
| @Enumerated(EnumType.STRING) | ||
| private JoinRequestState state; | ||
|
|
||
| @Builder | ||
| private JoinRequest(Long memberId, Long studyId, JoinRequestState state) { | ||
| this.memberId = memberId; | ||
| this.studyId = studyId; | ||
| this.state = state; | ||
| } | ||
|
|
||
| public static JoinRequest create(Long studyId, Long memberId) { | ||
| return JoinRequest.builder() | ||
| .studyId(studyId).memberId(memberId) | ||
| .state(JoinRequestState.WAIT) | ||
| .build(); | ||
| } | ||
|
|
||
| public boolean isWaiting() { | ||
| return this.state == JoinRequestState.WAIT; | ||
| } | ||
|
|
||
| public boolean validateStudyIdMatch(Long studyId) { | ||
| return Objects.equals(this.studyId, studyId); | ||
| } | ||
|
|
||
| public void accept() { | ||
| this.state = JoinRequestState.ACCEPT; | ||
| } | ||
|
|
||
| public void reject() { | ||
| this.state = JoinRequestState.REJECT; | ||
| } | ||
|
|
||
| } |
5 changes: 5 additions & 0 deletions
5
src/main/java/com/flytrap/venusplanner/api/join_request/domain/JoinRequestState.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,5 @@ | ||
| package com.flytrap.venusplanner.api.join_request.domain; | ||
|
|
||
| public enum JoinRequestState { | ||
| WAIT, ACCEPT, REJECT | ||
| } |
21 changes: 21 additions & 0 deletions
21
...in/java/com/flytrap/venusplanner/api/join_request/exception/JoinRequestExceptionType.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,21 @@ | ||
| package com.flytrap.venusplanner.api.join_request.exception; | ||
|
|
||
| import com.flytrap.venusplanner.api.join_request.domain.JoinRequest; | ||
| import com.flytrap.venusplanner.global.exception.CustomException; | ||
| import com.flytrap.venusplanner.global.exception.GeneralExceptionType; | ||
|
|
||
| public class JoinRequestExceptionType extends GeneralExceptionType { | ||
|
|
||
| public static CustomException JoinRequestNotFoundException(Long joinRequestId) { | ||
| return DomainNotFoundException(JoinRequest.class, joinRequestId); | ||
| } | ||
|
|
||
| public static CustomException DuplicateJoinRequestException() { | ||
| return DuplicateDomainException("이미 가입 요청된 상태입니다."); | ||
| } | ||
|
|
||
| public static CustomException JoinRequestAlreadyHandledException() { | ||
| return DuplicateDomainException("이미 처리된 가입 요청입니다"); | ||
| } | ||
|
|
||
| } |
10 changes: 10 additions & 0 deletions
10
...lytrap/venusplanner/api/join_request/infrastructure/repository/JoinRequestRepository.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,10 @@ | ||
| package com.flytrap.venusplanner.api.join_request.infrastructure.repository; | ||
|
|
||
| import com.flytrap.venusplanner.api.join_request.domain.JoinRequest; | ||
| import com.flytrap.venusplanner.api.join_request.domain.JoinRequestState; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| public interface JoinRequestRepository extends JpaRepository<JoinRequest, Long> { | ||
|
|
||
| boolean existsByMemberIdAndStudyIdAndState(Long memberId, Long studyId, JoinRequestState state); | ||
| } |
56 changes: 56 additions & 0 deletions
56
.../flytrap/venusplanner/api/join_request/presentation/controller/JoinRequestController.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,56 @@ | ||
| package com.flytrap.venusplanner.api.join_request.presentation.controller; | ||
|
|
||
| import com.flytrap.venusplanner.api.join_request.business.service.JoinRequestCurdFacadeService; | ||
| import com.flytrap.venusplanner.api.join_request.domain.JoinRequest; | ||
| import com.flytrap.venusplanner.api.join_request.presentation.dto.response.JoinRequestCreateResponse; | ||
| import com.flytrap.venusplanner.global.auth.annotation.SignIn; | ||
| import com.flytrap.venusplanner.global.auth.dto.SessionMember; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.http.HttpStatus; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.PatchMapping; | ||
| import org.springframework.web.bind.annotation.PathVariable; | ||
| import org.springframework.web.bind.annotation.PostMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| @RestController | ||
| @RequiredArgsConstructor | ||
| public class JoinRequestController { | ||
|
|
||
| private final JoinRequestCurdFacadeService joinRequestCrudService; | ||
|
|
||
| @PostMapping("/api/v1/studies/{studyId}/join-requests") | ||
| public ResponseEntity<JoinRequestCreateResponse> requestToJoinStudy( | ||
| @PathVariable Long studyId, | ||
| @SignIn SessionMember sessionMember | ||
| ) { | ||
| JoinRequest joinRequest = joinRequestCrudService | ||
| .createJoinRequest(studyId, sessionMember.id()); | ||
|
|
||
| return ResponseEntity.status(HttpStatus.CREATED) | ||
| .body(new JoinRequestCreateResponse(joinRequest.getId())); | ||
| } | ||
|
|
||
| @PatchMapping("/api/v1/studies/{studyId}/join-requests/{requestId}/accept") | ||
| public ResponseEntity<Void> acceptJoinRequest( | ||
| @PathVariable Long studyId, | ||
| @PathVariable Long requestId, | ||
| @SignIn SessionMember sessionMember | ||
| ) { | ||
| joinRequestCrudService.acceptJoinRequest(studyId, requestId, sessionMember.id()); | ||
|
|
||
| return ResponseEntity.ok(null); | ||
| } | ||
|
|
||
| @PatchMapping("/api/v1/studies/{studyId}/join-requests/{requestId}/reject") | ||
| public ResponseEntity<Void> rejectJoinRequest( | ||
| @PathVariable Long studyId, | ||
| @PathVariable Long requestId, | ||
| @SignIn SessionMember sessionMember | ||
| ) { | ||
| joinRequestCrudService.rejectJoinRequest(studyId, requestId, sessionMember.id()); | ||
|
|
||
| return ResponseEntity.ok(null); | ||
| } | ||
|
|
||
| } | ||
6 changes: 6 additions & 0 deletions
6
...ap/venusplanner/api/join_request/presentation/dto/response/JoinRequestCreateResponse.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,6 @@ | ||
| package com.flytrap.venusplanner.api.join_request.presentation.dto.response; | ||
|
|
||
| public record JoinRequestCreateResponse( | ||
| Long id | ||
| ) { | ||
| } |
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
8 changes: 8 additions & 0 deletions
8
...java/com/flytrap/venusplanner/api/member_study/business/service/MemberStudyValidator.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 com.flytrap.venusplanner.api.member_study.business.service; | ||
|
|
||
| public interface MemberStudyValidator { | ||
|
|
||
| boolean validateMemberBelongsToStudy(Long memberId, Long studyId); | ||
| void validateMemberCanAcceptJoinRequest(Long memberId, Long studyId); | ||
| void validateMemberCanRejectJoinRequest(Long memberId, Long studyId); | ||
| } |
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
4 changes: 4 additions & 0 deletions
4
...lytrap/venusplanner/api/member_study/infrastructure/repository/MemberStudyRepository.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 |
|---|---|---|
| @@ -1,9 +1,13 @@ | ||
| package com.flytrap.venusplanner.api.member_study.infrastructure.repository; | ||
|
|
||
| import com.flytrap.venusplanner.api.member_study.domain.MemberStudy; | ||
| import java.util.Optional; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
| import org.springframework.stereotype.Repository; | ||
|
|
||
| @Repository | ||
| public interface MemberStudyRepository extends JpaRepository<MemberStudy, Long> { | ||
|
|
||
| boolean existsByStudyIdAndMemberId(Long studyId, Long memberId); | ||
| Optional<MemberStudy> findByStudyIdAndMemberId(Long studyId, Long memberId); | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
바디가 없으면
.ok().build()하면 됩니당!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
감사합니다. 고쳤어요!