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

Feat : 소셜링 취소하기 #67

Merged
merged 5 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -49,7 +49,8 @@ public enum BaseExceptionResponseStatus implements ResponseStatus{
ALREADY_EXIST_IN_SOCIALRING(8003, HttpStatus.BAD_REQUEST.value(), "해당 소셜링에 이미 등록된 멤버입니다."),
N0T_EXIST_JOIN_SOCIALRING(8004, HttpStatus.BAD_REQUEST.value(), "참가 중인 소셜링이 존재하지 않습니다."),
N0T_EXIST_JOIN_BEFORE_SOCIALRING(8005, HttpStatus.BAD_REQUEST.value(), "참가 예정인 소셜링이 존재 하지않습니다."),
N0T_EXIST_JOIN_COMPLETE_SOCIALRING(8005, HttpStatus.BAD_REQUEST.value(), "참가 완료한 소셜링이 존재 하지않습니다."),
N0T_EXIST_JOIN_COMPLETE_SOCIALRING(8006, HttpStatus.BAD_REQUEST.value(), "참가 완료한 소셜링이 존재 하지않습니다."),
CANNOT_CANCEL_BY_CAPTAIN(8007, HttpStatus.BAD_REQUEST.value(), "소셜링 모임장은 소셜링을 나갈 수 없습니다. 소셜링 삭제를 이용해주세요"),

/**
* 9000 : crew 관련
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,17 @@ public BaseResponse<Void> deleteSocialring(@RequestHeader("Authorization") Strin
socialringService.deleteSocialring(memberId, socialringId);
return new BaseResponse<>(BaseExceptionResponseStatus.SUCCESS, null);
}

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ public MemberSocialring(BaseRole baseRole, Socialring socialring, Member member,
this.status = baseStatus;
}

// 상태를 'delete'로 변경하는 메서드
public void setStatusToDelete() {
this.status = BaseStatus.DELETE;
}

public void setStatus(BaseStatus status) {
this.status = status;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.example.likelion12.domain.*;
import com.example.likelion12.domain.base.BaseGender;
import com.example.likelion12.domain.base.BaseLevel;
import com.example.likelion12.domain.base.BaseRole;
import com.example.likelion12.domain.base.BaseStatus;
import com.example.likelion12.dto.socialring.*;
import com.example.likelion12.repository.*;
Expand Down Expand Up @@ -368,4 +369,37 @@ public void deleteSocialring(Long memberId, Long socialringId) {
memberSocialringRepository.save(memberSocialringEntry);
}
}

/**
* 소셜링 취소
*/
@Transactional
public void cancelSocialring(Long memberId, Long socialringId) {
log.info("[SocialringService.cancelSocialring]");

// 소셜링을 취소하고자 하는 멤버 찾고
Member member = memberRepository.findByMemberIdAndStatus(memberId, BaseStatus.ACTIVE)
.orElseThrow(() -> new MemberException(CANNOT_FOUND_MEMBER));

// 취소하고자 하는 소셜링 찾고
Socialring socialring = socialringRepository.findBySocialringIdAndStatus(socialringId, BaseStatus.ACTIVE)
.orElseThrow(() -> new SocialringException(CANNOT_FOUND_SOCIALRING));

// 해당 소셜링에 등록된 멤버 소셜링 중, 취소할 멤버의 멤버소셜링 값을 가져와서
MemberSocialring memberSocialring = memberSocialringRepository.findByMember_MemberIdAndSocialring_SocialringIdAndStatus(memberId,
socialringId, BaseStatus.ACTIVE).orElseThrow(() -> new MemberSocialringException(CANNOT_FOUND_MEMBERSOCIALRING));

// 가져온 멤버 소셜링의 값으로 캡틴인지 확인하고
memberSocialringService.ConfirmCaptainMemberSocialring(memberSocialring);

// 캡틴인 경우 예외 발생
if (memberSocialring.getRole() == BaseRole.CAPTAIN) {
throw new MemberSocialringException(CANNOT_CANCEL_BY_CAPTAIN);
}

// 캡틴이 아닌경우 정상적으로 상태를 DELETE로 변경
memberSocialring.setStatusToDelete();
memberSocialringRepository.save(memberSocialring);
}

}
1 change: 0 additions & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ spring:
kakao:
client-id: ${CLIENT_ID}
redirect-uri: http://43.202.94.241:8080/auth/kakao/callback

---
jwt:
secret: ${JWT_SECRET}
Expand Down
Loading