Skip to content

Commit

Permalink
Merge pull request #58 from Likelion12/9-be-소셜링-검색결과-필터링-구현
Browse files Browse the repository at this point in the history
Feat : 소셜링 검색결과 필터링 구현
  • Loading branch information
SonMyeongJin authored Aug 5, 2024
2 parents 69c9d35 + 8a4e64b commit 3780325
Show file tree
Hide file tree
Showing 8 changed files with 227 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.example.likelion12.common.response.BaseResponse;
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;
Expand All @@ -10,6 +11,8 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequiredArgsConstructor
Expand All @@ -29,6 +32,17 @@ public BaseResponse<PostCrewResponse> createCrew(@RequestHeader("Authorization")
Long memberId = jwtProvider.extractIdFromHeader(authorization);
return new BaseResponse<>(crewService.createCrew(memberId, postCrewRequest));
}
/**
* 크루 조회
*/
@GetMapping("/inquiry")
public BaseResponse<List<GetCrewInquiryResponse>> getCrewInquiries(@RequestHeader("Authorization") String authorization,
@RequestParam List<Long> crewId){
log.info("[CrewController.getCrewInquiries]");
Long memberId = jwtProvider.extractIdFromHeader(authorization);
return new BaseResponse<>(crewService.getCrewInquiries(memberId, crewId));
}


/**
* 크루 상세 조회
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.example.likelion12.common.response.BaseResponse;
import com.example.likelion12.common.response.status.BaseExceptionResponseStatus;
import com.example.likelion12.dto.crew.GetCrewInquiryResponse;
import com.example.likelion12.dto.socialring.*;
import com.example.likelion12.service.SocialringService;
import com.example.likelion12.util.*;
Expand Down Expand Up @@ -66,6 +67,17 @@ public BaseResponse<Void> joinSocialring(@RequestHeader("Authorization") String
return new BaseResponse<>(BaseExceptionResponseStatus.SUCCESS, null);
}

/**
* 소셜링 검색결과 필터링
*/
@GetMapping("/search/filter")
public BaseResponse<List<GetSocialringSearchFilterResponse>> searchFilterSocialring(@RequestHeader("Authorization") String authorization,
@RequestBody GetSocialringSearchFilterRequest getSocialringSearchFilterRequest){
log.info("[SocialringController.searchFilterSocialring]");
Long memberId = jwtProvider.extractIdFromHeader(authorization);
return new BaseResponse<>(socialringService.searchFilterSocialring(memberId, getSocialringSearchFilterRequest));
}

/**
* 참가 예정인 소셜링
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.example.likelion12.dto.crew;

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

@Getter
@AllArgsConstructor
public class GetCrewInquiryResponse {
/**
* 크루 조회 response dto
*/
private String crewName;
private String crewImg;
private String activityRegionName;
private String exerciseName;
private BaseLevel level;
private String commentSimple;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.example.likelion12.dto.socialring;

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


@Getter
@AllArgsConstructor
public class GetSocialringSearchFilterRequest {

/**
* 소셜링 검색결과 필터링 request dto
*/

private String exerciseName;
private BaseGender gender;
private BaseLevel level;
private Integer socialringCostMin;
private Integer socialringCostMax;
private Integer totalRecruitsMin;
private Integer totalRecruitsMax;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.example.likelion12.dto.socialring;

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
public class GetSocialringSearchFilterResponse {

/**
* 소셜링 검색결과필터링 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 @@ -23,4 +23,5 @@ public interface SocialringRepository extends JpaRepository<Socialring, Long> {
@Query("SELECT c FROM Socialring c WHERE c.activityRegion.id = :activityRegionId AND c.status = :status ORDER BY c.socialringId ASC")
List<Socialring> findTop3ByActivityRegionIdAndStatus(@Param("activityRegionId") Long activityRegionId, @Param("status") BaseStatus status, Pageable pageable);

List<Socialring> findAllByStatus(BaseStatus baseStatus);
}
32 changes: 32 additions & 0 deletions src/main/java/com/example/likelion12/service/CrewService.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.example.likelion12.domain.base.BaseLevel;
import com.example.likelion12.domain.base.BaseStatus;
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.repository.*;
Expand All @@ -15,6 +16,8 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -73,6 +76,35 @@ public PostCrewResponse createCrew(Long memberId, PostCrewRequest postCrewReques
return new PostCrewResponse(crew.getCrewId());
}

/**
* 크루 조회
*/
public List<GetCrewInquiryResponse> getCrewInquiries(Long memberId, List<Long> crewIds) {
log.info("[CrewService.getCrewInquiries]");

List<GetCrewInquiryResponse> getCrewInquiryResponses = new ArrayList<>();

for (Long crewId : crewIds) {

//조회하고자 하는 크루
Crew crew = crewRepository.findByCrewIdAndStatus(crewId, BaseStatus.ACTIVE)
.orElseThrow(() -> new CrewException(CANNOT_FOUND_CREW));

GetCrewInquiryResponse response = new GetCrewInquiryResponse(
crew.getCrewName(),
crew.getCrewImg(),
crew.getActivityRegion().getActivityRegionName(),
crew.getExercise().getExerciseName(),
crew.getLevel(),
crew.getCommentSimple()
);

getCrewInquiryResponses.add(response);
}

return getCrewInquiryResponses;
}

/**
* 크루 상세 조회
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,102 @@ public List<GetSocialringJoinStatusResponse> joinCompleteSocialring(Long memberI
return responseList;
}
/**
* 소셜링 검색결과 필터링
*/
@Transactional
public List<GetSocialringSearchFilterResponse> searchFilterSocialring
(Long memberId, GetSocialringSearchFilterRequest getSocialringSearchFilterRequest) {
log.info("[SocialringService.searchFilterSocialring]");

// 전체 소셜링 목록 조회
List<Socialring> allSocialrings = socialringRepository.findAllByStatus(BaseStatus.ACTIVE);
List<GetSocialringSearchFilterResponse> responseList = new ArrayList<>();


// 요청값의 범위 확인 후 필터링
for (Socialring socialring : allSocialrings) {
boolean matchesCriteria = true;

if (getSocialringSearchFilterRequest.getExerciseName() != null) {
if (!socialring.getExercise().getExerciseName().equals(getSocialringSearchFilterRequest.getExerciseName())) {
matchesCriteria = false;
}
}
if (matchesCriteria && getSocialringSearchFilterRequest.getGender() != null) {
if (!socialring.getGender().equals(getSocialringSearchFilterRequest.getGender())) {
matchesCriteria = false;
}
}
if (matchesCriteria && getSocialringSearchFilterRequest.getLevel() != null) {
if (!socialring.getLevel().equals(getSocialringSearchFilterRequest.getLevel())) {
matchesCriteria = false;
}
}

// 최소, 최대 범위가 둘 다 들어왔을 때
if (matchesCriteria && getSocialringSearchFilterRequest.getSocialringCostMin() != null && getSocialringSearchFilterRequest.getSocialringCostMax() != null) {
if (!(socialring.getSocialringCost() >= getSocialringSearchFilterRequest.getSocialringCostMin()
&& socialring.getSocialringCost() <= getSocialringSearchFilterRequest.getSocialringCostMax())) {
matchesCriteria = false;
}
}
// 최소 범위만 들어왔을 때
else if (matchesCriteria && getSocialringSearchFilterRequest.getSocialringCostMin() != null) {
if (socialring.getSocialringCost() < getSocialringSearchFilterRequest.getSocialringCostMin()) {
matchesCriteria = false;
}
}
// 최대 범위만 들어왔을 때
else if (matchesCriteria && getSocialringSearchFilterRequest.getSocialringCostMax() != null) {
if (socialring.getSocialringCost() > getSocialringSearchFilterRequest.getSocialringCostMax()) {
matchesCriteria = false;
}
}

// 최소, 최대 모집 인원 범위가 둘 다 들어왔을 때
if (matchesCriteria && getSocialringSearchFilterRequest.getTotalRecruitsMin() != null && getSocialringSearchFilterRequest.getTotalRecruitsMax() != null) {
if (!(socialring.getTotalRecruits() >= getSocialringSearchFilterRequest.getTotalRecruitsMin()
&& socialring.getTotalRecruits() <= getSocialringSearchFilterRequest.getTotalRecruitsMax())) {
matchesCriteria = false;
}
}
// 최소 모집 인원만 들어왔을 때
else if (matchesCriteria && getSocialringSearchFilterRequest.getTotalRecruitsMin() != null) {
if (socialring.getTotalRecruits() < getSocialringSearchFilterRequest.getTotalRecruitsMin()) {
matchesCriteria = false;
}
}
// 최대 모집 인원만 들어왔을 때
else if (matchesCriteria && getSocialringSearchFilterRequest.getTotalRecruitsMax() != null) {
if (socialring.getTotalRecruits() > getSocialringSearchFilterRequest.getTotalRecruitsMax()) {
matchesCriteria = false;
}
}

// 현재 참여중인 소셜링원 수 확인하기
int currentSocialrings = memberSocialringRepository.findBySocialring_SocialringIdAndStatus(socialring.getSocialringId(),BaseStatus.ACTIVE)
.orElseThrow(()-> new MemberSocialringException(CANNOT_FOUND_MEMBERSOCIALRING_LIST)).size();

// 조건에 맞으면 응답 리스트에 추가
if (matchesCriteria) {
GetSocialringSearchFilterResponse response =
new GetSocialringSearchFilterResponse(socialring.getSocialringId(),
socialring.getSocialringName(),socialring.getSocialringImg(),
socialring.getActivityRegion().getActivityRegionName(),socialring.getSocialringDate(),
socialring.getSocialringCost(),socialring.getCommentSimple(),currentSocialrings,socialring.getTotalRecruits());
responseList.add(response);
}
}

// 해당하는 소셜링 리스트가 하나도 없을 때 예외 처리
if (responseList.isEmpty()) {
throw new SocialringException(CANNOT_FOUND_SOCIALRING);
}

return responseList;
}

/**
* 소셜링 삭제하기
*/
@Transactional
Expand Down

0 comments on commit 3780325

Please sign in to comment.