-
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.
Browse files
Browse the repository at this point in the history
#84 GET - 베스트 활동 모임 및 모임별 글 조회
- Loading branch information
Showing
18 changed files
with
211 additions
and
25 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
9 changes: 9 additions & 0 deletions
9
module-domain/src/main/java/com/mile/moim/repository/MoimRepositoryCustom.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,9 @@ | ||
package com.mile.moim.repository; | ||
|
||
import com.mile.moim.domain.Moim; | ||
import java.util.List; | ||
|
||
public interface MoimRepositoryCustom { | ||
|
||
List<Moim> findTop3MoimsByPostCount(); | ||
} |
32 changes: 32 additions & 0 deletions
32
module-domain/src/main/java/com/mile/moim/repository/MoimRepositoryCustomImpl.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,32 @@ | ||
package com.mile.moim.repository; | ||
|
||
import static com.mile.moim.domain.QMoim.moim; | ||
import static com.mile.post.domain.QPost.post; | ||
|
||
import com.mile.moim.domain.Moim; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
public class MoimRepositoryCustomImpl implements MoimRepositoryCustom { | ||
private final JPAQueryFactory queryFactory; | ||
|
||
public List<Moim> findTop3MoimsByPostCount() { | ||
|
||
LocalDateTime oneWeekAgo = LocalDateTime.now().minusWeeks(1); | ||
|
||
List<Moim> result = queryFactory | ||
.select(moim) | ||
.from(moim) | ||
.leftJoin(post).on(moim.eq(post.topic.moim)) | ||
.where(post.createdAt.after(oneWeekAgo)) | ||
.groupBy(moim) | ||
.orderBy(post.id.count().desc()) | ||
.limit(3) | ||
.fetch(); | ||
|
||
return result; | ||
} | ||
} |
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
18 changes: 18 additions & 0 deletions
18
module-domain/src/main/java/com/mile/moim/service/dto/BestMoimInfoResponse.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,18 @@ | ||
package com.mile.moim.service.dto; | ||
|
||
import com.mile.moim.domain.Moim; | ||
import com.mile.post.domain.Post; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public record BestMoimInfoResponse(Long moimId, String moimName, List<BestMoimPostResponse> moimPosts) { | ||
public static BestMoimInfoResponse of(Moim moim, final List<Post> posts) { | ||
return new BestMoimInfoResponse( | ||
moim.getId(), | ||
moim.getName(), | ||
posts.stream() | ||
.map(BestMoimPostResponse::of) | ||
.collect(Collectors.toList()) | ||
); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
module-domain/src/main/java/com/mile/moim/service/dto/BestMoimListResponse.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,18 @@ | ||
package com.mile.moim.service.dto; | ||
|
||
import com.mile.moim.domain.Moim; | ||
import com.mile.post.domain.Post; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public record BestMoimListResponse(List<BestMoimInfoResponse> moim) { | ||
public static BestMoimListResponse of(Map<Moim, List<Post>> BestMoimAndPost) { | ||
List<BestMoimInfoResponse> bestMoims = new ArrayList<>(); | ||
for (Moim moim : BestMoimAndPost.keySet()) { | ||
bestMoims.add(BestMoimInfoResponse.of(moim, BestMoimAndPost.get(moim))); | ||
} | ||
return new BestMoimListResponse(bestMoims); | ||
|
||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
module-domain/src/main/java/com/mile/moim/service/dto/BestMoimPostResponse.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,31 @@ | ||
package com.mile.moim.service.dto; | ||
|
||
import com.mile.post.domain.Post; | ||
import org.jsoup.Jsoup; | ||
import org.jsoup.safety.Whitelist; | ||
|
||
public record BestMoimPostResponse(String topicName, String imageUrl, String postTitle, String postContent) { | ||
private static final int SUBSTRING_START = 0; | ||
private static final int SUBSTRING_END = 200; | ||
|
||
public static BestMoimPostResponse of(Post post) { | ||
|
||
return new BestMoimPostResponse( | ||
post.getTopic().getContent(), | ||
post.getImageUrl(), | ||
post.getTitle(), | ||
getSubStringOfCleanContent(post.getContent()) | ||
); | ||
} | ||
|
||
private static String getSubStringOfCleanContent( | ||
String content | ||
) { | ||
String cleanContent = Jsoup.clean(content, Whitelist.none()); | ||
if (cleanContent.length() >= SUBSTRING_END) { | ||
return cleanContent.substring(SUBSTRING_START, SUBSTRING_END); | ||
} else { | ||
return cleanContent; | ||
} | ||
} | ||
} |
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
Oops, something went wrong.