From 3f8cc3c08a8ff32ec8080ffec35d9f13dd545a56 Mon Sep 17 00:00:00 2001 From: Jeongmin39 Date: Thu, 18 Jan 2024 16:01:17 +0900 Subject: [PATCH 1/5] =?UTF-8?q?[Feat]=20Comment=20=EB=8F=84=EB=A9=94?= =?UTF-8?q?=EC=9D=B8=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/comment/domain/Comment.java | 31 ++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/ttubeog/domain/comment/domain/Comment.java b/src/main/java/com/ttubeog/domain/comment/domain/Comment.java index 8a25efcc..7d0a7dd7 100644 --- a/src/main/java/com/ttubeog/domain/comment/domain/Comment.java +++ b/src/main/java/com/ttubeog/domain/comment/domain/Comment.java @@ -1,15 +1,38 @@ package com.ttubeog.domain.comment.domain; import com.ttubeog.domain.common.BaseEntity; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; +import com.ttubeog.domain.member.domain.Member; +import jakarta.persistence.*; +import lombok.*; @Entity +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@Table(name = "comment") public class Comment extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; + + @Column(name = "content") + private String content; + + @Column(name = "latitude") + private Float latitude; + + @Column(name = "longitude") + private Float longitude; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "member_id") + private Member member; + + @Builder + public Comment(Long id, String content, Float latitude, Float longitude) { + this.id = id; + this.content = content; + this.latitude = latitude; + this.longitude = longitude; + } } From 915760d69dda3ff6b2d8ff5f020ec6100cc795e5 Mon Sep 17 00:00:00 2001 From: Jeongmin39 Date: Thu, 18 Jan 2024 17:42:21 +0900 Subject: [PATCH 2/5] =?UTF-8?q?[Feat]=20Comment=20=EC=9E=91=EC=84=B1=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../comment/application/CommentService.java | 49 +++++++++++++++++++ .../domain/comment/domain/Comment.java | 10 +--- .../comment/dto/request/CommentWriteReq.java | 16 ++++++ .../comment/dto/response/CommentWriteRes.java | 33 +++++++++++++ .../presentation/CommentController.java | 38 ++++++++++++++ 5 files changed, 138 insertions(+), 8 deletions(-) create mode 100644 src/main/java/com/ttubeog/domain/comment/dto/request/CommentWriteReq.java create mode 100644 src/main/java/com/ttubeog/domain/comment/dto/response/CommentWriteRes.java diff --git a/src/main/java/com/ttubeog/domain/comment/application/CommentService.java b/src/main/java/com/ttubeog/domain/comment/application/CommentService.java index 76ea8a0b..c049bd7b 100644 --- a/src/main/java/com/ttubeog/domain/comment/application/CommentService.java +++ b/src/main/java/com/ttubeog/domain/comment/application/CommentService.java @@ -1,11 +1,60 @@ package com.ttubeog.domain.comment.application; +import com.ttubeog.domain.comment.domain.Comment; +import com.ttubeog.domain.comment.domain.repository.CommentRepository; +import com.ttubeog.domain.comment.dto.request.CommentWriteReq; +import com.ttubeog.domain.comment.dto.response.CommentWriteRes; +import com.ttubeog.domain.member.domain.Member; +import com.ttubeog.domain.member.domain.repository.MemberRepository; +import com.ttubeog.global.DefaultAssert; +import com.ttubeog.global.config.security.token.UserPrincipal; +import com.ttubeog.global.payload.ApiResponse; import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.Optional; + @RequiredArgsConstructor @Service @Transactional(readOnly = true) public class CommentService { + + private final CommentRepository commentRepository; + private final MemberRepository memberRepository; + + // 댓글 작성 + @Transactional + public ResponseEntity writeComment(UserPrincipal userPrincipal, CommentWriteReq commentWriteReq) { + + Optional optionalMember = memberRepository.findById(userPrincipal.getId()); + DefaultAssert.isOptionalPresent(optionalMember); + Member member = optionalMember.get(); + + Comment comment = Comment.builder() + .content(commentWriteReq.getContent()) + .latitude(commentWriteReq.getLatitude()) + .longitude(commentWriteReq.getLongitude()) + .member(member) + .build(); + + commentRepository.save(comment); + + CommentWriteRes commentWriteRes = CommentWriteRes.builder() + .commentId(comment.getId()) + .memberId(member.getId()) + .content(comment.getContent()) + .latitude(comment.getLatitude()) + .longitude(comment.getLongitude()) + .build(); + + ApiResponse apiResponse = ApiResponse.builder() + .check(true) + .information(commentWriteRes) + .build(); + + return ResponseEntity.ok(apiResponse); + } + } diff --git a/src/main/java/com/ttubeog/domain/comment/domain/Comment.java b/src/main/java/com/ttubeog/domain/comment/domain/Comment.java index 7d0a7dd7..f83a073c 100644 --- a/src/main/java/com/ttubeog/domain/comment/domain/Comment.java +++ b/src/main/java/com/ttubeog/domain/comment/domain/Comment.java @@ -7,7 +7,9 @@ @Entity @Getter +@Builder @NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor @Table(name = "comment") public class Comment extends BaseEntity { @@ -27,12 +29,4 @@ public class Comment extends BaseEntity { @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "member_id") private Member member; - - @Builder - public Comment(Long id, String content, Float latitude, Float longitude) { - this.id = id; - this.content = content; - this.latitude = latitude; - this.longitude = longitude; - } } diff --git a/src/main/java/com/ttubeog/domain/comment/dto/request/CommentWriteReq.java b/src/main/java/com/ttubeog/domain/comment/dto/request/CommentWriteReq.java new file mode 100644 index 00000000..2987795a --- /dev/null +++ b/src/main/java/com/ttubeog/domain/comment/dto/request/CommentWriteReq.java @@ -0,0 +1,16 @@ +package com.ttubeog.domain.comment.dto.request; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Data +@Schema(description = "댓글 작성 Request") +public class CommentWriteReq { + + @Schema(description = "댓글 내용") + private String content; + @Schema(description = "위도") + private Float latitude; + @Schema(description = "경도") + private Float longitude; +} diff --git a/src/main/java/com/ttubeog/domain/comment/dto/response/CommentWriteRes.java b/src/main/java/com/ttubeog/domain/comment/dto/response/CommentWriteRes.java new file mode 100644 index 00000000..6c62b592 --- /dev/null +++ b/src/main/java/com/ttubeog/domain/comment/dto/response/CommentWriteRes.java @@ -0,0 +1,33 @@ +package com.ttubeog.domain.comment.dto.response; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Builder; +import lombok.Data; + +@Data +public class CommentWriteRes { + + @Schema(description = "댓글 ID") + private Long commentId; + + @Schema(description = "작성자 ID") + private Long memberId; + + @Schema(description = "내용") + private String content; + + @Schema(description = "위도") + private Float latitude; + + @Schema(description = "경도") + private Float longitude; + + @Builder + public CommentWriteRes(Long commentId, Long memberId, String content, Float latitude, Float longitude) { + this.commentId = commentId; + this.memberId = memberId; + this.content = content; + this.latitude = latitude; + this.longitude = longitude; + } +} diff --git a/src/main/java/com/ttubeog/domain/comment/presentation/CommentController.java b/src/main/java/com/ttubeog/domain/comment/presentation/CommentController.java index b2f17b3f..76a91abd 100644 --- a/src/main/java/com/ttubeog/domain/comment/presentation/CommentController.java +++ b/src/main/java/com/ttubeog/domain/comment/presentation/CommentController.java @@ -1,7 +1,45 @@ package com.ttubeog.domain.comment.presentation; +import com.ttubeog.domain.comment.application.CommentService; +import com.ttubeog.domain.comment.dto.request.CommentWriteReq; +import com.ttubeog.domain.comment.dto.response.CommentWriteRes; +import com.ttubeog.global.config.security.token.CurrentUser; +import com.ttubeog.global.config.security.token.UserPrincipal; +import com.ttubeog.global.payload.ErrorResponse; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.validation.Valid; +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +@Tag(name = "Comment", description = "Comment API") @RestController +@RequiredArgsConstructor +@RequestMapping("/api/v1/comment") public class CommentController { + + private final CommentService commentService; + @Operation(summary = "댓글 작성", description = "댓글을 작성합니다.") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "댓글 작성 성공", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = CommentWriteRes.class) ) } ), + @ApiResponse(responseCode = "400", description = "댓글 작성 실패", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class) ) } ) + }) + @PostMapping + public ResponseEntity writeComment( + @Parameter(description = "AccessToken을 입력해주세요.", required = true) @CurrentUser UserPrincipal userPrincipal, + @Valid @RequestBody CommentWriteReq commentWriteReq + ) { + return commentService.writeComment(userPrincipal, commentWriteReq); + } + + } From 723143a5ee98e91ff4ebb21d0375159806157121 Mon Sep 17 00:00:00 2001 From: Jeongmin39 Date: Thu, 18 Jan 2024 18:43:23 +0900 Subject: [PATCH 3/5] =?UTF-8?q?[Feat]=20Comment=20=EC=88=98=EC=A0=95=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../comment/application/CommentService.java | 32 +++++++++++++++++++ .../domain/comment/domain/Comment.java | 4 +++ .../comment/dto/request/CommentUpdateReq.java | 14 ++++++++ .../dto/response/CommentUpdateRes.java | 21 ++++++++++++ .../presentation/CommentController.java | 25 ++++++++++++--- 5 files changed, 92 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/ttubeog/domain/comment/dto/request/CommentUpdateReq.java create mode 100644 src/main/java/com/ttubeog/domain/comment/dto/response/CommentUpdateRes.java diff --git a/src/main/java/com/ttubeog/domain/comment/application/CommentService.java b/src/main/java/com/ttubeog/domain/comment/application/CommentService.java index c049bd7b..af2def9f 100644 --- a/src/main/java/com/ttubeog/domain/comment/application/CommentService.java +++ b/src/main/java/com/ttubeog/domain/comment/application/CommentService.java @@ -2,12 +2,15 @@ import com.ttubeog.domain.comment.domain.Comment; import com.ttubeog.domain.comment.domain.repository.CommentRepository; +import com.ttubeog.domain.comment.dto.request.CommentUpdateReq; import com.ttubeog.domain.comment.dto.request.CommentWriteReq; +import com.ttubeog.domain.comment.dto.response.CommentUpdateRes; import com.ttubeog.domain.comment.dto.response.CommentWriteRes; import com.ttubeog.domain.member.domain.Member; import com.ttubeog.domain.member.domain.repository.MemberRepository; import com.ttubeog.global.DefaultAssert; import com.ttubeog.global.config.security.token.UserPrincipal; +import com.ttubeog.global.error.DefaultException; import com.ttubeog.global.payload.ApiResponse; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; @@ -57,4 +60,33 @@ public ResponseEntity writeComment(UserPrincipal userPrincipal, CommentWriteR return ResponseEntity.ok(apiResponse); } + // 댓글 수정 + @Transactional + public ResponseEntity updateComment(UserPrincipal userPrincipal, CommentUpdateReq commentUpdateReq) { + + Optional optionalMember = memberRepository.findById(userPrincipal.getId()); + DefaultAssert.isOptionalPresent(optionalMember); + + Optional optionalComment = commentRepository.findById(commentUpdateReq.getCommentId()); + DefaultAssert.isOptionalPresent(optionalComment); + Comment comment = optionalComment.get(); + + Member commentWriter = comment.getMember(); + if (commentWriter.getId() != optionalMember.get().getId()) { + DefaultAssert.isTrue(true, "해당 댓글의 작성자만 수정할 수 있습니다."); + } + + comment.updateContent(commentUpdateReq.getContent()); + CommentUpdateRes commentUpdateRes = CommentUpdateRes.builder() + .commentId(comment.getId()) + .content(comment.getContent()) + .build(); + + ApiResponse apiResponse = ApiResponse.builder() + .check(true) + .information(commentUpdateRes) + .build(); + + return ResponseEntity.ok(apiResponse); + } } diff --git a/src/main/java/com/ttubeog/domain/comment/domain/Comment.java b/src/main/java/com/ttubeog/domain/comment/domain/Comment.java index f83a073c..6d4f8c01 100644 --- a/src/main/java/com/ttubeog/domain/comment/domain/Comment.java +++ b/src/main/java/com/ttubeog/domain/comment/domain/Comment.java @@ -29,4 +29,8 @@ public class Comment extends BaseEntity { @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "member_id") private Member member; + + public void updateContent(String content) { + this.content = content; + } } diff --git a/src/main/java/com/ttubeog/domain/comment/dto/request/CommentUpdateReq.java b/src/main/java/com/ttubeog/domain/comment/dto/request/CommentUpdateReq.java new file mode 100644 index 00000000..95e1fdef --- /dev/null +++ b/src/main/java/com/ttubeog/domain/comment/dto/request/CommentUpdateReq.java @@ -0,0 +1,14 @@ +package com.ttubeog.domain.comment.dto.request; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Data +public class CommentUpdateReq { + + @Schema(description = "댓글 ID") + private Long commentId; + + @Schema(description = "댓글 내용") + private String content; +} diff --git a/src/main/java/com/ttubeog/domain/comment/dto/response/CommentUpdateRes.java b/src/main/java/com/ttubeog/domain/comment/dto/response/CommentUpdateRes.java new file mode 100644 index 00000000..30e95954 --- /dev/null +++ b/src/main/java/com/ttubeog/domain/comment/dto/response/CommentUpdateRes.java @@ -0,0 +1,21 @@ +package com.ttubeog.domain.comment.dto.response; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Builder; +import lombok.Data; + +@Data +public class CommentUpdateRes { + + @Schema(description = "댓글 ID") + private Long commentId; + + @Schema(description = "내용") + private String content; + + @Builder + public CommentUpdateRes(Long commentId, String content) { + this.commentId = commentId; + this.content = content; + } +} diff --git a/src/main/java/com/ttubeog/domain/comment/presentation/CommentController.java b/src/main/java/com/ttubeog/domain/comment/presentation/CommentController.java index 76a91abd..6408ebfd 100644 --- a/src/main/java/com/ttubeog/domain/comment/presentation/CommentController.java +++ b/src/main/java/com/ttubeog/domain/comment/presentation/CommentController.java @@ -1,7 +1,9 @@ package com.ttubeog.domain.comment.presentation; import com.ttubeog.domain.comment.application.CommentService; +import com.ttubeog.domain.comment.dto.request.CommentUpdateReq; import com.ttubeog.domain.comment.dto.request.CommentWriteReq; +import com.ttubeog.domain.comment.dto.response.CommentUpdateRes; import com.ttubeog.domain.comment.dto.response.CommentWriteRes; import com.ttubeog.global.config.security.token.CurrentUser; import com.ttubeog.global.config.security.token.UserPrincipal; @@ -16,10 +18,7 @@ import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.PostMapping; -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.*; @Tag(name = "Comment", description = "Comment API") @RestController @@ -28,6 +27,8 @@ public class CommentController { private final CommentService commentService; + + // 댓글 작성 @Operation(summary = "댓글 작성", description = "댓글을 작성합니다.") @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "댓글 작성 성공", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = CommentWriteRes.class) ) } ), @@ -41,5 +42,21 @@ public ResponseEntity writeComment( return commentService.writeComment(userPrincipal, commentWriteReq); } + // 댓글 수정 + @Operation(summary = "댓글 수정", description = "댓글 내용을 수정합니다.") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "댓글 수정 성공", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = CommentUpdateRes.class) ) } ), + @ApiResponse(responseCode = "400", description = "댓글 수정 실패", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class) ) } ) + }) + @PatchMapping + public ResponseEntity updateComment( + @Parameter(description = "AccessToken을 입력해주세요.", required = true) @CurrentUser UserPrincipal userPrincipal, + @Valid @RequestBody CommentUpdateReq commentUpdateReq + ) { + return commentService.updateComment(userPrincipal, commentUpdateReq); + } + + // 댓글 삭제 + } From b046e88d50113365d1eaa57dcb41e64d0d12067f Mon Sep 17 00:00:00 2001 From: Jeongmin39 Date: Thu, 18 Jan 2024 18:54:25 +0900 Subject: [PATCH 4/5] =?UTF-8?q?[Feat]=20Comment=20=EC=82=AD=EC=A0=9C=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../comment/application/CommentService.java | 22 +++++++++++++++++++ .../presentation/CommentController.java | 15 +++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/ttubeog/domain/comment/application/CommentService.java b/src/main/java/com/ttubeog/domain/comment/application/CommentService.java index af2def9f..708c1859 100644 --- a/src/main/java/com/ttubeog/domain/comment/application/CommentService.java +++ b/src/main/java/com/ttubeog/domain/comment/application/CommentService.java @@ -12,6 +12,7 @@ import com.ttubeog.global.config.security.token.UserPrincipal; import com.ttubeog.global.error.DefaultException; import com.ttubeog.global.payload.ApiResponse; +import com.ttubeog.global.payload.Message; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; @@ -89,4 +90,25 @@ public ResponseEntity updateComment(UserPrincipal userPrincipal, CommentUpdat return ResponseEntity.ok(apiResponse); } + + // 댓글 삭제 + @Transactional + public ResponseEntity deleteComment(UserPrincipal userPrincipal, Long commentId) { + + Optional optionalMember = memberRepository.findById(userPrincipal.getId()); + DefaultAssert.isOptionalPresent(optionalMember); + + Optional optionalComment = commentRepository.findById(commentId); + DefaultAssert.isOptionalPresent(optionalComment); + Comment comment = optionalComment.get(); + + commentRepository.delete(comment); + + ApiResponse apiResponse = ApiResponse.builder() + .check(true) + .information(Message.builder().message("댓글이 정상적으로 삭제되었습니다.").build()) + .build(); + + return ResponseEntity.ok(apiResponse); + } } diff --git a/src/main/java/com/ttubeog/domain/comment/presentation/CommentController.java b/src/main/java/com/ttubeog/domain/comment/presentation/CommentController.java index 6408ebfd..a3b1e758 100644 --- a/src/main/java/com/ttubeog/domain/comment/presentation/CommentController.java +++ b/src/main/java/com/ttubeog/domain/comment/presentation/CommentController.java @@ -8,6 +8,7 @@ import com.ttubeog.global.config.security.token.CurrentUser; import com.ttubeog.global.config.security.token.UserPrincipal; import com.ttubeog.global.payload.ErrorResponse; +import com.ttubeog.global.payload.Message; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.media.Content; @@ -57,6 +58,16 @@ public ResponseEntity updateComment( } // 댓글 삭제 - - + @Operation(summary = "댓글 삭제", description = "댓글을 삭제합니다.") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "댓글 삭제 성공", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = Message.class) ) } ), + @ApiResponse(responseCode = "400", description = "댓글 삭제 실패", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class) ) } ) + }) + @DeleteMapping("/{commentId}") + public ResponseEntity deleteComment( + @Parameter(description = "AccessToken을 입력해주세요.", required = true) @CurrentUser UserPrincipal userPrincipal, + @PathVariable Long commentId + ) { + return commentService.deleteComment(userPrincipal, commentId); + } } From 68dc9745c8ab97e6324975b32d339f0273bad1f1 Mon Sep 17 00:00:00 2001 From: Jeongmin39 Date: Fri, 19 Jan 2024 11:31:33 +0900 Subject: [PATCH 5/5] =?UTF-8?q?[Chore]=20=EB=B3=80=EC=88=98=EB=AA=85=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../comment/application/CommentService.java | 60 ++++++++++--------- ...ntUpdateReq.java => UpdateCommentReq.java} | 2 +- ...mentWriteReq.java => WriteCommentReq.java} | 2 +- ...ntUpdateRes.java => UpdateCommentRes.java} | 4 +- ...mentWriteRes.java => WriteCommentRes.java} | 4 +- .../presentation/CommentController.java | 22 +++---- 6 files changed, 49 insertions(+), 45 deletions(-) rename src/main/java/com/ttubeog/domain/comment/dto/request/{CommentUpdateReq.java => UpdateCommentReq.java} (89%) rename src/main/java/com/ttubeog/domain/comment/dto/request/{CommentWriteReq.java => WriteCommentReq.java} (92%) rename src/main/java/com/ttubeog/domain/comment/dto/response/{CommentUpdateRes.java => UpdateCommentRes.java} (79%) rename src/main/java/com/ttubeog/domain/comment/dto/response/{CommentWriteRes.java => WriteCommentRes.java} (88%) diff --git a/src/main/java/com/ttubeog/domain/comment/application/CommentService.java b/src/main/java/com/ttubeog/domain/comment/application/CommentService.java index 708c1859..367e2fef 100644 --- a/src/main/java/com/ttubeog/domain/comment/application/CommentService.java +++ b/src/main/java/com/ttubeog/domain/comment/application/CommentService.java @@ -2,15 +2,14 @@ import com.ttubeog.domain.comment.domain.Comment; import com.ttubeog.domain.comment.domain.repository.CommentRepository; -import com.ttubeog.domain.comment.dto.request.CommentUpdateReq; -import com.ttubeog.domain.comment.dto.request.CommentWriteReq; -import com.ttubeog.domain.comment.dto.response.CommentUpdateRes; -import com.ttubeog.domain.comment.dto.response.CommentWriteRes; +import com.ttubeog.domain.comment.dto.request.UpdateCommentReq; +import com.ttubeog.domain.comment.dto.request.WriteCommentReq; +import com.ttubeog.domain.comment.dto.response.UpdateCommentRes; +import com.ttubeog.domain.comment.dto.response.WriteCommentRes; import com.ttubeog.domain.member.domain.Member; import com.ttubeog.domain.member.domain.repository.MemberRepository; import com.ttubeog.global.DefaultAssert; import com.ttubeog.global.config.security.token.UserPrincipal; -import com.ttubeog.global.error.DefaultException; import com.ttubeog.global.payload.ApiResponse; import com.ttubeog.global.payload.Message; import lombok.RequiredArgsConstructor; @@ -30,22 +29,22 @@ public class CommentService { // 댓글 작성 @Transactional - public ResponseEntity writeComment(UserPrincipal userPrincipal, CommentWriteReq commentWriteReq) { + public ResponseEntity writeComment(UserPrincipal userPrincipal, WriteCommentReq writeCommentReq) { - Optional optionalMember = memberRepository.findById(userPrincipal.getId()); - DefaultAssert.isOptionalPresent(optionalMember); - Member member = optionalMember.get(); + Optional memberOptional = memberRepository.findById(userPrincipal.getId()); + DefaultAssert.isOptionalPresent(memberOptional); + Member member = memberOptional.get(); Comment comment = Comment.builder() - .content(commentWriteReq.getContent()) - .latitude(commentWriteReq.getLatitude()) - .longitude(commentWriteReq.getLongitude()) + .content(writeCommentReq.getContent()) + .latitude(writeCommentReq.getLatitude()) + .longitude(writeCommentReq.getLongitude()) .member(member) .build(); commentRepository.save(comment); - CommentWriteRes commentWriteRes = CommentWriteRes.builder() + WriteCommentRes writeCommentRes = WriteCommentRes.builder() .commentId(comment.getId()) .memberId(member.getId()) .content(comment.getContent()) @@ -55,7 +54,7 @@ public ResponseEntity writeComment(UserPrincipal userPrincipal, CommentWriteR ApiResponse apiResponse = ApiResponse.builder() .check(true) - .information(commentWriteRes) + .information(writeCommentRes) .build(); return ResponseEntity.ok(apiResponse); @@ -63,29 +62,29 @@ public ResponseEntity writeComment(UserPrincipal userPrincipal, CommentWriteR // 댓글 수정 @Transactional - public ResponseEntity updateComment(UserPrincipal userPrincipal, CommentUpdateReq commentUpdateReq) { + public ResponseEntity updateComment(UserPrincipal userPrincipal, UpdateCommentReq updateCommentReq) { - Optional optionalMember = memberRepository.findById(userPrincipal.getId()); - DefaultAssert.isOptionalPresent(optionalMember); + Optional memberOptional = memberRepository.findById(userPrincipal.getId()); + DefaultAssert.isOptionalPresent(memberOptional); - Optional optionalComment = commentRepository.findById(commentUpdateReq.getCommentId()); - DefaultAssert.isOptionalPresent(optionalComment); - Comment comment = optionalComment.get(); + Optional commentOptional = commentRepository.findById(updateCommentReq.getCommentId()); + DefaultAssert.isOptionalPresent(commentOptional); + Comment comment = commentOptional.get(); Member commentWriter = comment.getMember(); - if (commentWriter.getId() != optionalMember.get().getId()) { + if (commentWriter.getId() != memberOptional.get().getId()) { DefaultAssert.isTrue(true, "해당 댓글의 작성자만 수정할 수 있습니다."); } - comment.updateContent(commentUpdateReq.getContent()); - CommentUpdateRes commentUpdateRes = CommentUpdateRes.builder() + comment.updateContent(updateCommentReq.getContent()); + UpdateCommentRes updateCommentRes = UpdateCommentRes.builder() .commentId(comment.getId()) .content(comment.getContent()) .build(); ApiResponse apiResponse = ApiResponse.builder() .check(true) - .information(commentUpdateRes) + .information(updateCommentRes) .build(); return ResponseEntity.ok(apiResponse); @@ -95,12 +94,12 @@ public ResponseEntity updateComment(UserPrincipal userPrincipal, CommentUpdat @Transactional public ResponseEntity deleteComment(UserPrincipal userPrincipal, Long commentId) { - Optional optionalMember = memberRepository.findById(userPrincipal.getId()); - DefaultAssert.isOptionalPresent(optionalMember); + Optional memberOptional = memberRepository.findById(userPrincipal.getId()); + DefaultAssert.isOptionalPresent(memberOptional); - Optional optionalComment = commentRepository.findById(commentId); - DefaultAssert.isOptionalPresent(optionalComment); - Comment comment = optionalComment.get(); + Optional commentOptional = commentRepository.findById(commentId); + DefaultAssert.isOptionalPresent(commentOptional); + Comment comment = commentOptional.get(); commentRepository.delete(comment); @@ -111,4 +110,7 @@ public ResponseEntity deleteComment(UserPrincipal userPrincipal, Long comment return ResponseEntity.ok(apiResponse); } + + // 댓글 조회 + } diff --git a/src/main/java/com/ttubeog/domain/comment/dto/request/CommentUpdateReq.java b/src/main/java/com/ttubeog/domain/comment/dto/request/UpdateCommentReq.java similarity index 89% rename from src/main/java/com/ttubeog/domain/comment/dto/request/CommentUpdateReq.java rename to src/main/java/com/ttubeog/domain/comment/dto/request/UpdateCommentReq.java index 95e1fdef..2f3a39ab 100644 --- a/src/main/java/com/ttubeog/domain/comment/dto/request/CommentUpdateReq.java +++ b/src/main/java/com/ttubeog/domain/comment/dto/request/UpdateCommentReq.java @@ -4,7 +4,7 @@ import lombok.Data; @Data -public class CommentUpdateReq { +public class UpdateCommentReq { @Schema(description = "댓글 ID") private Long commentId; diff --git a/src/main/java/com/ttubeog/domain/comment/dto/request/CommentWriteReq.java b/src/main/java/com/ttubeog/domain/comment/dto/request/WriteCommentReq.java similarity index 92% rename from src/main/java/com/ttubeog/domain/comment/dto/request/CommentWriteReq.java rename to src/main/java/com/ttubeog/domain/comment/dto/request/WriteCommentReq.java index 2987795a..d0541d7f 100644 --- a/src/main/java/com/ttubeog/domain/comment/dto/request/CommentWriteReq.java +++ b/src/main/java/com/ttubeog/domain/comment/dto/request/WriteCommentReq.java @@ -5,7 +5,7 @@ @Data @Schema(description = "댓글 작성 Request") -public class CommentWriteReq { +public class WriteCommentReq { @Schema(description = "댓글 내용") private String content; diff --git a/src/main/java/com/ttubeog/domain/comment/dto/response/CommentUpdateRes.java b/src/main/java/com/ttubeog/domain/comment/dto/response/UpdateCommentRes.java similarity index 79% rename from src/main/java/com/ttubeog/domain/comment/dto/response/CommentUpdateRes.java rename to src/main/java/com/ttubeog/domain/comment/dto/response/UpdateCommentRes.java index 30e95954..7fafb00c 100644 --- a/src/main/java/com/ttubeog/domain/comment/dto/response/CommentUpdateRes.java +++ b/src/main/java/com/ttubeog/domain/comment/dto/response/UpdateCommentRes.java @@ -5,7 +5,7 @@ import lombok.Data; @Data -public class CommentUpdateRes { +public class UpdateCommentRes { @Schema(description = "댓글 ID") private Long commentId; @@ -14,7 +14,7 @@ public class CommentUpdateRes { private String content; @Builder - public CommentUpdateRes(Long commentId, String content) { + public UpdateCommentRes(Long commentId, String content) { this.commentId = commentId; this.content = content; } diff --git a/src/main/java/com/ttubeog/domain/comment/dto/response/CommentWriteRes.java b/src/main/java/com/ttubeog/domain/comment/dto/response/WriteCommentRes.java similarity index 88% rename from src/main/java/com/ttubeog/domain/comment/dto/response/CommentWriteRes.java rename to src/main/java/com/ttubeog/domain/comment/dto/response/WriteCommentRes.java index 6c62b592..a3b78a19 100644 --- a/src/main/java/com/ttubeog/domain/comment/dto/response/CommentWriteRes.java +++ b/src/main/java/com/ttubeog/domain/comment/dto/response/WriteCommentRes.java @@ -5,7 +5,7 @@ import lombok.Data; @Data -public class CommentWriteRes { +public class WriteCommentRes { @Schema(description = "댓글 ID") private Long commentId; @@ -23,7 +23,7 @@ public class CommentWriteRes { private Float longitude; @Builder - public CommentWriteRes(Long commentId, Long memberId, String content, Float latitude, Float longitude) { + public WriteCommentRes(Long commentId, Long memberId, String content, Float latitude, Float longitude) { this.commentId = commentId; this.memberId = memberId; this.content = content; diff --git a/src/main/java/com/ttubeog/domain/comment/presentation/CommentController.java b/src/main/java/com/ttubeog/domain/comment/presentation/CommentController.java index a3b1e758..cfd84fef 100644 --- a/src/main/java/com/ttubeog/domain/comment/presentation/CommentController.java +++ b/src/main/java/com/ttubeog/domain/comment/presentation/CommentController.java @@ -1,10 +1,10 @@ package com.ttubeog.domain.comment.presentation; import com.ttubeog.domain.comment.application.CommentService; -import com.ttubeog.domain.comment.dto.request.CommentUpdateReq; -import com.ttubeog.domain.comment.dto.request.CommentWriteReq; -import com.ttubeog.domain.comment.dto.response.CommentUpdateRes; -import com.ttubeog.domain.comment.dto.response.CommentWriteRes; +import com.ttubeog.domain.comment.dto.request.UpdateCommentReq; +import com.ttubeog.domain.comment.dto.request.WriteCommentReq; +import com.ttubeog.domain.comment.dto.response.UpdateCommentRes; +import com.ttubeog.domain.comment.dto.response.WriteCommentRes; import com.ttubeog.global.config.security.token.CurrentUser; import com.ttubeog.global.config.security.token.UserPrincipal; import com.ttubeog.global.payload.ErrorResponse; @@ -32,29 +32,29 @@ public class CommentController { // 댓글 작성 @Operation(summary = "댓글 작성", description = "댓글을 작성합니다.") @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "댓글 작성 성공", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = CommentWriteRes.class) ) } ), + @ApiResponse(responseCode = "200", description = "댓글 작성 성공", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = WriteCommentRes.class) ) } ), @ApiResponse(responseCode = "400", description = "댓글 작성 실패", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class) ) } ) }) @PostMapping public ResponseEntity writeComment( @Parameter(description = "AccessToken을 입력해주세요.", required = true) @CurrentUser UserPrincipal userPrincipal, - @Valid @RequestBody CommentWriteReq commentWriteReq + @Valid @RequestBody WriteCommentReq writeCommentReq ) { - return commentService.writeComment(userPrincipal, commentWriteReq); + return commentService.writeComment(userPrincipal, writeCommentReq); } // 댓글 수정 @Operation(summary = "댓글 수정", description = "댓글 내용을 수정합니다.") @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "댓글 수정 성공", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = CommentUpdateRes.class) ) } ), + @ApiResponse(responseCode = "200", description = "댓글 수정 성공", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = UpdateCommentRes.class) ) } ), @ApiResponse(responseCode = "400", description = "댓글 수정 실패", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class) ) } ) }) @PatchMapping public ResponseEntity updateComment( @Parameter(description = "AccessToken을 입력해주세요.", required = true) @CurrentUser UserPrincipal userPrincipal, - @Valid @RequestBody CommentUpdateReq commentUpdateReq + @Valid @RequestBody UpdateCommentReq updateCommentReq ) { - return commentService.updateComment(userPrincipal, commentUpdateReq); + return commentService.updateComment(userPrincipal, updateCommentReq); } // 댓글 삭제 @@ -70,4 +70,6 @@ public ResponseEntity deleteComment( ) { return commentService.deleteComment(userPrincipal, commentId); } + + // 댓글 조회 }