-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #84 from TravelCompass-UMC/refactor/74
Refactor : 여행 계획 검색 기능 추가 및 스웨거 추가
- Loading branch information
Showing
8 changed files
with
110 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/main/java/com/travelcompass/api/plan/domain/PlanSpecification.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.travelcompass.api.plan.domain; | ||
|
||
import com.travelcompass.api.global.api_payload.ErrorCode; | ||
import com.travelcompass.api.global.exception.GeneralException; | ||
import com.travelcompass.api.hashtag.domain.HashtagPlan; | ||
import jakarta.persistence.criteria.Join; | ||
import jakarta.persistence.criteria.Predicate; | ||
import org.springframework.data.jpa.domain.Specification; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class PlanSpecification { | ||
|
||
public static Specification<Plan> filteredByParameters(Integer days, Long regionId, String vehicle, List<String> hashtags){ | ||
return (root, query, criteriaBuilder) -> { | ||
List<Predicate> predicates = new ArrayList<>(); | ||
|
||
if (days != null && days >= 0) { | ||
predicates.add(criteriaBuilder.equal(root.get("days"), days)); | ||
} else if (days != null && days < 0) { | ||
predicates.add(criteriaBuilder.greaterThanOrEqualTo(root.get("days"), 2)); | ||
} | ||
if (regionId != null) { | ||
predicates.add(criteriaBuilder.equal(root.get("region").get("id"), regionId)); | ||
} | ||
if (vehicle != null) { | ||
try { | ||
PlanVehicle planVehicle = PlanVehicle.valueOf(vehicle); | ||
predicates.add(criteriaBuilder.equal(root.get("vehicle"), planVehicle)); | ||
} catch (IllegalArgumentException e) { | ||
throw GeneralException.of(ErrorCode.WRONG_VEHICLE_PARAM); | ||
} | ||
} | ||
if (hashtags != null && !hashtags.isEmpty()) { | ||
Join<Plan, HashtagPlan> hashtagJoin = root.join("hashtagPlans"); | ||
predicates.add(hashtagJoin.get("hashtag").get("name").in(hashtags)); | ||
} | ||
|
||
return criteriaBuilder.and(predicates.toArray(new Predicate[0])); | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters