-
Notifications
You must be signed in to change notification settings - Fork 0
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 #87 from Lets-JUPJUP/feature/post-v2
feat : 플로깅 게시글 필터링 구현
- Loading branch information
Showing
8 changed files
with
201 additions
and
13 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
52 changes: 47 additions & 5 deletions
52
src/main/java/efub/back/jupjup/domain/post/domain/District.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 |
---|---|---|
@@ -1,12 +1,54 @@ | ||
package efub.back.jupjup.domain.post.domain; | ||
|
||
import lombok.AllArgsConstructor; | ||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public enum District { | ||
강남구, 강동구, 강북구, 강서구, 관악구, 광진구, 구로구, 금천구, 노원구, 도봉구, | ||
동대문구, 동작구, 마포구, 서대문구, 서초구, 성동구, 성북구, 송파구, 양천구, 영등포구, | ||
용산구, 은평구, 종로구, 중구, 중랑구 | ||
GANGNAM("강남구"), | ||
GANGDONG("강동구"), | ||
GANGBUK("강북구"), | ||
GANGSEO("강서구"), | ||
GWANAK("관악구"), | ||
GWANGJIN("광진구"), | ||
GURO("구로구"), | ||
GEUMCHEON("금천구"), | ||
NOWON("노원구"), | ||
DOBONG("도봉구"), | ||
DONGDAEMUN("동대문구"), | ||
DONGJAK("동작구"), | ||
MAPO("마포구"), | ||
SEODAEMUN("서대문구"), | ||
SEOCHO("서초구"), | ||
SEONGDONG("성동구"), | ||
SEONGBUK("성북구"), | ||
SONGPA("송파구"), | ||
YANGCHEON("양천구"), | ||
YEONGDEUNGPO("영등포구"), | ||
YONGSAN("용산구"), | ||
EUNPYEONG("은평구"), | ||
JONGNO("종로구"), | ||
JUNG("중구"), | ||
JUNGNANG("중랑구"); | ||
|
||
private final String koreanName; | ||
|
||
District(String koreanName) { | ||
this.koreanName = koreanName; | ||
} | ||
|
||
@JsonCreator | ||
public static District from(String value) { | ||
for (District district : District.values()) { | ||
if (district.getKoreanName().equals(value) || district.name().equalsIgnoreCase(value)) { | ||
return district; | ||
} | ||
} | ||
throw new IllegalArgumentException("Invalid district: " + value); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return this.koreanName; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/efub/back/jupjup/domain/post/dto/PostFilterDto.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,22 @@ | ||
package efub.back.jupjup.domain.post.dto; | ||
|
||
import java.util.List; | ||
|
||
import efub.back.jupjup.domain.member.domain.Gender; | ||
import efub.back.jupjup.domain.post.domain.District; | ||
import efub.back.jupjup.domain.post.domain.PostGender; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
public class PostFilterDto { | ||
private PostGender postGender; | ||
private Boolean withPet; | ||
private List<District> districts; | ||
private Boolean allAge; // '연령무관' 옵션 | ||
private Boolean allGender; // '성별무관' 옵션 | ||
private Boolean excludeClosedRecruitment; | ||
private Gender userGender; | ||
private Integer userAge; | ||
} |
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
73 changes: 73 additions & 0 deletions
73
src/main/java/efub/back/jupjup/domain/post/specification/PostSpecification.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,73 @@ | ||
package efub.back.jupjup.domain.post.specification; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
|
||
import org.springframework.data.jpa.domain.Specification; | ||
|
||
import efub.back.jupjup.domain.member.domain.Gender; | ||
import efub.back.jupjup.domain.post.domain.District; | ||
import efub.back.jupjup.domain.post.domain.Post; | ||
import efub.back.jupjup.domain.post.domain.PostGender; | ||
|
||
public class PostSpecification { | ||
|
||
public static Specification<Post> withGender(Boolean allGender, Gender userGender) { | ||
return (root, query, criteriaBuilder) -> { | ||
if (Boolean.TRUE.equals(allGender)) { | ||
return null; // 모든 성별 포함 | ||
} | ||
// allGender가 false인 경우, 사용자 성별과 ANY만 포함 | ||
return criteriaBuilder.or( | ||
criteriaBuilder.equal(root.get("postGender"), PostGender.ANY), | ||
criteriaBuilder.equal(root.get("postGender"), convertGenderToPostGender(userGender)) | ||
); | ||
}; | ||
} | ||
|
||
private static PostGender convertGenderToPostGender(Gender gender) { | ||
switch (gender) { | ||
case FEMALE: | ||
return PostGender.FEMALE; | ||
case MALE: | ||
return PostGender.MALE; | ||
default: | ||
return PostGender.ANY; | ||
} | ||
} | ||
|
||
public static Specification<Post> withPet(Boolean withPet) { | ||
return (root, query, criteriaBuilder) -> | ||
withPet == null ? null : criteriaBuilder.equal(root.get("withPet"), withPet); | ||
} | ||
|
||
public static Specification<Post> withDistricts(List<District> districts) { | ||
return (root, query, criteriaBuilder) -> { | ||
if (districts == null || districts.isEmpty()) { | ||
return null; | ||
} | ||
return root.get("district").in(districts); | ||
}; | ||
} | ||
|
||
public static Specification<Post> withAgeRange(Boolean allAge, Integer userAge) { | ||
return (root, query, criteriaBuilder) -> { | ||
if (Boolean.TRUE.equals(allAge)) { | ||
return null; // 모든 연령 포함 | ||
} | ||
if (userAge != null) { | ||
return criteriaBuilder.and( | ||
criteriaBuilder.lessThanOrEqualTo(root.get("minAge"), userAge), | ||
criteriaBuilder.greaterThanOrEqualTo(root.get("maxAge"), userAge) | ||
); | ||
} | ||
return null; | ||
}; | ||
} | ||
|
||
public static Specification<Post> excludeClosedRecruitment(Boolean exclude) { | ||
return (root, query, criteriaBuilder) -> | ||
exclude == null || !exclude ? null : | ||
criteriaBuilder.greaterThan(root.get("dueDate"), LocalDateTime.now()); | ||
} | ||
} |