Skip to content

Commit

Permalink
Merge branch 'develop' into 19-be-크루-조회
Browse files Browse the repository at this point in the history
  • Loading branch information
jsilver01 authored Aug 5, 2024
2 parents 91aacad + 6a99452 commit b3fc56e
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 관련
Expand Down
18 changes: 10 additions & 8 deletions src/main/java/com/example/likelion12/config/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -24,26 +25,27 @@ public class SecurityConfig {
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http
.csrf(CsrfConfigurer<HttpSecurity>::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();
}

@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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -103,4 +99,14 @@ public BaseResponse<Void> cancelCrew(@RequestHeader("Authorization") String auth
return new BaseResponse<>(null);
}

/**
* 참여중인 크루 조회
*/
@GetMapping("/join")
public BaseResponse<List<GetJoinCrewResponse>> getJoinCrew(@RequestHeader("Authorization") String authorization) {
log.info("[CrewController.getJoinCrew]");
Long memberId = jwtProvider.extractIdFromHeader(authorization);
List<GetJoinCrewResponse> joinCrewResponses = crewService.getJoinCrew(memberId);
return new BaseResponse<>(joinCrewResponses);
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
63 changes: 52 additions & 11 deletions src/main/java/com/example/likelion12/service/CrewService.java
Original file line number Diff line number Diff line change
@@ -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.*;
Expand Down Expand Up @@ -270,8 +272,8 @@ else if (matchesCriteria && getCrewSearchFilterRequest.getTotalRecruitsMax() !=
return responseList;

}

/**
/**
* 크루 삭제하기
*/
@Transactional
Expand Down Expand Up @@ -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<GetJoinCrewResponse> getJoinCrew(Long memberId) {
log.info("[CrewService.getJoinCrew]");

// 멤버Id로 멤버찾고
Member member = memberRepository.findByMemberIdAndStatus(memberId, BaseStatus.ACTIVE)
.orElseThrow(()-> new MemberException(CANNOT_FOUND_MEMBER));

// 멤버가 가지고 있는 멤버크루를 리스트로 가져오고
List<MemberCrew> memberCrewList = member.getMemberCrewList();

// 그 멤버크루로 속해있는 크루들을 가져와서 필요한 정보만 dto에 담고
List<GetJoinCrewResponse> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit b3fc56e

Please sign in to comment.