Skip to content

Commit

Permalink
[Feature] 게시글 상세보기 아카이브 정보 추가 (#63)
Browse files Browse the repository at this point in the history
feat: 게시물 조회 시 archive 정보 추가 (#60)
  • Loading branch information
yongbin97 authored Oct 8, 2024
1 parent ef41c87 commit 23f5015
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.springframework.data.domain.PageRequest;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Component;
import project.backend.business.archive.implement.ArchiveReader;
import project.backend.business.post.request.PostDetailServiceRequest;
import project.backend.business.post.response.dto.PostDetailDto;
import project.backend.business.post.response.dto.PostListDto;
Expand All @@ -25,6 +26,7 @@ public class PostReader {

private final PostRepository postRepository;
private final TagReader tagReader;
private final ArchiveReader archiveReader;

public Post readActivatedPost(Long userId, Long postId) {
return postRepository.findByIdAndUserIdAndActivatedTrue(postId, userId)
Expand All @@ -34,8 +36,7 @@ public Post readActivatedPost(Long userId, Long postId) {
public Post readActivatedPublishedPost(Long userId, Long PostId) {
return postRepository.findPostByIdAndUserIdAndStatusAndActivatedTrue(PostId, userId,
PostStatus.PUBLISHED)
.orElseThrow(() -> new CustomException(
ErrorCode.BAD_REQUEST));
.orElseThrow(() -> new CustomException(ErrorCode.BAD_REQUEST));
}

public Post readActivatedPostAndWriter(Long postId) {
Expand All @@ -50,19 +51,19 @@ public List<PostListDto> readPostsWithTags(Specification<Post> spec, PageRequest
Map<Long, List<String>> postTagMap = tagReader.getPostTagMap(postIdList);

return postList.stream().map(
post -> PostListDto.builder()
.id(post.getId())
.title(post.getTitle())
.createdAt(DateTimeManager.convertToStringPattern(
post.getCreatedAt(), "yyyy.MM.dd"))
.tagList(postTagMap.get(post.getId()))
.build()
).toList();
post -> PostListDto.builder()
.id(post.getId())
.title(post.getTitle())
.createdAt(DateTimeManager.convertToStringPattern(
post.getCreatedAt(), "yyyy.MM.dd"))
.tagList(postTagMap.get(post.getId()))
.build())
.toList();
}

public PostDetailDto readPostDetailWithTags(Long userId,
PostDetailServiceRequest postDetailServiceRequest) {
Post postDetail = postRepository.findPostByIdAndUserIdAndStatusAndActivatedTrue(
Post postDetail = postRepository.findPostAndArchiveByIdAndUserIdAndStatusAndActivatedTrue(
postDetailServiceRequest.getPostId(),
userId,
postDetailServiceRequest.getStatus())
Expand All @@ -74,15 +75,13 @@ public PostDetailDto readPostDetailWithTags(Long userId,
.title(postDetail.getTitle())
.content(postDetail.getContent())
.url(postDetail.getUrl())
.tagList(tagList)
.createdAt(DateTimeManager.convertToStringPattern(
postDetail.getCreatedAt(),
"yyyy년 MM월 dd일"))
.tagList(tagList).createdAt(DateTimeManager.convertToStringPattern(
postDetail.getCreatedAt(), "yyyy년 MM월 dd일"))
.memoContent(postDetail.getMemo())
.memoCreatedAt(
DateTimeManager.convertToStringPattern(
postDetail.getMemoCreatedAt(),
"yy.MM.dd"))
.memoCreatedAt(DateTimeManager.convertToStringPattern(
postDetail.getMemoCreatedAt(), "yy.MM.dd"))
.archiveId(postDetail.getArchive().getId())
.archiveName(postDetail.getArchive().getName())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@ public class PostDetailResponse {
private final String createdAt;
private final String memoContent;
private final String memoCreatedAt;
private final Long archiveId;
private final String archiveName;

public static PostDetailResponse from(PostDetailDto postDetailDto) {
return PostDetailResponse.builder()
.title(postDetailDto.getTitle())
.content(postDetailDto.getContent())
.url(postDetailDto.getUrl())
.tagList(postDetailDto.getTagList())
.archiveId(postDetailDto.getArchiveId())
.archiveName(postDetailDto.getArchiveName())
.createdAt(postDetailDto.getCreatedAt())
.memoContent(postDetailDto.getMemoContent())
.memoCreatedAt(postDetailDto.getMemoCreatedAt())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ public class PostDetailDto {
private final String content;
private final String url;
private final List<String> tagList;
private final int archiveId;
private final Long archiveId;
private final String archiveName;
private final String createdAt;
private final String memoContent;
private final String memoCreatedAt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,7 @@ public interface PostRepository extends JpaRepository<Post, Long>, JpaSpecificat

Optional<Post> findPostByIdAndUserIdAndStatusAndActivatedTrue(Long postId, Long userId,
PostStatus status);

Optional<Post> findPostAndArchiveByIdAndUserIdAndStatusAndActivatedTrue(Long postId, Long userId,
PostStatus status);
}

0 comments on commit 23f5015

Please sign in to comment.