-
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.
- Loading branch information
Showing
31 changed files
with
797 additions
and
101 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
13 changes: 12 additions & 1 deletion
13
src/main/java/com/leets/xcellentbe/domain/article/domain/repository/ArticleRepository.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,16 +1,27 @@ | ||
package com.leets.xcellentbe.domain.article.domain.repository; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
|
||
import com.leets.xcellentbe.domain.article.domain.Article; | ||
import com.leets.xcellentbe.domain.article.dto.ArticlesWithMediaDto; | ||
import com.leets.xcellentbe.domain.user.domain.User; | ||
|
||
import io.lettuce.core.dynamic.annotation.Param; | ||
|
||
public interface ArticleRepository extends JpaRepository<Article, UUID> { | ||
@Query("SELECT new com.leets.xcellentbe.domain.article.dto.ArticlesWithMediaDto(p, pm.filePath) FROM Article p LEFT JOIN PostMedia pm ON p.postId = pm.article.postId WHERE p.writer = :user") | ||
@Query("SELECT new com.leets.xcellentbe.domain.article.dto.ArticlesWithMediaDto(p, pm.filePath) FROM Article p LEFT JOIN PostMedia pm ON p.articleId = pm.article.articleId WHERE p.writer = :user") | ||
List<ArticlesWithMediaDto[]> findPostsByWriter(User user); | ||
|
||
@Query("SELECT a FROM Article a ORDER BY a.createdAt DESC") | ||
List<Article> findRecentArticles(Pageable pageable); | ||
|
||
@Query("SELECT a FROM Article a WHERE a.createdAt < :cursor ORDER BY a.createdAt DESC") | ||
List<Article> findRecentArticles(@Param("cursor") LocalDateTime cursor, Pageable pageable); | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/leets/xcellentbe/domain/article/dto/ArticleCreateRequestDto.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,10 @@ | ||
package com.leets.xcellentbe.domain.article.dto; | ||
|
||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
public class ArticleCreateRequestDto { | ||
private String content; | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/com/leets/xcellentbe/domain/article/dto/ArticleCreateResponseDto.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,27 @@ | ||
package com.leets.xcellentbe.domain.article.dto; | ||
|
||
import java.util.UUID; | ||
|
||
import com.leets.xcellentbe.domain.article.domain.Article; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
public class ArticleCreateResponseDto { | ||
|
||
private UUID articleId; | ||
|
||
@Builder | ||
private ArticleCreateResponseDto(UUID articleId, String message) { | ||
this.articleId = articleId; | ||
} | ||
|
||
public static ArticleCreateResponseDto from(Article article) { | ||
return ArticleCreateResponseDto.builder() | ||
.articleId(article.getArticleId()) | ||
.build(); | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
src/main/java/com/leets/xcellentbe/domain/article/dto/ArticleResponseDto.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,72 @@ | ||
package com.leets.xcellentbe.domain.article.dto; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
import java.util.stream.Collectors; | ||
|
||
import com.leets.xcellentbe.domain.article.domain.Article; | ||
import com.leets.xcellentbe.domain.articleMedia.domain.ArticleMedia; | ||
import com.leets.xcellentbe.domain.hashtag.domain.Hashtag; | ||
import com.leets.xcellentbe.domain.shared.DeletedStatus; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
public class ArticleResponseDto { | ||
private UUID articleId; | ||
private Long writerId; | ||
private String content; | ||
private DeletedStatus deletedStatus; | ||
private List<String> hashtags; | ||
private UUID rePostId; | ||
private List<String> mediaUrls; | ||
private int viewCnt; | ||
private int rePostCnt; | ||
private int likeCnt; | ||
private int commentCnt; | ||
private boolean owner; | ||
|
||
@Builder | ||
private ArticleResponseDto(UUID articleId, Long writerId, String content, DeletedStatus deletedStatus, | ||
List<String> hashtags, UUID rePostId, List<String> mediaUrls, int viewCnt, | ||
int rePostCnt, int likeCnt, int commentCnt, boolean owner) { | ||
this.articleId = articleId; | ||
this.writerId = writerId; | ||
this.content = content; | ||
this.deletedStatus = deletedStatus; | ||
this.hashtags = hashtags; | ||
this.rePostId = rePostId; | ||
this.mediaUrls = mediaUrls; | ||
this.viewCnt = viewCnt; | ||
this.rePostCnt = rePostCnt; | ||
this.likeCnt = likeCnt; | ||
this.commentCnt = commentCnt; | ||
this.owner = owner; | ||
} | ||
|
||
public static ArticleResponseDto from(Article article, boolean isOwner) { | ||
return ArticleResponseDto.builder() | ||
.articleId(article.getArticleId()) | ||
.content(article.getContent()) | ||
.deletedStatus(article.getDeletedStatus()) | ||
.writerId(article.getWriter().getUserId()) | ||
.hashtags(article.getHashtags() != null ? article.getHashtags() | ||
.stream() | ||
.map(Hashtag::getContent) | ||
.collect(Collectors.toList()) : null) | ||
.rePostId(article.getRePost() != null ? article.getRePost().getArticleId() : null) | ||
.mediaUrls(article.getMediaList() != null ? article.getMediaList() | ||
.stream() | ||
.map(ArticleMedia::getFilePath) // 이미지 URL로 매핑 | ||
.collect(Collectors.toList()) : null) | ||
.viewCnt(article.getViewCnt()) | ||
.rePostCnt(article.getRepostCnt()) | ||
.likeCnt(article.getLikeCnt()) | ||
.commentCnt(article.getCommentCnt()) | ||
.owner(isOwner) | ||
.build(); | ||
} | ||
} |
Oops, something went wrong.