-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
feat:> MypageComment api #19
- Loading branch information
Showing
6 changed files
with
70 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/main/java/com/alevel/backend/controller/MypageCommentController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.alevel.backend.controller; | ||
|
||
import com.alevel.backend.controller.dto.MypageCommentResponseDto; | ||
import com.alevel.backend.service.MypageCommentService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RequiredArgsConstructor | ||
@RestController | ||
public class MypageCommentController { | ||
private final MypageCommentService mypageCommentService; | ||
|
||
@GetMapping("/user/{id}/comment") | ||
public MypageCommentResponseDto findByUserId(@PathVariable Long id){ | ||
return mypageCommentService.findByUserId(id); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/alevel/backend/controller/dto/MypageCommentResponseDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.alevel.backend.controller.dto; | ||
|
||
import com.alevel.backend.domain.comment.Comment; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class MypageCommentResponseDto { | ||
private String content; | ||
|
||
public MypageCommentResponseDto(Comment entity){ | ||
this.content=entity.getContent(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/main/java/com/alevel/backend/service/MypageCommentService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.alevel.backend.service; | ||
|
||
import com.alevel.backend.controller.dto.MypageCommentResponseDto; | ||
import com.alevel.backend.domain.comment.Comment; | ||
import com.alevel.backend.domain.comment.CommentRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@RequiredArgsConstructor | ||
@Service | ||
public class MypageCommentService { | ||
private final CommentRepository commentRepository; | ||
|
||
@Transactional | ||
public MypageCommentResponseDto findByUserId(Long id){ | ||
Comment entity = commentRepository.findByUserId(id).orElseThrow(() | ||
-> new IllegalArgumentException("작성한 댓글이 없습니다. id="+id)); | ||
return new MypageCommentResponseDto(entity); | ||
} | ||
} |