Skip to content

Commit

Permalink
Fix: post list 조회 response postId 추가 (#43)
Browse files Browse the repository at this point in the history
우체통 조회, 내가 쓴 게시물 조회 수정

#42
  • Loading branch information
wcorn authored Dec 25, 2023
1 parent a3478a7 commit 1b9f976
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.fubao.project.domain.api.post.dto.response;

import com.fubao.project.domain.entity.Post;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.springframework.beans.factory.annotation.Value;

import java.time.LocalDate;
import java.time.LocalDateTime;
Expand All @@ -14,12 +16,19 @@
@AllArgsConstructor
@Builder
public class PostMailBoxGetResponse {
String imageUrl;
String content;
LocalDateTime time;
@Schema(description = "post id", example = "1")
private Long postId;
@Schema(description = "게시글 이미지 주소", example = "https://d3hubo81q4ghxt.cloudfront.net/local/post/3cebc0ed-f1dd-4fab-9351-96efa8b912fa.jpg")
private String imageUrl;
@Schema(description = "게시글 내용", example = "hiii222")
private String content;
@Schema(description = "게시글 생성일", example = "2023-12-20T02:08:50")
private LocalDateTime date;

public PostMailBoxGetResponse(Post post) {
this.postId = post.getId();
this.imageUrl = post.getImageUrl();
this.content = post.getContent();
this.time = post.getCreatedAt();
this.date = post.getCreatedAt();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.fubao.project.domain.api.post.dto.response;

import com.fubao.project.domain.entity.Post;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -13,12 +14,18 @@
@AllArgsConstructor
@Builder
public class PostMyGetResponse {
String imageUrl;
String content;
LocalDateTime time;
@Schema(description = "post id", example = "1")
private Long postId;
@Schema(description = "게시글 이미지 주소", example = "https://d3hubo81q4ghxt.cloudfront.net/local/post/3cebc0ed-f1dd-4fab-9351-96efa8b912fa.jpg")
private String imageUrl;
@Schema(description = "게시글 내용", example = "hiii222")
private String content;
@Schema(description = "게시글 생성일", example = "2023-12-20T02:08:50")
private LocalDateTime date;
public PostMyGetResponse(Post post) {
this.postId = post.getId();
this.imageUrl = post.getImageUrl();
this.content = post.getContent();
this.time = post.getCreatedAt();
this.date = post.getCreatedAt();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.fubao.project.domain.entity.Member;
import com.fubao.project.domain.entity.Post;
import com.fubao.project.domain.repository.MemberRepository;
import com.fubao.project.domain.repository.PostCustomRepository;
import com.fubao.project.domain.repository.PostRepository;
import com.fubao.project.global.common.exception.ResponseCode;
import com.fubao.project.global.common.exception.CustomException;
Expand All @@ -31,7 +30,6 @@ public class PostServiceImp implements PostService {
private final static String DIR = "post";
private final S3Util s3Util;
private final PostRepository postRepository;
private final PostCustomRepository postCustomRepository;
private final MemberRepository memberRepository;

@Override
Expand Down Expand Up @@ -60,7 +58,7 @@ public PostPatchResponse patch(MultipartFile image, PostWriteRequest postWriteRe
Post post = findPostById(postId);
String imageUrl = null;
String prevImage = post.getImageUrl();
if(!post.getMember().getId().equals(memberId))
if (!post.getMember().getId().equals(memberId))
throw new CustomException(ResponseCode.DO_NOT_PATCH_POST);
if (image != null && !image.isEmpty()) {
imageUrl = uploadS3Image(image);
Expand Down Expand Up @@ -99,7 +97,8 @@ public List<PostMailBoxGetResponse> getMailBox(Pageable pageable) {
Page<Post> postList = postRepository.findAll(pageable);
return postList.stream().map(
post -> PostMailBoxGetResponse.builder()
.time(post.getCreatedAt())
.postId(post.getId())
.date(post.getCreatedAt())
.content(post.getContent())
.imageUrl(post.getImageUrl())
.build()
Expand All @@ -112,8 +111,9 @@ public List<PostMyGetResponse> myPostGet(UUID memberId) {
List<Post> myPostList = member.getPostList();
return myPostList.stream().map(
post -> PostMyGetResponse.builder()
.postId(post.getId())
.content(post.getContent())
.time(post.getCreatedAt())
.date(post.getCreatedAt())
.imageUrl(post.getImageUrl()).build()
).collect(Collectors.toList());
}
Expand Down

0 comments on commit 1b9f976

Please sign in to comment.