Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature/post-service] 댓글 API 테스트코드 작성 #58

Merged
merged 1 commit into from
Mar 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/docs/asciidoc/board.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ include::{snippets}/default-board-create/http-response.adoc[]

==== 3. 소개 게시글 작성하기
===== Request
include::{snippets}/intro-post-create/http-request.adoc[]
include::{snippets}/intro-board-create/http-request.adoc[]
===== Response
include::{snippets}/intro-post-create/http-response.adoc[]
include::{snippets}/intro-board-create/http-response.adoc[]

==== 4. 게시글 리스트 조회 ( 페이징 처리 )
===== Request
Expand Down
25 changes: 25 additions & 0 deletions src/docs/asciidoc/comment.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
== Comment API

=== 1. 게시글에 대한 댓글 리스트 조회
===== Request
include::{snippets}/get-comment-all/http-request.adoc[]
===== Response
include::{snippets}/get-comment-all/http-response.adoc[]

=== 2. 댓글 작성
===== Request
include::{snippets}/comment-create/http-request.adoc[]
===== Response
include::{snippets}/comment-create/http-response.adoc[]

=== 3. 댓글 수정
===== Request
include::{snippets}/comment-update/http-request.adoc[]
===== Response
include::{snippets}/comment-update/http-response.adoc[]

=== 4. 댓글 삭제
===== Request
include::{snippets}/comment-delete/http-request.adoc[]
===== Response
include::{snippets}/comment-delete/http-response.adoc[]
3 changes: 2 additions & 1 deletion src/docs/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ endif::[]
제작 <5do2chonri@gmail.com> +
제작일 2023-03-23 +

*해당 문서는 주말의 집을 제작하는 오도리 팀에게 있으며, 무단 배포/변형을 금지합니다.*
*해당 문서의 저작권은 주말의 집을 제작하는 오도리 팀에게 있으며, 무단 배포/변형을 금지합니다.*

include::user.adoc[]
include::board.adoc[]
include::comment.adoc[]
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
package com.example.jhouse_server.domain.comment.controller // ktlint-disable package-name

import com.example.jhouse_server.domain.comment.dto.CommentCreateReqDto
import com.example.jhouse_server.domain.comment.dto.CommentReqDto
import com.example.jhouse_server.domain.comment.dto.CommentResDto
import com.example.jhouse_server.domain.comment.dto.CommentUpdateReqDto
import com.example.jhouse_server.domain.comment.service.CommentService
import com.example.jhouse_server.domain.user.entity.User
import com.example.jhouse_server.global.annotation.Auth
import com.example.jhouse_server.global.annotation.AuthUser
import com.example.jhouse_server.global.response.ApplicationResponse
import org.springframework.validation.annotation.Validated
import org.springframework.web.bind.annotation.DeleteMapping
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.PutMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import org.springframework.web.bind.annotation.*

@RestController
@RequestMapping("/api/v1/comments")
Expand All @@ -30,24 +23,27 @@ class CommentController(
return ApplicationResponse.ok(commentService.getCommentAll(boardId))
}

@Auth
@PostMapping
fun createComment(
@RequestBody @Validated req: CommentCreateReqDto,
@RequestBody @Validated req: CommentReqDto,
@AuthUser user: User
): ApplicationResponse<Long> {
return ApplicationResponse.ok(commentService.createComment(req, user))
}

@Auth
@PutMapping("/{commentId}")
fun updateComment(
@PathVariable commentId: Long,
@RequestBody @Validated req: CommentUpdateReqDto,
@RequestBody @Validated req: CommentReqDto,
@AuthUser user: User
): ApplicationResponse<Long> {
return ApplicationResponse.ok(commentService.updateComment(commentId, req, user))
}

@DeleteMapping("{/commentId}")
@Auth
@DeleteMapping("/{commentId}")
fun deleteComment(
@PathVariable commentId: Long,
@AuthUser user: User
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.example.jhouse_server.domain.comment.dto

import com.example.jhouse_server.domain.comment.entity.Comment
import java.time.format.DateTimeFormatter
import javax.validation.constraints.NotBlank
import javax.validation.constraints.NotNull

data class CommentResDto(
Expand All @@ -12,7 +11,7 @@ data class CommentResDto(
val createdAt: String,
)

data class CommentCreateReqDto(
data class CommentReqDto(
@field:NotNull(message = "게시글ID 필수값입니다.")
val boardId: Long? = null,
@field:NotNull(message = "댓글 내용은 필수값입니다.")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.example.jhouse_server.domain.comment.service

import com.example.jhouse_server.domain.comment.dto.CommentCreateReqDto
import com.example.jhouse_server.domain.comment.dto.CommentReqDto
import com.example.jhouse_server.domain.comment.dto.CommentResDto
import com.example.jhouse_server.domain.comment.dto.CommentUpdateReqDto
import com.example.jhouse_server.domain.user.entity.User
Expand All @@ -9,8 +9,8 @@ interface CommentService {

fun getCommentAll(postId : Long) : List<CommentResDto>

fun createComment(req: CommentCreateReqDto, user: User) : Long
fun createComment(req: CommentReqDto, user: User) : Long

fun updateComment(commentId: Long, req: CommentUpdateReqDto, user: User) : Long
fun updateComment(commentId: Long, req: CommentReqDto, user: User) : Long
fun deleteComment(commentId: Long, user: User)
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.example.jhouse_server.domain.comment.service

import com.example.jhouse_server.domain.board.repository.BoardRepository
import com.example.jhouse_server.domain.comment.dto.CommentCreateReqDto
import com.example.jhouse_server.domain.comment.dto.CommentReqDto
import com.example.jhouse_server.domain.comment.dto.CommentResDto
import com.example.jhouse_server.domain.comment.dto.CommentUpdateReqDto
import com.example.jhouse_server.domain.comment.dto.toDto
Expand All @@ -25,7 +25,7 @@ class CommentServiceImpl(
}

@Transactional
override fun createComment(req: CommentCreateReqDto, user: User): Long {
override fun createComment(req: CommentReqDto, user: User): Long {
val board = boardRepository.findByIdOrThrow(req.boardId)
val comment = Comment(
board, req.content!!, user
Expand All @@ -34,7 +34,7 @@ class CommentServiceImpl(
}

@Transactional
override fun updateComment(commentId: Long, req: CommentUpdateReqDto, user: User): Long {
override fun updateComment(commentId: Long, req: CommentReqDto, user: User): Long {
val comment = commentRepository.findByIdOrThrow(commentId)
return if (user == comment.user) {
comment.updateEntity(req.content!!).id
Expand Down
56 changes: 28 additions & 28 deletions src/main/resources/static/docs/board.html
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ <h5 id="_request">Request</h5>
<div class="content">
<pre class="highlight nowrap"><code class="language-http" data-lang="http">POST /api/v1/boards HTTP/1.1
Content-Type: application/json;charset=UTF-8
Authorization: Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJ0ZXN0X2pob3VzZV9jb20iLCJleHAiOjE2Nzk1MDQ5MDAsImF1dGgiOiJVU0VSIn0.ikNbrtvUVdD2Tl_Gg_WbsI81drZ2Tl2M4kCg9HEB41kdTP4KpbJkT9JgoJtrAtZV0rfYn44X1mcGz08d3SM6bQ
Authorization: Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJ0ZXN0X2pob3VzZV9jb20iLCJleHAiOjE2Nzk1NTE0MjQsImF1dGgiOiJVU0VSIn0.ka4Labm-4PYe1i85mxhL1NG5LocGBOkjf0X69MvHtZoWrodh4UwVPovAp60dA75F6plekEJim-62DPxey1e7jA
Accept: application/json
Content-Length: 334
Host: localhost:8080
Expand All @@ -478,12 +478,12 @@ <h4 id="_response">Response</h4>
Vary: Access-Control-Request-Method
Vary: Access-Control-Request-Headers
Content-Type: application/json;charset=UTF-8
Content-Length: 63
Content-Length: 64

{
"code" : "SUCCESS",
"message" : "성공",
"data" : 66
"data" : 298
}</code></pre>
</div>
</div>
Expand All @@ -496,7 +496,7 @@ <h5 id="_request_2">Request</h5>
<div class="content">
<pre class="highlight nowrap"><code class="language-http" data-lang="http">POST /api/v1/boards HTTP/1.1
Content-Type: application/json;charset=UTF-8
Authorization: Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJ0ZXN0X2pob3VzZV9jb20iLCJleHAiOjE2Nzk1MDQ5MDAsImF1dGgiOiJVU0VSIn0.ikNbrtvUVdD2Tl_Gg_WbsI81drZ2Tl2M4kCg9HEB41kdTP4KpbJkT9JgoJtrAtZV0rfYn44X1mcGz08d3SM6bQ
Authorization: Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJ0ZXN0X2pob3VzZV9jb20iLCJleHAiOjE2Nzk1NTE0MjQsImF1dGgiOiJVU0VSIn0.ka4Labm-4PYe1i85mxhL1NG5LocGBOkjf0X69MvHtZoWrodh4UwVPovAp60dA75F6plekEJim-62DPxey1e7jA
Accept: application/json
Content-Length: 330
Host: localhost:8080
Expand All @@ -522,12 +522,12 @@ <h5 id="_response_2">Response</h5>
Vary: Access-Control-Request-Method
Vary: Access-Control-Request-Headers
Content-Type: application/json;charset=UTF-8
Content-Length: 63
Content-Length: 64

{
"code" : "SUCCESS",
"message" : "성공",
"data" : 64
"data" : 296
}</code></pre>
</div>
</div>
Expand All @@ -541,7 +541,7 @@ <h5 id="_request_3">Request</h5>
<div class="content">
<pre class="highlight nowrap"><code class="language-http" data-lang="http">POST /api/v1/boards HTTP/1.1
Content-Type: application/json;charset=UTF-8
Authorization: Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJ0ZXN0X2pob3VzZV9jb20iLCJleHAiOjE2Nzk1MDQ4OTksImF1dGgiOiJVU0VSIn0.n-vaQmLOo6uU4eXAYL8PnOYrJQra9a7TRFPBBoq-c0zcvxnlDlQE8_sK_a1o8os96pGE7uyeOjDN2rjbPCVJlA
Authorization: Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJ0ZXN0X2pob3VzZV9jb20iLCJleHAiOjE2Nzk1NTE0MjQsImF1dGgiOiJVU0VSIn0.ka4Labm-4PYe1i85mxhL1NG5LocGBOkjf0X69MvHtZoWrodh4UwVPovAp60dA75F6plekEJim-62DPxey1e7jA
Accept: application/json
Content-Length: 335
Host: localhost:8080
Expand All @@ -567,12 +567,12 @@ <h5 id="_response_3">Response</h5>
Vary: Access-Control-Request-Method
Vary: Access-Control-Request-Headers
Content-Type: application/json;charset=UTF-8
Content-Length: 63
Content-Length: 64

{
"code" : "SUCCESS",
"message" : "성공",
"data" : 59
"data" : 291
}</code></pre>
</div>
</div>
Expand All @@ -599,14 +599,14 @@ <h5 id="_response_4">Response</h5>
Vary: Access-Control-Request-Method
Vary: Access-Control-Request-Headers
Content-Type: application/json;charset=UTF-8
Content-Length: 975
Content-Length: 976

{
"code" : "SUCCESS",
"message" : "성공",
"data" : {
"content" : [ {
"boardId" : 60,
"boardId" : 292,
"title" : "짱구는 못말려",
"code" : "&lt;body&gt; &lt;div&gt; &lt;h2&gt;짱구는 못말려&lt;/h2&gt; &lt;/div&gt; &lt;div&gt; &lt;i&gt;철수&lt;/i&gt;야 나랑 놀자 &lt;/div&gt; &lt;/body&gt;",
"oneLineContent" : "짱구는 못말려철수야 나랑 놀자",
Expand All @@ -618,26 +618,26 @@ <h5 id="_response_4">Response</h5>
"pageable" : {
"sort" : {
"empty" : true,
"sorted" : false,
"unsorted" : true
"unsorted" : true,
"sorted" : false
},
"offset" : 0,
"pageSize" : 20,
"pageNumber" : 0,
"pageSize" : 20,
"paged" : true,
"unpaged" : false
},
"last" : true,
"totalPages" : 1,
"totalElements" : 1,
"number" : 0,
"size" : 20,
"sort" : {
"empty" : true,
"sorted" : false,
"unsorted" : true
"unsorted" : true,
"sorted" : false
},
"size" : 20,
"first" : true,
"number" : 0,
"numberOfElements" : 1,
"empty" : false
}
Expand All @@ -652,7 +652,7 @@ <h4 id="_5_게시글_상세_조회">5. 게시글 상세 조회</h4>
<h5 id="_request_5">Request</h5>
<div class="listingblock">
<div class="content">
<pre class="highlight nowrap"><code class="language-http" data-lang="http">GET /api/v1/boards/61 HTTP/1.1
<pre class="highlight nowrap"><code class="language-http" data-lang="http">GET /api/v1/boards/293 HTTP/1.1
Accept: application/json
Host: localhost:8080</code></pre>
</div>
Expand All @@ -667,13 +667,13 @@ <h5 id="_response_5">Response</h5>
Vary: Access-Control-Request-Method
Vary: Access-Control-Request-Headers
Content-Type: application/json;charset=UTF-8
Content-Length: 407
Content-Length: 408

{
"code" : "SUCCESS",
"message" : "성공",
"data" : {
"boardId" : 61,
"boardId" : 293,
"title" : "짱구는 못말려",
"code" : "&lt;body&gt; &lt;div&gt; &lt;h2&gt;짱구는 못말려&lt;/h2&gt; &lt;/div&gt; &lt;div&gt; &lt;i&gt;철수&lt;/i&gt;야 나랑 놀자 &lt;/div&gt; &lt;/body&gt;",
"nickName" : "테스트유저1",
Expand All @@ -694,9 +694,9 @@ <h4 id="_6_게시글_수정">6. 게시글 수정</h4>
<h5 id="_request_6">Request</h5>
<div class="listingblock">
<div class="content">
<pre class="highlight nowrap"><code class="language-http" data-lang="http">PUT /api/v1/boards/62 HTTP/1.1
<pre class="highlight nowrap"><code class="language-http" data-lang="http">PUT /api/v1/boards/294 HTTP/1.1
Content-Type: application/json;charset=UTF-8
Authorization: Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJ0ZXN0X2pob3VzZV9jb20iLCJleHAiOjE2Nzk1MDQ5MDAsImF1dGgiOiJVU0VSIn0.ikNbrtvUVdD2Tl_Gg_WbsI81drZ2Tl2M4kCg9HEB41kdTP4KpbJkT9JgoJtrAtZV0rfYn44X1mcGz08d3SM6bQ
Authorization: Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJ0ZXN0X2pob3VzZV9jb20iLCJleHAiOjE2Nzk1NTE0MjQsImF1dGgiOiJVU0VSIn0.ka4Labm-4PYe1i85mxhL1NG5LocGBOkjf0X69MvHtZoWrodh4UwVPovAp60dA75F6plekEJim-62DPxey1e7jA
Accept: application/json
Content-Length: 273
Host: localhost:8080
Expand All @@ -722,12 +722,12 @@ <h5 id="_response_6">Response</h5>
Vary: Access-Control-Request-Method
Vary: Access-Control-Request-Headers
Content-Type: application/json;charset=UTF-8
Content-Length: 63
Content-Length: 64

{
"code" : "SUCCESS",
"message" : "성공",
"data" : 62
"data" : 294
}</code></pre>
</div>
</div>
Expand All @@ -739,8 +739,8 @@ <h4 id="_7_게시글_삭제">7. 게시글 삭제</h4>
<h5 id="_request_7">Request</h5>
<div class="listingblock">
<div class="content">
<pre class="highlight nowrap"><code class="language-http" data-lang="http">DELETE /api/v1/boards/57 HTTP/1.1
Authorization: Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJ0ZXN0X2pob3VzZV9jb20iLCJleHAiOjE2Nzk1MDQ4OTksImF1dGgiOiJVU0VSIn0.n-vaQmLOo6uU4eXAYL8PnOYrJQra9a7TRFPBBoq-c0zcvxnlDlQE8_sK_a1o8os96pGE7uyeOjDN2rjbPCVJlA
<pre class="highlight nowrap"><code class="language-http" data-lang="http">DELETE /api/v1/boards/289 HTTP/1.1
Authorization: Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJ0ZXN0X2pob3VzZV9jb20iLCJleHAiOjE2Nzk1NTE0MjMsImF1dGgiOiJVU0VSIn0.NmxPUDZxF4-QkYCMKVD6JT3K2rzPxZgJEwb_3s1ix_UdcGxz46ygqq4FNTawZCD50ZJ6MMwklIzE0nCEJoya5A
Host: localhost:8080</code></pre>
</div>
</div>
Expand Down Expand Up @@ -808,7 +808,7 @@ <h5 id="_response_8">Response</h5>
<div id="footer">
<div id="footer-text">
Version 0.0.1-SNAPSHOT<br>
Last updated 2023-03-23 01:22:29 +0900
Last updated 2023-03-23 13:41:06 +0900
</div>
</div>
</body>
Expand Down
Loading