Skip to content

Commit

Permalink
Merge pull request #32 from Leets-Official/fix/#31/게시글-목록-조회-문제-파일-업로…
Browse files Browse the repository at this point in the history
…드-문제

[Fix] 게시글 목록 조회 문제 파일 업로드 문제
  • Loading branch information
ehs208 authored Nov 13, 2024
2 parents 7eb51b4 + 61fe28a commit 040f0bd
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
@NoArgsConstructor
public class ArticleResponseDto {
private UUID articleId;
private Long writerId;
private String customId;
private String userName;
private String content;
private DeletedStatus deletedStatus;
private List<String> hashtags;
Expand All @@ -34,11 +35,13 @@ public class ArticleResponseDto {
private boolean owner;

@Builder
private ArticleResponseDto(UUID articleId, Long writerId, String content, DeletedStatus deletedStatus,
List<String> hashtags, UUID rePostId, List<String> mediaUrls, List<CommentResponseDto> comments,
int viewCnt, long rePostCnt, long likeCnt, long commentCnt, boolean owner) {
private ArticleResponseDto(UUID articleId, String userName, String customId, String content,
DeletedStatus deletedStatus,
List<String> hashtags, UUID rePostId, List<String> mediaUrls, List<CommentResponseDto> comments,
int viewCnt, long rePostCnt, long likeCnt, long commentCnt, boolean owner) {
this.articleId = articleId;
this.writerId = writerId;
this.userName = userName;
this.customId = customId;
this.content = content;
this.deletedStatus = deletedStatus;
this.hashtags = hashtags;
Expand All @@ -52,12 +55,14 @@ private ArticleResponseDto(UUID articleId, Long writerId, String content, Delete
this.comments = comments;
}

public static ArticleResponseDto from(Article article, boolean isOwner, ArticleStatsDto stats, Map<UUID, CommentStatsDto> replyStatsMap) {
public static ArticleResponseDto from(Article article, boolean isOwner, ArticleStatsDto stats,
Map<UUID, CommentStatsDto> replyStatsMap) {
return ArticleResponseDto.builder()
.articleId(article.getArticleId())
.content(article.getContent())
.deletedStatus(article.getDeletedStatus())
.writerId(article.getWriter().getUserId())
.userName(article.getWriter().getUserName())
.customId(article.getWriter().getCustomId())
.hashtags(article.getHashtags() != null ? article.getHashtags()
.stream()
.map(Hashtag::getContent)
Expand All @@ -69,9 +74,11 @@ public static ArticleResponseDto from(Article article, boolean isOwner, ArticleS
.collect(Collectors.toList()) : null)
.comments(article.getComments() != null ? article.getComments()
.stream()
.filter(comment -> comment != null && comment.getDeletedStatus() == DeletedStatus.NOT_DELETED) // null 및 삭제된 댓글 필터링
.filter(comment -> comment != null
&& comment.getDeletedStatus() == DeletedStatus.NOT_DELETED) // null 및 삭제된 댓글 필터링
.map(comment -> {
CommentStatsDto commentStats = replyStatsMap.getOrDefault(comment.getCommentId(), CommentStatsDto.from(0, 0));
CommentStatsDto commentStats = replyStatsMap.getOrDefault(comment.getCommentId(),
CommentStatsDto.from(0, 0));
boolean isCommentOwner = comment.getWriter().getUserId().equals(article.getWriter().getUserId());
return CommentResponseDto.from(comment, isCommentOwner, commentStats, replyStatsMap, 1); // 깊이 1로 제한
})
Expand All @@ -89,7 +96,8 @@ public static ArticleResponseDto fromWithoutComments(Article article, boolean is
.articleId(article.getArticleId())
.content(article.getContent())
.deletedStatus(article.getDeletedStatus())
.writerId(article.getWriter().getUserId())
.userName(article.getWriter().getUserName())
.customId(article.getWriter().getCustomId())
.hashtags(article.getHashtags() != null ? article.getHashtags()
.stream()
.map(Hashtag::getContent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ public class S3UploadMediaService {
public String upload(MultipartFile multipartFile, String dirName) {
String fileName = multipartFile.getOriginalFilename();

if (!(fileName.endsWith(".png") || fileName.endsWith(".jpg"))) {
if (!(fileName.endsWith(".png") || fileName.endsWith(".jpg") || fileName.endsWith(".jpeg") || fileName.endsWith(
".gif") || fileName.endsWith(".bmp"))) {
throw new InvalidFileFormat();
}
try {
File uploadFile = convert(multipartFile)
.orElseThrow(()->new RuntimeException());
.orElseThrow(() -> new RuntimeException());
return upload(uploadFile, dirName);
} catch (IOException e) {
throw new InternalServerErrorException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public class S3UploadService {
// MultipartFile을 전달받아 File로 전환한 후 S3에 업로드
public String upload(MultipartFile multipartFile, String dirName) { // dirName의 디렉토리가 S3 Bucket 내부에 생성됨
String fileName = multipartFile.getOriginalFilename();
if ((fileName.endsWith(".png") || fileName.endsWith(".jpg"))) {
if (!(fileName.endsWith(".png") || fileName.endsWith(".jpg") || fileName.endsWith(".jpeg") || fileName.endsWith(
".gif") || fileName.endsWith(".bmp"))) {
throw new InvalidFileFormat();
}

Expand Down

0 comments on commit 040f0bd

Please sign in to comment.