-
Notifications
You must be signed in to change notification settings - Fork 2
feat: 크루 탈퇴 기능 구현 #37
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| package com.retrip.crew.application.in; | ||
|
|
||
| import com.retrip.crew.application.in.request.crew.CrewOrder; | ||
| import com.retrip.crew.application.in.request.demand.CreateDemandRequest; | ||
| import com.retrip.crew.application.in.request.demand.DemandOrder; | ||
| import com.retrip.crew.application.in.response.demand.*; | ||
| import com.retrip.crew.application.in.usecase.ManageDemandUseCase; | ||
| import com.retrip.crew.application.in.usecase.UpdateRecruitmentUseCase; | ||
| import com.retrip.crew.application.out.repository.CrewDemandRepository; | ||
| import com.retrip.crew.application.out.repository.CrewQueryRepository; | ||
| import com.retrip.crew.application.out.repository.CrewRepository; | ||
| import com.retrip.crew.domain.entity.Crew; | ||
| import com.retrip.crew.domain.entity.Demand; | ||
| import com.retrip.crew.domain.exception.CrewNotFoundException; | ||
| import com.retrip.crew.domain.exception.NotCrewLeaderException; | ||
| import com.retrip.crew.domain.exception.common.BusinessException; | ||
| import com.retrip.crew.domain.exception.common.EntityNotFoundException; | ||
| import com.retrip.crew.domain.vo.DemandStatus; | ||
| import com.retrip.crew.infra.util.PaginationUtils; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.data.domain.Page; | ||
| import org.springframework.data.domain.Pageable; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| import java.util.UUID; | ||
|
|
||
| @Service | ||
| @Transactional | ||
| @RequiredArgsConstructor | ||
| public class DemandService implements UpdateRecruitmentUseCase, ManageDemandUseCase { | ||
| private final CrewRepository crewRepository; | ||
| private final CrewDemandRepository demandRepository; | ||
| private final CrewQueryRepository crewQueryRepository; | ||
|
|
||
| @Override | ||
| public ChangeRecruitmentStatusResponse startRecruitment(UUID crewId) { | ||
| Crew crew = findById(crewId); | ||
| crew.startRecruitment(); | ||
| return ChangeRecruitmentStatusResponse.of(crew); | ||
| } | ||
|
|
||
| @Override | ||
| public ChangeRecruitmentStatusResponse stopRecruitment(UUID crewId) { | ||
| Crew crew = findById(crewId); | ||
| crew.stopRecruitment(); | ||
| return ChangeRecruitmentStatusResponse.of(crew); | ||
| } | ||
|
|
||
| @Override | ||
| public CreateDemandResponse createDemand(UUID crewId, CreateDemandRequest request) { | ||
| Crew crew = findById(crewId); | ||
| Demand demand = crew.demand(request.memberId()); | ||
| return CreateDemandResponse.of(crew.getId(), demand); | ||
| } | ||
|
|
||
| @Override | ||
| public Page<DemandsResponse> getDemands( | ||
| UUID crewId, UUID memberId, String status, Pageable pageable, DemandOrder order, String sort) { | ||
| Crew crew = findById(crewId); | ||
| throwIfNotLeader(crew, memberId, new NotCrewLeaderException()); | ||
| Page<Demand> demands = demandRepository.findByCrewIdAndStatus( | ||
| crewId, DemandStatus.valueOf(status), PaginationUtils.createPageRequest(pageable, order.getField(), sort)); | ||
| return demands.map(d -> DemandsResponse.of(crewId, d)); | ||
| } | ||
|
|
||
| @Override | ||
| public Page<CrewsOfDemandResponse> getCrewsOfDemand( | ||
| UUID crewId, UUID demandId, UUID memberId, Pageable pageable, CrewOrder order, String sort) { | ||
| Crew crew = findById(crewId); | ||
| throwIfNotLeader(crew, memberId, new NotCrewLeaderException()); | ||
| Demand demand = findDemandByIdAndCrewId(demandId, crewId); | ||
| return crewQueryRepository.findAllContainsMember(pageable, demand.getMemberId()); | ||
| } | ||
|
|
||
| private static void throwIfNotLeader(Crew crew, UUID memberId, BusinessException exception) { | ||
| if (!crew.getCrewMembers().isLeader(memberId)) { | ||
| throw exception; | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void cancelDemand(UUID crewId, UUID demandId, UUID memberId) { | ||
| Demand demand = findDemandByIdAndCrewId(demandId, crewId); | ||
| Crew crew = demand.getCrew(); | ||
| crew.cancelDemand(demand); | ||
| } | ||
|
|
||
| @Override | ||
| public RejectDemandResponse rejectDemand(UUID crewId, UUID demandId, UUID memberId) { | ||
| Demand demand = findDemandByIdAndCrewId(demandId, crewId); | ||
| Crew crew = demand.getCrew(); | ||
| crew.rejectDemand(demand); | ||
| return RejectDemandResponse.of(demand); | ||
| } | ||
|
|
||
| @Override | ||
| public ApproveDemandResponse approveDemand(UUID crewId, UUID demandId, UUID memberId) { | ||
| Demand demand = findDemandByIdAndCrewId(demandId, crewId); | ||
| Crew crew = demand.getCrew(); | ||
| crew.approveDemand(demand); | ||
| return ApproveDemandResponse.of(demand); | ||
| } | ||
|
|
||
| private Demand findDemandByIdAndCrewId(UUID demandId, UUID crewId) { | ||
| return demandRepository.findCrewByIdAndCrewId(demandId, crewId) | ||
| .orElseThrow(() -> new EntityNotFoundException("참여 요청 엔티티를 찾을 수 없습니다.")); | ||
| } | ||
|
|
||
| private Crew findById(UUID crewId){ | ||
| return crewRepository.findById(crewId) | ||
| .orElseThrow(CrewNotFoundException::new); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package com.retrip.crew.application.in.request.crew; | ||
|
|
||
| import com.retrip.crew.domain.CrewTrip; | ||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
|
|
||
| import java.util.List; | ||
| import java.util.UUID; | ||
|
|
||
| @Schema(description = "크루 탈퇴 Request") | ||
| public record CrewWithdrawalRequest( | ||
| @Schema(description = "크루원 ID") | ||
| UUID memberId, | ||
|
|
||
| @Schema(description = "참여 중인 크루 여행 목록") | ||
| List<CrewTrip> participatingCrewTrips | ||
| ) { | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| package com.retrip.crew.domain; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
|
|
||
| import java.util.UUID; | ||
|
|
||
| import static com.retrip.crew.domain.CrewTrip.CrewTripType.EXCLUSION; | ||
|
|
||
| public record CrewTrip( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 혹시 해당 CrewTrip을 탈퇴 Request에서 받던데 본인이 참여중인 크루 여행목록은 프론트에서 주는건가요?? 여행에서 가져오는게 아니라?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. API gateway에서 Trip 서비스로 요청해서 참여중인 크루 여행 목록을 받아오고 |
||
| UUID tripId, | ||
| CrewTripType type | ||
| ) { | ||
| public boolean isImpossibleWithdrawal() { | ||
| return this.type == EXCLUSION; | ||
| } | ||
|
|
||
| @Getter | ||
| @AllArgsConstructor | ||
| public enum CrewTripType { | ||
| EXCLUSION("EXCLUSION", "크루원 전용"), | ||
| INCLUSION("INCLUSION", "크루원 포함"); | ||
|
|
||
| private final String code; | ||
| private final String viewName; | ||
| } | ||
| } | ||
|
|
||
|
|
||
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.
withDraw면 탈퇴하다 뜻인가요??
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.
네 맞습니다