-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[스테디] 스테디 인기 모집글 조회 API 개발 #197
Changes from all commits
2e76411
166497f
1c54f7a
2962984
87afebf
73cdb89
778feb4
9e7f890
8c74715
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package dev.steady.steady.dto; | ||
|
||
import java.time.LocalDate; | ||
|
||
public record RankCondition( | ||
LocalDate date, | ||
int limit, | ||
RankType type | ||
) { | ||
|
||
public static RankCondition of(LocalDate date, int limit, String type) { | ||
return new RankCondition(date, limit, RankType.from(type)); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package dev.steady.steady.dto; | ||
|
||
public enum RankType { | ||
|
||
ALL, | ||
STUDY, | ||
PROJECT; | ||
|
||
public static RankType from(String type) { | ||
return valueOf(type.toUpperCase()); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package dev.steady.steady.dto.request; | ||
|
||
import dev.steady.steady.dto.RankCondition; | ||
import jakarta.validation.constraints.Max; | ||
import org.springframework.format.annotation.DateTimeFormat; | ||
|
||
import java.time.LocalDate; | ||
|
||
public record RankParams( | ||
@DateTimeFormat(pattern = "yyyy-MM-dd") | ||
LocalDate date, | ||
@Max(value = 10, message = "인기글은 최대 10개까지 조회가 가능합니다.") | ||
int limit, | ||
String type | ||
) { | ||
|
||
public RankCondition toCondition() { | ||
return RankCondition.of(date, limit, type); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package dev.steady.steady.dto.response; | ||
|
||
import dev.steady.steady.domain.Steady; | ||
import dev.steady.steady.domain.SteadyStatus; | ||
import dev.steady.steady.domain.SteadyType; | ||
|
||
import java.time.LocalDate; | ||
|
||
public record SteadyRankResponse( | ||
Long steadyId, | ||
String title, | ||
SteadyType type, | ||
SteadyStatus status, | ||
LocalDate deadline, | ||
int viewCount, | ||
int likeCount | ||
) { | ||
|
||
public static SteadyRankResponse from(Steady steady) { | ||
return new SteadyRankResponse( | ||
steady.getId(), | ||
steady.getTitle(), | ||
steady.getType(), | ||
steady.getStatus(), | ||
steady.getDeadline(), | ||
steady.getViewCount(), | ||
steady.getLikeCount() | ||
); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,10 @@ | |
import dev.steady.steady.domain.Participant; | ||
import dev.steady.steady.domain.Steady; | ||
import dev.steady.steady.domain.SteadyStatus; | ||
import dev.steady.steady.domain.SteadyType; | ||
import dev.steady.steady.dto.FilterConditionDto; | ||
import dev.steady.steady.dto.RankCondition; | ||
import dev.steady.steady.dto.RankType; | ||
import dev.steady.steady.dto.response.MySteadyQueryResponse; | ||
import dev.steady.steady.uitl.Cursor; | ||
import dev.steady.user.domain.User; | ||
|
@@ -33,6 +36,8 @@ | |
import static dev.steady.steady.domain.SteadyStatus.CLOSED; | ||
import static dev.steady.steady.domain.SteadyStatus.FINISHED; | ||
import static dev.steady.steady.domain.SteadyStatus.RECRUITING; | ||
import static dev.steady.steady.dto.RankType.PROJECT; | ||
import static dev.steady.steady.dto.RankType.STUDY; | ||
import static dev.steady.steady.infrastructure.util.DynamicQueryUtils.filterCondition; | ||
import static dev.steady.steady.infrastructure.util.DynamicQueryUtils.orderBySort; | ||
|
||
|
@@ -90,6 +95,18 @@ public Slice<MySteadyQueryResponse> findMySteadies(SteadyStatus status, User use | |
return new SliceImpl<>(content, pageable, hasNext); | ||
} | ||
|
||
@Override | ||
public List<Steady> findPopularStudyInCondition(RankCondition condition) { | ||
return jpaQueryFactory.selectFrom(steady) | ||
.where(steady.promotion.promotedAt | ||
.after(condition.date().atStartOfDay()), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
steadyTypeCond(condition.type()) | ||
) | ||
.orderBy(steady.likeCount.desc(), steady.viewCount.desc()) | ||
.limit(condition.limit()) | ||
.fetch(); | ||
} | ||
|
||
private BooleanExpression isParticipantUserIdEqual(User user) { | ||
return participant.user.id.eq(user.getId()); | ||
} | ||
|
@@ -113,6 +130,16 @@ private BooleanExpression isWorkSteady(SteadyStatus status) { | |
return null; | ||
} | ||
|
||
private BooleanExpression steadyTypeCond(RankType type) { | ||
if (type == PROJECT) { | ||
return steady.type.eq(SteadyType.PROJECT); | ||
} | ||
if (type == STUDY) { | ||
return steady.type.eq(SteadyType.STUDY); | ||
} | ||
return null; | ||
} | ||
|
||
private BooleanBuilder filterConditionBuilder(UserInfo userInfo, FilterConditionDto condition) { | ||
BooleanBuilder booleanBuilder = new BooleanBuilder(); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
import dev.steady.steady.dto.response.SteadyQueryResponse; | ||
import dev.steady.steady.dto.response.SteadyQuestionResponse; | ||
import dev.steady.steady.dto.response.SteadyQuestionsResponse; | ||
import dev.steady.steady.dto.response.SteadyRankResponse; | ||
import dev.steady.user.domain.Position; | ||
import dev.steady.user.domain.Stack; | ||
import dev.steady.user.domain.User; | ||
|
@@ -28,9 +29,11 @@ | |
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
import java.util.stream.IntStream; | ||
|
||
import static dev.steady.steady.domain.ScheduledPeriod.FIVE_MONTH; | ||
import static dev.steady.steady.domain.SteadyMode.ONLINE; | ||
import static dev.steady.steady.domain.SteadyStatus.CLOSED; | ||
import static dev.steady.steady.domain.SteadyType.STUDY; | ||
import static dev.steady.user.fixture.UserFixturesV2.generateStackEntity; | ||
import static org.instancio.Select.field; | ||
|
@@ -80,6 +83,19 @@ public static Steady createSteady(User leader, List<Stack> stacks) { | |
.build(); | ||
} | ||
|
||
public static List<Steady> createSteadiesWithLikeCount(User leader, List<Stack> stacks, int likeCount) { | ||
return IntStream.rangeClosed(0, likeCount) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 마지막값을 포함한다는걸 좀 더 명확하게 하고싶어서 사용했습니다! |
||
.mapToObj(count -> createSteadyWithLikeCount(leader, stacks, count)) | ||
.toList(); | ||
} | ||
|
||
public static List<SteadyRankResponse> createSteadyRankResponses() { | ||
return List.of( | ||
new SteadyRankResponse(2L, "스테디 제목2", STUDY, CLOSED, LocalDate.of(2023, 12, 31), 10, 1), | ||
new SteadyRankResponse(2L, "스테디 제목2", STUDY, CLOSED, LocalDate.of(2023, 12, 15), 10, 3) | ||
); | ||
} | ||
|
||
public static Steady createSteadyWithStatus(User leader, List<Stack> stacks, SteadyStatus status) { | ||
Steady steady = Steady.builder() | ||
.name("테스트 스테디") | ||
|
@@ -196,4 +212,10 @@ public static SliceResponse<MySteadyResponse> createMySteadyResponse() { | |
); | ||
} | ||
|
||
private static Steady createSteadyWithLikeCount(User leader, List<Stack> stacks, int likeCount) { | ||
Steady steady = createSteady(leader, stacks); | ||
ReflectionTestUtils.setField(steady, "likeCount", likeCount); | ||
return steady; | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
limit에 Max 값을 지정해줌으로써 예상치 못한 서버 에러를 방지하는 모습이 좋은 것 같습니다!