-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
308 additions
and
22 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
module-api/src/main/java/com/mile/controller/comment/CommentController.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,30 @@ | ||
package com.mile.controller.comment; | ||
|
||
|
||
import com.mile.comment.service.CommentService; | ||
import com.mile.dto.SuccessResponse; | ||
import com.mile.exception.message.SuccessMessage; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.security.Principal; | ||
|
||
@RestController | ||
@RequestMapping("/api/comment") | ||
@RequiredArgsConstructor | ||
public class CommentController implements CommentControllerSwagger{ | ||
|
||
private final CommentService commentService; | ||
|
||
@DeleteMapping("/{commentId}") | ||
public SuccessResponse deleteComment( | ||
@PathVariable final Long commentId, | ||
final Principal principal | ||
) { | ||
commentService.deleteComment(commentId, Long.valueOf(principal.getName())); | ||
return SuccessResponse.of(SuccessMessage.COMMENT_DELETE_SUCCESS); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
module-api/src/main/java/com/mile/controller/comment/CommentControllerSwagger.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,34 @@ | ||
package com.mile.controller.comment; | ||
|
||
import com.mile.dto.ErrorResponse; | ||
import com.mile.dto.SuccessResponse; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
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 org.springframework.web.bind.annotation.PathVariable; | ||
|
||
import java.security.Principal; | ||
|
||
@Tag(name = "Comment", description = "댓글 관련 API - 현재는 댓글 삭제만 API 해당") | ||
public interface CommentControllerSwagger { | ||
|
||
@Operation(description = "댓글 삭제 API") | ||
@ApiResponses( | ||
value = { | ||
@ApiResponse(responseCode = "200", description = "댓글 삭제가 완료되었습니다."), | ||
@ApiResponse(responseCode = "403", description = "해당 사용자는 댓글에 접근 권한이 없습니다.", | ||
content = @Content(schema = @Schema(implementation = ErrorResponse.class))), | ||
@ApiResponse(responseCode = "404", description = "해당 댓글이 존재하지 않습니다.", | ||
content = @Content(schema = @Schema(implementation = ErrorResponse.class))), | ||
@ApiResponse(responseCode = "500", description = "서버 내부 오류입니다.", | ||
content = @Content(schema = @Schema(implementation = ErrorResponse.class))) | ||
} | ||
) | ||
SuccessResponse deleteComment( | ||
@PathVariable final Long commentId, | ||
final Principal principal | ||
); | ||
} |
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
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
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
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
28 changes: 28 additions & 0 deletions
28
module-domain/src/main/java/com/mile/comment/service/dto/CommentResponse.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,28 @@ | ||
package com.mile.comment.service.dto; | ||
|
||
import com.mile.comment.domain.Comment; | ||
import com.mile.writerName.domain.WriterName; | ||
|
||
public record CommentResponse( | ||
Long commentId, | ||
String name, | ||
String moimName, | ||
String content, | ||
boolean isMyComment | ||
) { | ||
private final static String ANONYMOUS = "작자미상"; | ||
|
||
public static CommentResponse of( | ||
final Comment comment, | ||
final Long userId | ||
) { | ||
WriterName writerName = comment.getWriterName(); | ||
return new CommentResponse( | ||
comment.getId(), | ||
ANONYMOUS + writerName.getId().toString(), | ||
writerName.getMoim().getName(), | ||
comment.getContent(), | ||
writerName.getId().equals(userId) | ||
); | ||
} | ||
} |
Oops, something went wrong.