Skip to content

Commit

Permalink
Merge pull request #122 from Codiary-UMC-6th/feature/#111-set-post-re…
Browse files Browse the repository at this point in the history
…presentation-image

Feat: post 대표 이미지 설정 기능 구현
  • Loading branch information
lee-haeseung authored Aug 9, 2024
2 parents 9dd808d + d41261d commit e3d2e22
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ public static MemberResponseDTO.BookmarkDTO toBookmarkDTO(Bookmark bookmark) {
.memberId(bookmark.getMember().getMemberId())
.bookmarkId(bookmark.getId())
.postId(bookmark.getPost().getPostId())
// Post의 첫 번째 사진을 가져온다
// 나중에 postFile이 존재하지 않을 경우 나오는 기본 사진 처리를 해줘야 한다
.photoUrl(bookmark.getPost().getPostFileList().get(0).getFileUrl())
.thumbnailImageUrl((bookmark.getPost().getThumbnailImage() != null)
? bookmark.getPost().getThumbnailImage().getFileUrl()
: "")
.postTitle(bookmark.getPost().getPostTitle())
.nickname(bookmark.getPost().getMember().getNickname())
.postBody(bookmark.getPost().getPostBody())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public static Post toPost(PostRequestDTO.CreatePostRequestDTO request) {
.postStatus(request.getPostStatus())
//.categoriesList(categories)
.postAccess(request.getPostAccess())
.thumbnailImage(null)
.build();
}

Expand All @@ -41,6 +42,9 @@ public static PostResponseDTO.CreatePostResultDTO toCreateResultDTO(Post post) {
.map(author -> author.getMember().getMemberId())
.collect(Collectors.toSet()))
.postAccess(post.getPostAccess())
.thumbnailImageUrl((post.getThumbnailImage() != null)
? post.getThumbnailImage().getFileUrl()
: "")
.postFileList(PostFileConverter.toPostFileListDTO(post.getPostFileList()))
.build();
}
Expand All @@ -63,6 +67,9 @@ public static PostResponseDTO.UpdatePostResultDTO toUpdatePostResultDTO(Post pos
.map(author -> author.getMember().getMemberId())
.collect(Collectors.toSet()))
.postAccess(post.getPostAccess())
.thumbnailImageUrl((post.getThumbnailImage() != null)
? post.getThumbnailImage().getFileUrl()
: "")
.postFileList(PostFileConverter.toPostFileListDTO(post.getPostFileList()))
.build();
}
Expand All @@ -86,6 +93,9 @@ public static PostResponseDTO.PostPreviewDTO toPostPreviewDTO(Post post) {
.map(author -> author.getMember().getMemberId())
.collect(Collectors.toSet()))
.postAccess(post.getPostAccess())
.thumbnailImageUrl((post.getThumbnailImage() != null)
? post.getThumbnailImage().getFileUrl()
: "")
.postFileList(PostFileConverter.toPostFileListDTO(post.getPostFileList()))
.createdAt(post.getCreatedAt())
.updatedAt(post.getUpdatedAt())
Expand Down Expand Up @@ -127,6 +137,9 @@ public static PostResponseDTO.MemberPostPreviewDTO toMemberPostPreviewDTO(Post p
.map(author -> author.getMember().getMemberId())
.collect(Collectors.toSet()))
.postAccess(post.getPostAccess())
.thumbnailImageUrl((post.getThumbnailImage() != null)
? post.getThumbnailImage().getFileUrl()
: "")
.postFileList(PostFileConverter.toPostFileListDTO(post.getPostFileList()))
.createdAt(post.getCreatedAt())
.updatedAt(post.getUpdatedAt())
Expand Down Expand Up @@ -168,6 +181,9 @@ public static PostResponseDTO.TeamPostPreviewDTO toTeamPostPreviewDTO(Post post)
.map(author -> author.getMember().getMemberId())
.collect(Collectors.toSet()))
.postAccess(post.getPostAccess())
.thumbnailImageUrl((post.getThumbnailImage() != null)
? post.getThumbnailImage().getFileUrl()
: "")
.postFileList(PostFileConverter.toPostFileListDTO(post.getPostFileList()))
.createdAt(post.getCreatedAt())
.updatedAt(post.getUpdatedAt())
Expand Down Expand Up @@ -210,6 +226,9 @@ public static PostResponseDTO.MemberPostInProjectPreviewDTO toMemberPostInProjec
.map(author -> author.getMember().getMemberId())
.collect(Collectors.toSet()))
.postAccess(post.getPostAccess())
.thumbnailImageUrl((post.getThumbnailImage() != null)
? post.getThumbnailImage().getFileUrl()
: "")
.postFileList(PostFileConverter.toPostFileListDTO(post.getPostFileList()))
.createdAt(post.getCreatedAt())
.updatedAt(post.getUpdatedAt())
Expand Down Expand Up @@ -251,6 +270,9 @@ public static PostResponseDTO.TeamPostInProjectPreviewDTO toTeamPostInProjectPre
.map(author -> author.getMember().getMemberId())
.collect(Collectors.toSet()))
.postAccess(post.getPostAccess())
.thumbnailImageUrl((post.getThumbnailImage() != null)
? post.getThumbnailImage().getFileUrl()
: "")
.postFileList(PostFileConverter.toPostFileListDTO(post.getPostFileList()))
.createdAt(post.getCreatedAt())
.updatedAt(post.getUpdatedAt())
Expand Down Expand Up @@ -292,6 +314,9 @@ public static PostResponseDTO.MemberPostInTeamPreviewDTO toMemberPostInTeamPrevi
.map(author -> author.getMember().getMemberId())
.collect(Collectors.toSet()))
.postAccess(post.getPostAccess())
.thumbnailImageUrl((post.getThumbnailImage() != null)
? post.getThumbnailImage().getFileUrl()
: "")
.postFileList(PostFileConverter.toPostFileListDTO(post.getPostFileList()))
.createdAt(post.getCreatedAt())
.updatedAt(post.getUpdatedAt())
Expand Down Expand Up @@ -335,6 +360,9 @@ public static PostResponseDTO.PostAdjacentDTO.PostAdjacentPreviewDTO toPostAdjac
.map(author -> author.getMember().getMemberId())
.collect(Collectors.toSet()))
.postAccess(post.getPostAccess())
.thumbnailImageUrl((post.getThumbnailImage() != null)
? post.getThumbnailImage().getFileUrl()
: "")
.postFileList(PostFileConverter.toPostFileListDTO(post.getPostFileList()))
.createdAt(post.getCreatedAt())
.updatedAt(post.getUpdatedAt())
Expand Down Expand Up @@ -369,6 +397,9 @@ public static PostResponseDTO.UpdatePostResultDTO toSetPostCategoriesResultDTO(P
.map(author -> author.getMember().getMemberId())
.collect(Collectors.toSet()))
.postAccess(post.getPostAccess())
.thumbnailImageUrl((post.getThumbnailImage() != null)
? post.getThumbnailImage().getFileUrl()
: "")
.postFileList(PostFileConverter.toPostFileListDTO(post.getPostFileList()))
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ public class Post extends BaseEntity {
@Column(name = "post_body", nullable = false, columnDefinition = "varchar(500)")
private String postBody;

@OneToOne
@JoinColumn(name = "thumbnail_image_id")
private PostFile thumbnailImage;

@Builder.Default
@Enumerated(EnumType.STRING)
@Column(name = "post_access", nullable = false, columnDefinition = "varchar(500)")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,17 @@ public Post createPost(PostRequestDTO.CreatePostRequestDTO request) {
}
}

// 대표 사진 설정
String thumbnailImageName = request.getThumbnailImageName();
for (PostFile postFile : tempPost.getPostFileList()) {
if (postFile.getFileName().equals(thumbnailImageName)) {
tempPost.setThumbnailImage(postFile);
}
}
if (tempPost.getPostFileList().size() != 0 && tempPost.getThumbnailImage() == null) {
tempPost.setThumbnailImage(tempPost.getPostFileList().get(0));
}

Post savedPost = postRepository.save(tempPost);
return savedPost;
}
Expand Down Expand Up @@ -101,6 +112,17 @@ public Post updatePost(Long postId, PostRequestDTO.UpdatePostDTO request) {
}
}

// 대표 사진 설정
String thumbnailImageName = request.getThumbnailImageName();
for (PostFile postFile : updatePost.getPostFileList()) {
if (postFile.getFileName() == thumbnailImageName) {
updatePost.setThumbnailImage(postFile);
}
}
if (updatePost.getPostFileList().size() != 0 && updatePost.getThumbnailImage() == null) {
updatePost.setThumbnailImage(updatePost.getPostFileList().get(0));
}

return postRepository.save(updatePost);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static class BookmarkDTO {
Long memberId;
Long bookmarkId;
Long postId;
String photoUrl;
String thumbnailImageUrl;
String postTitle;
String nickname;
String postBody;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public static class CreatePostRequestDTO {
private Boolean postStatus;
//private Set<String> postCategory;
private PostAccess postAccess;
private String thumbnailImageName;
private List<MultipartFile> postFiles;
}

Expand All @@ -36,6 +37,7 @@ public static class UpdatePostDTO {
private Boolean postStatus;
//private Set<String> postCategory;
private PostAccess postAccess;
private String thumbnailImageName;
private List<MultipartFile> addedPostFiles;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public static class CreatePostResultDTO {
Long projectId;
String postTitle;
String postBody;
String thumbnailImageUrl;
Boolean postStatus;
String postCategory;
Set<Long> coauthorIds;
Expand All @@ -43,6 +44,7 @@ public static class UpdatePostResultDTO {
Long projectId;
String postTitle;
String postBody;
String thumbnailImageUrl;
Boolean postStatus;
String postCategory;
Set<Long> coauthorIds;
Expand All @@ -61,6 +63,7 @@ public static class PostPreviewDTO { // Post 조회
Long projectId;
String postTitle;
String postBody;
String thumbnailImageUrl;
Boolean postStatus;
String postCategory;
Set<Long> coauthorIds;
Expand Down Expand Up @@ -94,6 +97,7 @@ public static class MemberPostPreviewDTO { // 저자별 Post 조회
Long projectId;
String postTitle;
String postBody;
String thumbnailImageUrl;
Boolean postStatus;
String postCategory;
Set<Long> coauthorIds;
Expand Down Expand Up @@ -128,6 +132,7 @@ public static class TeamPostPreviewDTO { // 팀별 Post 조회
Long projectId;
String postTitle;
String postBody;
String thumbnailImageUrl;
Boolean postStatus;
String postCategory;
Set<Long> coauthorIds;
Expand Down Expand Up @@ -161,6 +166,7 @@ public static class MemberPostInProjectPreviewDTO { // 프로젝트별 저자의
Long teamId;
String postTitle;
String postBody;
String thumbnailImageUrl;
Boolean postStatus;
String postCategory;
Set<Long> coauthorIds;
Expand Down Expand Up @@ -194,6 +200,7 @@ public static class TeamPostInProjectPreviewDTO { // 프로젝트별 팀의 Post
Long memberId;
String postTitle;
String postBody;
String thumbnailImageUrl;
Boolean postStatus;
String postCategory;
Set<Long> coauthorIds;
Expand Down Expand Up @@ -227,6 +234,7 @@ public static class MemberPostInTeamPreviewDTO { // 팀별 멤버의 Post 조회
Long projectId;
String postTitle;
String postBody;
String thumbnailImageUrl;
Boolean postStatus;
String postCategory;
Set<Long> coauthorIds;
Expand Down Expand Up @@ -271,6 +279,7 @@ public static class PostAdjacentPreviewDTO {
Long projectId;
String postTitle;
String postBody;
String thumbnailImageUrl;
Boolean postStatus;
String postCategory;
Set<Long> coauthorIds;
Expand Down

0 comments on commit e3d2e22

Please sign in to comment.