Skip to content

Commit

Permalink
Merge branch 'develop' into 61-be-크루-검색결과-필터링
Browse files Browse the repository at this point in the history
  • Loading branch information
jsilver01 authored Aug 5, 2024
2 parents b11c161 + 00e3397 commit 95ec3ac
Show file tree
Hide file tree
Showing 13 changed files with 340 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ public enum BaseExceptionResponseStatus implements ResponseStatus{
NOT_MEMBERSOCIALRING_CAPTAIN(8001, HttpStatus.BAD_REQUEST.value(), "소셜링 수정,삭제에 접근할수없는 권한입니다."),
CANNOT_FOUND_MEMBERSOCIALRING_LIST(8002, HttpStatus.BAD_REQUEST.value(), "해당하는 멤버소셜링 리스트를 찾을 수 없습니다."),
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(8006, HttpStatus.BAD_REQUEST.value(), "참가 완료한 소셜링이 존재 하지않습니다."),
CANNOT_CANCEL_BY_CAPTAIN(8007, HttpStatus.BAD_REQUEST.value(), "소셜링 모임장은 소셜링을 나갈 수 없습니다. 소셜링 삭제를 이용해주세요"),

/**
* 9000 : crew 관련
Expand All @@ -64,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
28 changes: 24 additions & 4 deletions src/main/java/com/example/likelion12/config/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@
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;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.CorsConfigurationSource;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;

import java.util.Arrays;

@Configuration
@RequiredArgsConstructor
Expand All @@ -19,16 +25,30 @@ public class SecurityConfig {
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http
.csrf(CsrfConfigurer<HttpSecurity>::disable)
.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://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);
return source;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,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
Expand Up @@ -79,6 +79,26 @@ public BaseResponse<List<GetSocialringSearchFilterResponse>> searchFilterSocialr
}

/**
* 참가 예정인 소셜링
*/
@GetMapping("/join/before")
public BaseResponse<List<GetSocialringJoinStatusResponse>> joinBeforeSocialring(@RequestHeader("Authorization") String authorization){
log.info("[SocialringController.joinBeforeSocialring]");
Long memberId = jwtProvider.extractIdFromHeader(authorization);
return new BaseResponse<>(socialringService.joinBeforeSocialring(memberId));
}

/**
* 참가 완료한 소셜링
*/
@GetMapping("/join/complete")
public BaseResponse<List<GetSocialringJoinStatusResponse>> joinCompleteSocialring(@RequestHeader("Authorization") String authorization){
log.info("[SocialringController.joinCompleteSocialring]");
Long memberId = jwtProvider.extractIdFromHeader(authorization);
return new BaseResponse<>(socialringService.joinCompleteSocialring(memberId));
}

/**
* 소셜링 삭제하기
*/
@PatchMapping("/delete")
Expand All @@ -89,4 +109,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
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.example.likelion12.dto.socialring;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.time.LocalDate;

@Getter
@AllArgsConstructor
public class GetSocialringJoinStatusResponse {

/**
* 소셜링 참여상태 response dto
*/
private Long socialringId;
private String socialringName;
private String socialringImg;
private String activityRegionName;
private LocalDate socialringDate;
private int socialringCost;
private String commentSimple;
private int currentRecruits;
private int totalRecruits;

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

import lombok.AllArgsConstructor;
import lombok.Getter;
import com.example.likelion12.domain.base.BaseGender;
import com.example.likelion12.domain.base.BaseLevel;
import com.example.likelion12.domain.base.BaseRole;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.time.LocalDate;

@Getter
@AllArgsConstructor
Expand All @@ -10,6 +17,14 @@ public class GetSocialringSearchFilterResponse {
/**
* 소셜링 검색결과필터링 response dto
*/
private long socialringId;
private Long socialringId;
private String socialringName;
private String socialringImg;
private String activityRegionName;
private LocalDate socialringDate;
private int socialringCost;
private String commentSimple;
private int currentRecruits;
private int totalRecruits;

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public interface MemberSocialringRepository extends JpaRepository<MemberSocialri
Optional<MemberSocialring> findByMember_MemberIdAndSocialring_SocialringIdAndStatus(Long memberId, Long socialringId, BaseStatus status);
Optional<List<MemberSocialring>> findBySocialring_SocialringIdAndStatus(Long socialringId, BaseStatus baseStatus);
boolean existsByMember_MemberIdAndSocialring_SocialringIdAndStatus(Long memberId, Long socialringId, BaseStatus status);
Optional<List<MemberSocialring>> findByMember_MemberIdAndAndStatus(Long memberId, BaseStatus baseStatus);
}


58 changes: 49 additions & 9 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 @@ -313,22 +315,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);
}

}

//CAPTAIN일 경우 크루 삭제
if(memberCrewService.ConfirmCaptainMemberCrew(memberCrew))
deleteCrew(memberId,crewId);
else //크루 탈퇴
memberCrewRepository.delete(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());

// 반환하기
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;
}
}
Loading

0 comments on commit 95ec3ac

Please sign in to comment.