Skip to content

Commit

Permalink
Merge pull request #80 from Likelion12/크루-삭제,탈퇴하기-name-수정
Browse files Browse the repository at this point in the history
크루 삭제,탈퇴하기 name 수정
  • Loading branch information
SonMyeongJin authored Aug 5, 2024
2 parents 7a12ce4 + ab427be commit a1917da
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,21 @@ public BaseResponse<List<GetCrewInquiryResponse>> getCrewInquiries(@RequestHeade
*/
@GetMapping("")
public BaseResponse<GetCrewDetailResponse> getCrewDetail(@RequestHeader("Authorization") String authorization,
@RequestParam Long crewId){
@RequestParam String crewName){
log.info("[CrewController.getCrewDetail]");
Long memberId = jwtProvider.extractIdFromHeader(authorization);
return new BaseResponse<>(crewService.getCrewDetail(memberId, crewId));
return new BaseResponse<>(crewService.getCrewDetail(memberId, crewName));
}

/**
* 크루 참여하기
*/
@PostMapping("/join")
public BaseResponse<Void> joinCrew(@RequestHeader("Authorization") String authorization,
@RequestParam Long crewId){
@RequestParam String crewName){
log.info("[CrewController.joinCrew]");
Long memberId = jwtProvider.extractIdFromHeader(authorization);
crewService.joinCrew(memberId,crewId);
crewService.joinCrew(memberId,crewName);
return new BaseResponse<>(null);
}

Expand All @@ -82,10 +82,10 @@ public BaseResponse<List<GetCrewSearchFilterResponse>> searchFilterCrew(@Request
*/
@PatchMapping("/delete")
public BaseResponse<Void> deleteCrew(@RequestHeader("Authorization") String authorization,
@RequestParam Long crewId){
@RequestParam String crewName){
log.info("[CrewController.deleteCrew]");
Long memberId = jwtProvider.extractIdFromHeader(authorization);
crewService.deleteCrew(memberId,crewId);
crewService.deleteCrew(memberId,crewName);
return new BaseResponse<>(null);
}

Expand All @@ -94,10 +94,10 @@ public BaseResponse<Void> deleteCrew(@RequestHeader("Authorization") String auth
*/
@PatchMapping("/cancel")
public BaseResponse<Void> cancelCrew(@RequestHeader("Authorization") String authorization,
@RequestParam Long crewId){
@RequestParam String crewName){
log.info("[CrewController.deleteCrew]");
Long memberId = jwtProvider.extractIdFromHeader(authorization);
crewService.cancelCrew(memberId,crewId);
crewService.cancelCrew(memberId,crewName);
return new BaseResponse<>(null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ public BaseResponse<PostSocialringResponse> createSocialring(@RequestHeader("Aut
* 소셜링 수정
*/
@PatchMapping("")
public BaseResponse<Void> modifySocialring(@RequestHeader("Authorization") String authorization, @RequestParam long socialringId,
public BaseResponse<Void> modifySocialring(@RequestHeader("Authorization") String authorization, @RequestParam String socialringName,
@RequestBody PatchSocialringModifyRequest patchSocialringModifyRequest)
{
Long memberId = jwtProvider.extractIdFromHeader(authorization);
socialringService.modifySocialring(memberId,socialringId,patchSocialringModifyRequest);
socialringService.modifySocialring(memberId,socialringName,patchSocialringModifyRequest);
return new BaseResponse<>(BaseExceptionResponseStatus.SUCCESS, null);
}

Expand All @@ -52,20 +52,20 @@ public BaseResponse<Void> modifySocialring(@RequestHeader("Authorization") Strin
*/
@GetMapping("")
public BaseResponse<GetSocialringDetailResponse> getSocialringDetail(@RequestHeader("Authorization") String authorization,
@RequestParam Long socialringId){
@RequestParam String socialringName){
log.info("[SocialringController.getSocialringDetail]");
Long memberId = jwtProvider.extractIdFromHeader(authorization);
return new BaseResponse<>(socialringService.getSocialringDetail(memberId, socialringId));
return new BaseResponse<>(socialringService.getSocialringDetail(memberId, socialringName));
}

/**
* 소셜링 참여하기
*/
@PostMapping("/join")
public BaseResponse<Void> joinSocialring(@RequestHeader("Authorization") String authorization,@RequestParam Long socialringId){
public BaseResponse<Void> joinSocialring(@RequestHeader("Authorization") String authorization,@RequestParam String socialringName){
log.info("[SocialringController.joinSocialring]");
Long memberId = jwtProvider.extractIdFromHeader(authorization);
socialringService.joinSocialring(memberId, socialringId);
socialringService.joinSocialring(memberId, socialringName);
return new BaseResponse<>(BaseExceptionResponseStatus.SUCCESS, null);
}

Expand Down Expand Up @@ -105,10 +105,10 @@ public BaseResponse<List<GetSocialringJoinStatusResponse>> joinCompleteSocialrin
*/
@PatchMapping("/delete")
public BaseResponse<Void> deleteSocialring(@RequestHeader("Authorization") String authorization,
@RequestParam("socialringId") Long socialringId) {
@RequestParam("socialringName") String socialringName) {
log.info("[SocialringController.deleteSocialring]");
Long memberId = jwtProvider.extractIdFromHeader(authorization);
socialringService.deleteSocialring(memberId, socialringId);
socialringService.deleteSocialring(memberId, socialringName);
return new BaseResponse<>(BaseExceptionResponseStatus.SUCCESS, null);
}

Expand All @@ -132,10 +132,10 @@ public BaseResponse<Page<GetSocialringSearchResponse>> searchSocialrings(
*/
@PatchMapping("/cancel")
public BaseResponse<Void> cancelSocialring(@RequestHeader("Authorization") String authorization,
@RequestParam("socialringId") Long socialringId) {
@RequestParam("socialringName") String socialringName) {
log.info("[SocialringController.cancelSocialring]");
Long memberId = jwtProvider.extractIdFromHeader(authorization);
socialringService.cancelSocialring(memberId, socialringId);
socialringService.cancelSocialring(memberId, socialringName);
return new BaseResponse<>(BaseExceptionResponseStatus.SUCCESS, null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ public interface CrewRepository extends JpaRepository<Crew, Long> {
@Query("SELECT c FROM Crew c LEFT JOIN c.memberCrewList m GROUP BY c ORDER BY COUNT(m) DESC LIMIT 4")
Optional<List<Crew>> findTop4ByMemberCrewListSize();

Optional<Crew> findByCrewIdAndStatus(Long crewId, BaseStatus status);
Optional<Crew> findByCrewNameAndStatus(String crewName, BaseStatus status);

List<Crew> findAllByStatus(BaseStatus baseStatus);

// 특정 exercise_id 값을 가진 상위 3개의 Crew를 반환하는 쿼리
@Query("SELECT c FROM Crew c WHERE c.exercise.id = :exerciseId AND c.status = :status ORDER BY c.crewId ASC")
List<Crew> findTop3ByExerciseIdAndStatus(@Param("exerciseId") Long exerciseId, @Param("status") BaseStatus status, Pageable pageable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public interface SocialringRepository extends JpaRepository<Socialring, Long> {
Optional<List<Socialring>> findTop4ByOrderBySocialringDate();

Optional<Socialring> findBySocialringIdAndStatus(Long socialringId, BaseStatus status);
Optional<Socialring> findBySocialringNameAndStatus(String socialringName, BaseStatus status);

// 특정 activity_region_id 값을 가진 상위 3개의 Socialring를 반환하는 쿼리
@Query("SELECT c FROM Socialring c WHERE c.activityRegion.id = :activityRegionId AND c.status = :status ORDER BY c.socialringId ASC")
Expand Down
38 changes: 20 additions & 18 deletions src/main/java/com/example/likelion12/service/CrewService.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,16 @@ public List<GetCrewInquiryResponse> getCrewInquiries(Long memberId, int page) {
/**
* 크루 상세 조회
*/
public GetCrewDetailResponse getCrewDetail(Long memberId, Long crewId){
public GetCrewDetailResponse getCrewDetail(Long memberId, String crewName){
log.info("[CrewService.getCrewDetail]");

Crew crew = crewRepository.findByCrewIdAndStatus(crewId, BaseStatus.ACTIVE)
Crew crew = crewRepository.findByCrewNameAndStatus(crewName, BaseStatus.ACTIVE)
.orElseThrow(()->new CrewException(CANNOT_FOUND_CREW));
MemberCrew memberCrew = memberCrewRepository.findByMember_MemberIdAndCrew_CrewIdAndStatus(memberId, crewId, BaseStatus.ACTIVE)
MemberCrew memberCrew = memberCrewRepository.findByMember_MemberIdAndCrew_CrewIdAndStatus(memberId, crew.getCrewId(), BaseStatus.ACTIVE)
.orElseThrow(()-> new CrewException(CANNOT_FOUND_MEMBERCREW));

// 가입한 멤버 리스트 추출
List<MemberCrew> memberCrewList = memberCrewRepository.findByCrew_CrewIdAndStatus(crewId, BaseStatus.ACTIVE)
List<MemberCrew> memberCrewList = memberCrewRepository.findByCrew_CrewIdAndStatus(crew.getCrewId(), BaseStatus.ACTIVE)
.orElseThrow(()-> new MemberCrewException(CANNOT_FOUND_MEMBERCREW_LIST));
// 그 멤버 중에서 사진만 추출해서 반환
List<GetCrewDetailResponse.Crews> memberImgList = memberCrewList.stream()
Expand Down Expand Up @@ -156,24 +156,26 @@ public GetCrewDetailResponse getCrewDetail(Long memberId, Long crewId){
* 크루 참여하기
*/
@Transactional
public void joinCrew(Long memberId, Long crewId){
public void joinCrew(Long memberId, String crewName){
log.info("[CrewService.joinCrew]");
// 참여하려는 member 찾기
Member member = memberRepository.findByMemberIdAndStatus(memberId, BaseStatus.ACTIVE)
.orElseThrow(()-> new MemberException(CANNOT_FOUND_MEMBER));

//크루 찾기
Crew crew = crewRepository.findByCrewNameAndStatus(crewName, BaseStatus.ACTIVE)
.orElseThrow(()->new CrewException(CANNOT_FOUND_CREW));

//크루 아이디로 참여하려는 크루 찾기
if(memberCrewRepository.existsByMember_MemberIdAndCrew_CrewIdAndStatus(memberId,crewId, BaseStatus.ACTIVE)){
if(memberCrewRepository.existsByMember_MemberIdAndCrew_CrewIdAndStatus(memberId,crew.getCrewId(), BaseStatus.ACTIVE)){
throw new MemberCrewException(ALREADY_EXIST_IN_CREW);
}
Crew crew = crewRepository.findByCrewIdAndStatus(crewId, BaseStatus.ACTIVE)
.orElseThrow(()->new CrewException(CANNOT_FOUND_CREW));

// 참여하려는 크루의 총 모집 인원 확인하기
int totalRecruits = crew.getTotalRecruits();

// 현재 참여중인 크루원 수 확인하기
List<MemberCrew> memberCrewList = memberCrewRepository.findByCrew_CrewIdAndStatus(crewId, BaseStatus.ACTIVE)
List<MemberCrew> memberCrewList = memberCrewRepository.findByCrew_CrewIdAndStatus(crew.getCrewId(), BaseStatus.ACTIVE)
.orElseThrow(()->new MemberCrewException(CANNOT_FOUND_MEMBERCREW_LIST));
int currentCrews = memberCrewList.size();

Expand Down Expand Up @@ -280,27 +282,27 @@ else if (matchesCriteria && getCrewSearchFilterRequest.getTotalRecruitsMax() !=
* 크루 삭제하기
*/
@Transactional
public void deleteCrew(Long memberId, Long crewId) {
public void deleteCrew(Long memberId, String crewName) {
log.info("[CrewService.deleteCrew]");

// 크루를 삭제하고자 하는 member
Member member = memberRepository.findByMemberIdAndStatus(memberId, BaseStatus.ACTIVE)
.orElseThrow(()-> new MemberException(CANNOT_FOUND_MEMBER));

//삭제하고자 하는 크루
Crew crew = crewRepository.findByCrewIdAndStatus(crewId, BaseStatus.ACTIVE)
Crew crew = crewRepository.findByCrewNameAndStatus(crewName, BaseStatus.ACTIVE)
.orElseThrow(()->new CrewException(CANNOT_FOUND_CREW));

//삭제하고자 하는 크루의 멤버크루
//해당크루와 관계없음(해당크루에 등록되있지 않음), 멤버크루가 존재하지않음
MemberCrew memberCrew = memberCrewRepository.findByMember_MemberIdAndCrew_CrewIdAndStatus( memberId, crewId, BaseStatus.ACTIVE)
MemberCrew memberCrew = memberCrewRepository.findByMember_MemberIdAndCrew_CrewIdAndStatus( memberId, crew.getCrewId(), BaseStatus.ACTIVE)
.orElseThrow(()->new MemberCrewException(NOT_CREW_MEMBERCREW));

//멤버가 CAPTAIN 권한인지 유효성 검사
memberCrewService.ConfirmCaptainMemberCrew(memberCrew);

//삭제하고자 하는 크루의 멤버크루리스트
List<MemberCrew> memberCrewList = memberCrewRepository.findByCrew_CrewIdAndStatus(crewId, BaseStatus.ACTIVE)
List<MemberCrew> memberCrewList = memberCrewRepository.findByCrew_CrewIdAndStatus(crew.getCrewId(), BaseStatus.ACTIVE)
.orElseThrow(()->new MemberCrewException(CANNOT_FOUND_MEMBERCREW_LIST));

// 멤버 크루리스트 삭제
Expand All @@ -317,21 +319,21 @@ public void deleteCrew(Long memberId, Long crewId) {
* 크루 탈퇴하기
*/
@Transactional
public void cancelCrew(Long memberId, Long crewId) {
public void cancelCrew(Long memberId, String crewName) {
log.info("[CrewService.cancelCrew]");

// 크루를 탈퇴하고자 하는 member
Member member = memberRepository.findByMemberIdAndStatus(memberId, BaseStatus.ACTIVE)
.orElseThrow(() -> new MemberException(CANNOT_FOUND_MEMBER));

//탈퇴하고자 하는 크루
Crew crew = crewRepository.findByCrewIdAndStatus(crewId, BaseStatus.ACTIVE)
.orElseThrow(() -> new CrewException(CANNOT_FOUND_CREW));
Crew crew = crewRepository.findByCrewNameAndStatus(crewName, BaseStatus.ACTIVE)
.orElseThrow(()->new CrewException(CANNOT_FOUND_CREW));

//탈퇴하고자 하는 크루의 멤버크루
//해당크루와 관계없음(해당크루에 등록되있지 않음), 멤버크루가 존재하지않음
MemberCrew memberCrew = memberCrewRepository.findByMember_MemberIdAndCrew_CrewIdAndStatus(memberId, crewId, BaseStatus.ACTIVE)
.orElseThrow(() -> new MemberCrewException(NOT_CREW_MEMBERCREW));
MemberCrew memberCrew = memberCrewRepository.findByMember_MemberIdAndCrew_CrewIdAndStatus( memberId, crew.getCrewId(), BaseStatus.ACTIVE)
.orElseThrow(()->new MemberCrewException(NOT_CREW_MEMBERCREW));

//CAPTAIN일 경우 예외처리 --> 크루삭제
if (BaseRole.CAPTAIN.equals(memberCrew.getRole())){
Expand Down
Loading

0 comments on commit a1917da

Please sign in to comment.