Skip to content

Commit

Permalink
add : 3차 세미나 실습 과제_ 포스트 전체 조회 리턴 값 PostFindDto로 변경 #7
Browse files Browse the repository at this point in the history
  • Loading branch information
PicturePark1101 committed May 1, 2024
1 parent 0bdefff commit 448350c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.example.demo.service.dto.member.MemberCreateDto;
import com.example.demo.service.dto.post.PostCreateRequest;
import com.example.demo.service.dto.post.PostFindDto;
import com.example.demo.service.dto.post.PostListFindDto;
import jakarta.validation.Valid;
import java.net.URI;
import java.util.List;
Expand Down Expand Up @@ -53,7 +54,7 @@ public ResponseEntity<SuccessStatusResponse> findPostList(
@PathVariable(name = "blogId") Long blogId
) {

List<PostFindDto> postList = postService.findAllPost(memberId, blogId);
PostListFindDto postList = postService.findAllPost(memberId, blogId);

return ResponseEntity.ok(SuccessStatusResponse.of(
SuccessMessage.POST_FIND_SUCCESS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.example.demo.repository.PostRepository;
import com.example.demo.service.dto.post.PostCreateRequest;
import com.example.demo.service.dto.post.PostFindDto;
import com.example.demo.service.dto.post.PostListFindDto;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -34,15 +35,14 @@ public String create(Long memberId, Long blogId, PostCreateRequest postCreateReq
return post.getId().toString();
}

public List<PostFindDto> findAllPost(Long memberId, Long blogId){
public PostListFindDto findAllPost(Long memberId, Long blogId){
// blog 찾기
Blog blog = blogService.findById(blogId);
Long findMemberId = blog.getMember().getId();

// 요청한 사람이 블로그 소유주인지 확인
blogService.validateOwner(memberId, findMemberId);

return postRepository.findByBlog(blog)
.stream().map(PostFindDto::of).toList();
return PostListFindDto.of(postRepository.findByBlog(blog));
}
}

0 comments on commit 448350c

Please sign in to comment.