-
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 #51 from Project-Catcher/feat-hs-schedules-list
schedules/list 구현 (일부 조건 미구현)
- Loading branch information
Showing
12 changed files
with
307 additions
and
11 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
5 changes: 5 additions & 0 deletions
5
src/main/java/com/catcher/core/domain/entity/enums/SearchOption.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,5 @@ | ||
package com.catcher.core.domain.entity.enums; | ||
|
||
public enum SearchOption { | ||
ALL, TITLE, WRITER, DESCRIPTION, TAG, TITLEANDDESCRIPTION | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/com/catcher/core/dto/request/ScheduleListRequest.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,21 @@ | ||
package com.catcher.core.dto.request; | ||
|
||
import com.catcher.core.domain.entity.enums.SearchOption; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Getter | ||
@Setter | ||
public class ScheduleListRequest { | ||
private Long participantFrom; | ||
private Long participantTo; | ||
private Long budgetFrom; | ||
private Long budgetTo; | ||
private String keyword; | ||
private SearchOption keywordOption; | ||
private String categoryName; | ||
private LocalDateTime startAt; | ||
private LocalDateTime endAt; | ||
} |
53 changes: 53 additions & 0 deletions
53
src/main/java/com/catcher/core/dto/response/ScheduleListResponse.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,53 @@ | ||
package com.catcher.core.dto.response; | ||
|
||
import com.catcher.core.domain.entity.Location; | ||
import com.catcher.core.domain.entity.Schedule; | ||
import lombok.Getter; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
|
||
@Getter | ||
public class ScheduleListResponse { | ||
private final List<ScheduleDTO> schedules; | ||
|
||
public ScheduleListResponse(List<ScheduleDTO> schedules) { | ||
this.schedules = schedules; | ||
} | ||
|
||
@Getter | ||
public static class ScheduleDTO { | ||
private final Long id; | ||
private final Long participantLimit; | ||
private final String title; | ||
private final String description; | ||
private final String thumbnailUrl; | ||
private final Long viewCount; | ||
private final Long budget; | ||
//private final int participantCount; | ||
private final Location location; | ||
private final LocalDateTime startAt; | ||
private final LocalDateTime endAt; | ||
private final LocalDateTime participantStartAt; | ||
private final LocalDateTime participantEndAt; | ||
//private final List<Tag> scheduleTags; | ||
|
||
public ScheduleDTO(Schedule schedule) { | ||
this.id = schedule.getId(); | ||
this.participantLimit = schedule.getParticipantLimit(); | ||
this.title = schedule.getTitle(); | ||
this.description = schedule.getDescription(); | ||
this.thumbnailUrl = schedule.getThumbnailUrl(); | ||
this.viewCount = schedule.getViewCount(); | ||
this.budget = schedule.getBudget(); | ||
//this.participantCount = schedule.getScheduleParticipants().size(); | ||
this.location = schedule.getLocation(); | ||
this.startAt = schedule.getStartAt(); | ||
this.endAt = schedule.getEndAt(); | ||
this.participantStartAt = schedule.getParticipateStartAt(); | ||
this.participantEndAt = schedule.getParticipateEndAt(); | ||
//this.scheduleTags = schedule.getScheduleTags().stream().map(ScheduleTag::getTag).collect(Collectors.toList()); | ||
|
||
} | ||
} | ||
} |
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
122 changes: 122 additions & 0 deletions
122
src/main/java/com/catcher/core/specification/ScheduleSpecification.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,122 @@ | ||
package com.catcher.core.specification; | ||
|
||
import com.catcher.core.domain.entity.*; | ||
import com.catcher.core.domain.entity.enums.ScheduleStatus; | ||
import jakarta.persistence.criteria.*; | ||
import org.springframework.data.jpa.domain.Specification; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
public class ScheduleSpecification { | ||
|
||
public static Specification<Schedule> likeTitle(String title) { | ||
/* | ||
select s from Schedule s | ||
where s.title like '%' || :title || '%' | ||
*/ | ||
return (root, query, criteriaBuilder) | ||
-> criteriaBuilder.like(root.get("title"), "%" + title + "%"); | ||
} | ||
|
||
public static Specification<Schedule> likeDescription (String description) { | ||
/* | ||
select s from Schedule s | ||
where s.description like '%' || :description || '%' | ||
*/ | ||
return (root, query, criteriaBuilder) | ||
-> criteriaBuilder.like(root.get("description"), "%" + description + "%"); | ||
} | ||
|
||
public static Specification<Schedule> fromBudget(Long budget) { | ||
/* | ||
select s from Schedule s | ||
where s.budget >= :budget | ||
*/ | ||
return (root, query, criteriaBuilder) | ||
-> criteriaBuilder.greaterThanOrEqualTo(root.get("budget"), budget); | ||
} | ||
|
||
public static Specification<Schedule> toBudget(Long budget) { | ||
/* | ||
select s from Schedule s | ||
where s.budget <= :budget | ||
*/ | ||
return (root, query, criteriaBuilder) | ||
-> criteriaBuilder.lessThanOrEqualTo(root.get("budget"), budget); | ||
} | ||
|
||
public static Specification<Schedule> fromStartAt(LocalDateTime startAt) { | ||
/* | ||
select s from Schedule s | ||
where s.startAt >= :startAt | ||
*/ | ||
return (root, query, criteriaBuilder) | ||
-> criteriaBuilder.greaterThanOrEqualTo(root.get("startAt"), startAt); | ||
} | ||
|
||
public static Specification<Schedule> toEndAt(LocalDateTime endAt) { | ||
/* | ||
select s from Schedule s | ||
where s.endAt <= :endAt | ||
*/ | ||
return (root, query, criteriaBuilder) | ||
-> criteriaBuilder.lessThanOrEqualTo(root.get("endAt"), endAt); | ||
} | ||
|
||
public static Specification<Schedule> fromParticipant(Long participantFrom) { | ||
/* | ||
select s from Schedule s | ||
where s.participantLimit >= :participantFrom | ||
*/ | ||
return (root, query, criteriaBuilder) | ||
-> criteriaBuilder.greaterThanOrEqualTo(root.get("participantLimit"), participantFrom); | ||
} | ||
|
||
public static Specification<Schedule> toParticipant(Long participantTo) { | ||
/* | ||
select s from Schedule s | ||
where s.participantLimit <= :participantTo | ||
*/ | ||
return (root, query, criteriaBuilder) | ||
-> criteriaBuilder.lessThanOrEqualTo(root.get("participantLimit"), participantTo); | ||
} | ||
|
||
public static Specification<Schedule> likeByUsername(String username) { | ||
/* | ||
select s from Schedule s | ||
left join User u s.u | ||
where u.username like '%' || :username || '%' | ||
*/ | ||
return (root, query, criteriaBuilder) -> { | ||
Join<Schedule, User> join = root.join("user", JoinType.LEFT); | ||
|
||
return criteriaBuilder.like(join.get("username"), "%" + username + "%"); | ||
}; | ||
} | ||
|
||
public static Specification<Schedule> scheduleStatus(ScheduleStatus scheduleStatus) { | ||
/* | ||
select s from Schedule s | ||
where s.scheduleStatus = :scheduleStatus | ||
*/ | ||
return (root, query, criteriaBuilder) -> criteriaBuilder.equal(root.get("scheduleStatus"), scheduleStatus); | ||
} | ||
|
||
public static Specification<Schedule> inTagName(String tagName) { | ||
/* | ||
select s from Schedule s | ||
where | ||
s.id in (select st.schedule.id from ScheduleTag st where st.tag.name = :tagName) | ||
*/ | ||
return (root, query, criteriaBuilder) -> { | ||
|
||
Subquery<Long> subquery = query.subquery(Long.class); | ||
Root<ScheduleTag> subRoot = subquery.from(ScheduleTag.class); | ||
|
||
subquery.select(subRoot.get("schedule").get("id")) | ||
.where(criteriaBuilder.equal(subRoot.get("tag").get("name"), tagName)); | ||
|
||
return criteriaBuilder.in(root.get("id")).value(subquery); | ||
}; | ||
} | ||
} |
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
Oops, something went wrong.