File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed
src/main/java/com/back/domain/post/post Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -41,4 +41,16 @@ public RsData<PostResponseDto> createPost(
4141 public RsData <List <PostResponseDto >> getAllPosts () {
4242 return RsData .successOf (postService .getAllPosts ()); // code=200, message="success"
4343 }
44+
45+ /**
46+ * 게시글 단건 조회 API
47+ * @param postId 조회할 게시글 ID
48+ * @return 해당 ID의 게시글 정보
49+ */
50+ @ GetMapping ("/{postId}" )
51+ public RsData <PostResponseDto > getPost (
52+ @ PathVariable Long postId
53+ ) {
54+ return RsData .successOf (postService .getPost (postId )); // code=200, message="success"
55+ }
4456}
Original file line number Diff line number Diff line change 1111import com .back .domain .user .entity .User ;
1212import com .back .global .rq .Rq ;
1313import java .util .List ;
14+ import java .util .NoSuchElementException ;
1415import java .util .stream .Collectors ;
1516import lombok .RequiredArgsConstructor ;
1617import org .springframework .stereotype .Service ;
@@ -69,4 +70,13 @@ public List<PostResponseDto> getAllPosts() {
6970 .map (PostResponseDto ::new )
7071 .collect (Collectors .toList ());
7172 }
73+
74+ // 게시글 단건 조회 로직
75+ @ Transactional (readOnly = true )
76+ public PostResponseDto getPost (Long postId ) {
77+ return new PostResponseDto (
78+ postRepository .findById (postId )
79+ .orElseThrow (() -> new NoSuchElementException ("해당 게시글을 찾을 수 없습니다. ID: " + postId ))
80+ );
81+ }
7282}
You can’t perform that action at this time.
0 commit comments