-
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 #41 from ssu-student-union/feat/40-post
[feat] #40 게시판별 좋아요 많은 게시물 api 구현 및 쿼리dsl, common(페이지네이션, p6spy)
- Loading branch information
Showing
13 changed files
with
213 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
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
25 changes: 25 additions & 0 deletions
25
src/main/java/ussum/homepage/application/post/service/dto/response/SimplePostResponse.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,25 @@ | ||
package ussum.homepage.application.post.service.dto.response; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import ussum.homepage.domain.post.Post; | ||
|
||
@Builder(access = AccessLevel.PRIVATE) | ||
public record SimplePostResponse( | ||
Long postId, | ||
String title, | ||
String content, | ||
String date, | ||
Integer like | ||
) { | ||
public static SimplePostResponse of(Post post, | ||
Integer like){ | ||
return SimplePostResponse.builder() | ||
.postId(post.getId()) | ||
.title(post.getTitle()) | ||
.content(post.getContent()) | ||
.date(post.getCreatedAt()) | ||
.like(like) | ||
.build(); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...n/java/ussum/homepage/application/post/service/dto/response/TopLikedPostListResponse.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,19 @@ | ||
package ussum.homepage.application.post.service.dto.response; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import ussum.homepage.global.common.PageInfo; | ||
|
||
import java.util.List; | ||
@Builder(access = AccessLevel.PRIVATE) | ||
public record TopLikedPostListResponse( | ||
List<SimplePostResponse> posts, | ||
PageInfo pageInfo | ||
) { | ||
public static TopLikedPostListResponse of(List<SimplePostResponse> posts, PageInfo pageInfo){ | ||
return TopLikedPostListResponse.builder() | ||
.posts(posts) | ||
.pageInfo(pageInfo) | ||
.build(); | ||
} | ||
} |
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
31 changes: 31 additions & 0 deletions
31
src/main/java/ussum/homepage/global/common/CustomP6spySqlFormatter.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 ussum.homepage.global.common; | ||
|
||
import com.p6spy.engine.logging.Category; | ||
import com.p6spy.engine.spy.appender.MessageFormattingStrategy; | ||
import org.hibernate.engine.jdbc.internal.FormatStyle; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.time.LocalDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
import java.util.Locale; | ||
|
||
@Component | ||
public class CustomP6spySqlFormatter implements MessageFormattingStrategy { | ||
@Override | ||
public String formatMessage(int connectionId, String now, long elapsed, String category, String prepared, String sql, String url) { | ||
sql = formatSql(category, sql); | ||
return String.format("[SQL] %s | %s | %d ms | %s ", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(LocalDateTime.now()), category, elapsed, formatSql(category, sql)); | ||
} | ||
|
||
private String formatSql(String category, String sql) { | ||
if (sql != null && !sql.trim().isEmpty() && Category.STATEMENT.getName().equals(category)) { | ||
String trimmedSql = sql.trim().toLowerCase(Locale.ROOT); | ||
if (trimmedSql.startsWith("create") || trimmedSql.startsWith("alter") || trimmedSql.startsWith("comment")) { | ||
sql = FormatStyle.DDL.getFormatter().format(sql); | ||
} | ||
sql = FormatStyle.BASIC.getFormatter().format(sql); | ||
return sql; | ||
} | ||
return sql; | ||
} | ||
} |
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,27 @@ | ||
package ussum.homepage.global.common; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.PageRequest; | ||
import org.springframework.data.domain.Pageable; | ||
|
||
@Builder(access = AccessLevel.PRIVATE) | ||
public record PageInfo( | ||
int pageNum, | ||
int pageSize, | ||
long totalElements, | ||
long totalPages | ||
) { | ||
public static PageInfo of(Page<?> page) { | ||
return PageInfo.builder() | ||
.pageNum(page.getNumber()) | ||
.pageSize(page.getSize()) | ||
.totalElements(page.getTotalElements()) | ||
.totalPages(page.getTotalPages()) | ||
.build(); | ||
} | ||
public static Pageable of(int page, int take){ | ||
return PageRequest.of(page, take); | ||
} | ||
} |
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
11 changes: 11 additions & 0 deletions
11
src/main/java/ussum/homepage/infra/jpa/post/dto/SimplePostDto.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,11 @@ | ||
package ussum.homepage.infra.jpa.post.dto; | ||
|
||
import ussum.homepage.infra.jpa.post.entity.PostEntity; | ||
|
||
|
||
public record SimplePostDto(PostEntity postEntity, Long likeCount) { | ||
|
||
public static SimplePostDto of(PostEntity post, Long likeCount) { | ||
return new SimplePostDto(post, likeCount); | ||
} | ||
} |