diff --git a/src/main/java/com/example/likelion12/common/response/status/BaseExceptionResponseStatus.java b/src/main/java/com/example/likelion12/common/response/status/BaseExceptionResponseStatus.java index fcde466..b09546f 100644 --- a/src/main/java/com/example/likelion12/common/response/status/BaseExceptionResponseStatus.java +++ b/src/main/java/com/example/likelion12/common/response/status/BaseExceptionResponseStatus.java @@ -68,6 +68,7 @@ public enum BaseExceptionResponseStatus implements ResponseStatus{ ALREADY_EXIST_IN_CREW(10002, HttpStatus.BAD_REQUEST.value(), "해당 크루에 이미 등록된 멤버입니다."), NOT_MEMBERCREW_CAPTAIN(10003, HttpStatus.BAD_REQUEST.value(), "크루 수정,삭제에 접근할수없는 권한입니다."), NOT_CREW_MEMBERCREW(10004, HttpStatus.BAD_REQUEST.value(), "해당 크루에 참여 상태가 아닙니다."), + CANNOT_CREW_CANCEL(10005, HttpStatus.BAD_REQUEST.value(), "해당 크루를 탈퇴 할 수 없습니다. 크루 삭제를 이용해주세요."), /** * 11000 : Review 관련 diff --git a/src/main/java/com/example/likelion12/config/SecurityConfig.java b/src/main/java/com/example/likelion12/config/SecurityConfig.java index 5d64c5c..ca10697 100644 --- a/src/main/java/com/example/likelion12/config/SecurityConfig.java +++ b/src/main/java/com/example/likelion12/config/SecurityConfig.java @@ -4,6 +4,7 @@ import lombok.RequiredArgsConstructor; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.http.HttpMethod; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configurers.CsrfConfigurer; import org.springframework.security.config.http.SessionCreationPolicy; @@ -24,16 +25,17 @@ public class SecurityConfig { public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { http .csrf(CsrfConfigurer::disable) - .cors(cors -> cors.configurationSource(corsConfigurationSource())) // CORS 설정 추가 + .cors(cors -> cors.configurationSource(corsConfigurationSource())) .authorizeHttpRequests(requests -> requests - .requestMatchers("/test", "/auth/kakao/callback", "/user/signup","/main").permitAll() // 이 URL은 모두에게 허용 - .anyRequest().authenticated() // 그 외의 모든 요청은 인증 필요 + .requestMatchers(HttpMethod.OPTIONS, "/**").permitAll() + .requestMatchers("/test", "/auth/kakao/callback", "/user/signup", "/main").permitAll() + .anyRequest().authenticated() ) .sessionManagement(sessionManagement -> sessionManagement.sessionCreationPolicy(SessionCreationPolicy.STATELESS) - ) // 세션을 사용하지 않으므로 STATELESS 설정 - .addFilterBefore(jwtAuthenticationFilter, UsernamePasswordAuthenticationFilter.class); // JwtAuthenticationFilter를 UsernamePasswordAuthenticationFilter 전에 추가 + ) + .addFilterBefore(jwtAuthenticationFilter, UsernamePasswordAuthenticationFilter.class); return http.build(); } @@ -41,9 +43,9 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { @Bean public CorsConfigurationSource corsConfigurationSource() { CorsConfiguration configuration = new CorsConfiguration(); - configuration.setAllowedOrigins(Arrays.asList("http://example.com")); // 허용할 도메인 설정 - configuration.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE")); // 허용할 HTTP 메서드 설정 - configuration.setAllowedHeaders(Arrays.asList("*")); // 허용할 헤더 설정 + configuration.setAllowedOrigins(Arrays.asList("http://localhost:3000")); // 허용할 도메인 설정 + configuration.setAllowedMethods(Arrays.asList("GET", "POST", "PATCH", "DELETE")); // 허용할 HTTP 메서드 설정 + configuration.setAllowedHeaders(Arrays.asList("Authorization", "Cache-Control", "Content-Type")); // 허용할 헤더 설정 configuration.setAllowCredentials(true); // 자격 증명 허용 설정 UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); source.registerCorsConfiguration("/**", configuration); diff --git a/src/main/java/com/example/likelion12/controller/CrewController.java b/src/main/java/com/example/likelion12/controller/CrewController.java index a892a48..a80b542 100644 --- a/src/main/java/com/example/likelion12/controller/CrewController.java +++ b/src/main/java/com/example/likelion12/controller/CrewController.java @@ -2,10 +2,6 @@ import com.example.likelion12.common.response.BaseResponse; import com.example.likelion12.dto.crew.*; -import com.example.likelion12.dto.crew.GetCrewDetailResponse; -import com.example.likelion12.dto.crew.GetCrewInquiryResponse; -import com.example.likelion12.dto.crew.PostCrewRequest; -import com.example.likelion12.dto.crew.PostCrewResponse; import com.example.likelion12.service.CrewService; import com.example.likelion12.util.*; import lombok.RequiredArgsConstructor; @@ -103,4 +99,14 @@ public BaseResponse cancelCrew(@RequestHeader("Authorization") String auth return new BaseResponse<>(null); } + /** + * 참여중인 크루 조회 + */ + @GetMapping("/join") + public BaseResponse> getJoinCrew(@RequestHeader("Authorization") String authorization) { + log.info("[CrewController.getJoinCrew]"); + Long memberId = jwtProvider.extractIdFromHeader(authorization); + List joinCrewResponses = crewService.getJoinCrew(memberId); + return new BaseResponse<>(joinCrewResponses); + } } diff --git a/src/main/java/com/example/likelion12/dto/crew/GetJoinCrewResponse.java b/src/main/java/com/example/likelion12/dto/crew/GetJoinCrewResponse.java new file mode 100644 index 0000000..90bb2dc --- /dev/null +++ b/src/main/java/com/example/likelion12/dto/crew/GetJoinCrewResponse.java @@ -0,0 +1,24 @@ +package com.example.likelion12.dto.crew; + +import com.example.likelion12.domain.MemberCrew; +import com.example.likelion12.domain.base.BaseLevel; +import com.example.likelion12.domain.base.BaseRole; +import com.example.likelion12.domain.base.BaseStatus; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.util.List; + +@Getter +@AllArgsConstructor +@NoArgsConstructor +public class GetJoinCrewResponse { + + private String crewName; + private String crewImg; + private String commentSimple; + private String exercise_name; + private String activty_area_name; + private BaseLevel level; +} diff --git a/src/main/java/com/example/likelion12/service/CrewService.java b/src/main/java/com/example/likelion12/service/CrewService.java index 490ce7a..0a98c98 100644 --- a/src/main/java/com/example/likelion12/service/CrewService.java +++ b/src/main/java/com/example/likelion12/service/CrewService.java @@ -1,9 +1,11 @@ package com.example.likelion12.service; import com.example.likelion12.common.exception.*; +import com.example.likelion12.common.response.BaseResponse; 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.crew.*; import com.example.likelion12.repository.*; @@ -270,8 +272,8 @@ else if (matchesCriteria && getCrewSearchFilterRequest.getTotalRecruitsMax() != return responseList; } - - /** + + /** * 크루 삭제하기 */ @Transactional @@ -317,21 +319,60 @@ public void cancelCrew(Long memberId, Long crewId) { // 크루를 탈퇴하고자 하는 member Member member = memberRepository.findByMemberIdAndStatus(memberId, BaseStatus.ACTIVE) - .orElseThrow(()-> new MemberException(CANNOT_FOUND_MEMBER)); + .orElseThrow(() -> new MemberException(CANNOT_FOUND_MEMBER)); //탈퇴하고자 하는 크루 Crew crew = crewRepository.findByCrewIdAndStatus(crewId, BaseStatus.ACTIVE) - .orElseThrow(()->new CrewException(CANNOT_FOUND_CREW)); + .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, crewId, BaseStatus.ACTIVE) + .orElseThrow(() -> new MemberCrewException(NOT_CREW_MEMBERCREW)); + + //CAPTAIN일 경우 예외처리 --> 크루삭제 + if (BaseRole.CAPTAIN.equals(memberCrew.getRole())){ + throw new MemberCrewException(CANNOT_CREW_CANCEL); + } + //크루 탈퇴 + else { + //멤버크루 삭제 + memberCrew.DeleteMemberCrewInfo(BaseStatus.DELETE); + memberCrewRepository.save(memberCrew); + } + + } + + /** + * 참여중인 크루 조회하기 + */ + @Transactional + public List getJoinCrew(Long memberId) { + log.info("[CrewService.getJoinCrew]"); + + // 멤버Id로 멤버찾고 + Member member = memberRepository.findByMemberIdAndStatus(memberId, BaseStatus.ACTIVE) + .orElseThrow(()-> new MemberException(CANNOT_FOUND_MEMBER)); + + // 멤버가 가지고 있는 멤버크루를 리스트로 가져오고 + List memberCrewList = member.getMemberCrewList(); + + // 그 멤버크루로 속해있는 크루들을 가져와서 필요한 정보만 dto에 담고 + List joinCrewResponses = memberCrewList.stream() + .map(memberCrew -> { + Crew crew = memberCrew.getCrew(); + return new GetJoinCrewResponse( + crew.getCrewName(), + crew.getCrewImg(), + crew.getCommentSimple(), + crew.getActivityRegion().getActivityRegionName(), + crew.getExercise().getExerciseName(), + crew.getLevel() + ); + }) + .collect(Collectors.toList()); - //CAPTAIN일 경우 크루 삭제 - if(memberCrewService.ConfirmCaptainMemberCrew(memberCrew)) - deleteCrew(memberId,crewId); - else //크루 탈퇴 - memberCrewRepository.delete(memberCrew); + // 반환하기 + return joinCrewResponses; } } diff --git a/src/main/java/com/example/likelion12/service/MemberCrewService.java b/src/main/java/com/example/likelion12/service/MemberCrewService.java index 3c7c31d..41ed6cc 100644 --- a/src/main/java/com/example/likelion12/service/MemberCrewService.java +++ b/src/main/java/com/example/likelion12/service/MemberCrewService.java @@ -45,12 +45,11 @@ public void createMemberCrew(Member member, Crew crew){ /** * 크루 수정,삭제 시 접근하는 member가 CAPTAIN 인지 확인 */ - public boolean ConfirmCaptainMemberCrew(MemberCrew memberCrew) { + public void ConfirmCaptainMemberCrew(MemberCrew memberCrew) { log.info("[MemberCrewService.ConfirmCaptainMemberCrew]"); if (!BaseRole.CAPTAIN.equals(memberCrew.getRole())) { throw new MemberCrewException(NOT_MEMBERCREW_CAPTAIN); } - return true; } } diff --git a/src/main/java/com/example/likelion12/service/SocialringService.java b/src/main/java/com/example/likelion12/service/SocialringService.java index a7ce534..0c226e3 100644 --- a/src/main/java/com/example/likelion12/service/SocialringService.java +++ b/src/main/java/com/example/likelion12/service/SocialringService.java @@ -405,7 +405,6 @@ else if (matchesCriteria && getSocialringSearchFilterRequest.getTotalRecruitsMax matchesCriteria = false; } } - // 현재 참여중인 소셜링원 수 확인하기 int currentSocialrings = memberSocialringRepository.findBySocialring_SocialringIdAndStatus(socialring.getSocialringId(),BaseStatus.ACTIVE) .orElseThrow(()-> new MemberSocialringException(CANNOT_FOUND_MEMBERSOCIALRING_LIST)).size();