Skip to content
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

크루 삭제,탈퇴하기 name 수정 #80

Merged
merged 21 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
b7bce89
.
hd0rable Aug 1, 2024
4ad8d26
Merge branch 'develop' of https://github.com/Likelion12/Backend_Team …
hd0rable Aug 1, 2024
9a12167
.
hd0rable Aug 1, 2024
4fa044e
Merge branch 'develop' of https://github.com/Likelion12/Backend_Team …
hd0rable Aug 1, 2024
cd7d6f7
Merge branch 'develop' of https://github.com/Likelion12/Backend_Team …
hd0rable Aug 2, 2024
384f160
Merge branch 'develop' of https://github.com/Likelion12/Backend_Team …
hd0rable Aug 2, 2024
eb1a467
Merge branch 'develop' of https://github.com/Likelion12/Backend_Team …
hd0rable Aug 2, 2024
137c839
Merge branch 'develop' of https://github.com/Likelion12/Backend_Team …
hd0rable Aug 2, 2024
2fcaa5d
Merge branch 'develop' of https://github.com/Likelion12/Backend_Team …
hd0rable Aug 3, 2024
c8f5591
Merge branch 'develop' of https://github.com/Likelion12/Backend_Team …
hd0rable Aug 4, 2024
3dd2f74
Merge branch 'develop' of https://github.com/Likelion12/Backend_Team …
hd0rable Aug 4, 2024
8ab55e7
Merge branch 'develop' of https://github.com/Likelion12/Backend_Team …
hd0rable Aug 5, 2024
e36adf4
fix : 소셜링 상세조회 요청 값 id에서 name으로 수정
hd0rable Aug 5, 2024
178f1ce
fix : 소셜링 수정 요청 값 id에서 name으로 수정
hd0rable Aug 5, 2024
59f8ef8
fix : 소셜링 참여하기 요청 값 id에서 name으로 수정
hd0rable Aug 5, 2024
3618c2e
fix : 소셜링 삭제하기 요청 값 id에서 name으로 수정
hd0rable Aug 5, 2024
712d3ce
fix : 소셜링 취소하기 요청 값 id에서 name으로 수정
hd0rable Aug 5, 2024
25c21b5
fix : 크루 상세조회 요청 값 id에서 name으로 수정
hd0rable Aug 5, 2024
4479145
fix : 크루 참여하기 요청 값 id에서 name으로 수정
hd0rable Aug 5, 2024
92acb63
fix : 크루 삭제하기 요청 값 id에서 name으로 수정
hd0rable Aug 5, 2024
ab427be
Merge branch 'develop' into 크루-삭제,탈퇴하기-name-수정
hd0rable Aug 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -37,11 +37,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 @@ -50,20 +50,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 @@ -103,10 +103,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 @@ -115,10 +115,10 @@ public BaseResponse<Void> deleteSocialring(@RequestHeader("Authorization") Strin
*/
@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 @@ -18,6 +18,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
Loading