feat: 블로그 핵심 기능 구현 (댓글, 태그, 카테고리, 이미지)
[댓글 시스템] - 계층형(대댓글) 구조 및 회원/비회원 하이브리드 작성 로직 구현 - 비회원 댓글용 비밀번호 암호화 저장 (PasswordEncoder 적용) - 관리자용 댓글 강제 삭제 및 전체 댓글 모니터링(Dashboard) API 구현 [태그 & 카테고리] - N:M 태그 시스템(PostTag) 엔티티 설계 및 게시글 작성 시 자동 저장 로직 - 계층형(Tree) 카테고리 구조 구현 및 관리자 생성/삭제 API - QueryDSL 검색 조건에 태그 및 카테고리 필터링 추가 [이미지 업로드] - AWS S3 (MinIO) 연동 및 Bucket 자동 생성/Public 정책 설정 - 마크다운 에디터용 이미지 업로드 API 구현
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
package me.wypark.blogbackend.api.controller
|
||||
|
||||
import me.wypark.blogbackend.api.common.ApiResponse
|
||||
import me.wypark.blogbackend.api.dto.CommentDeleteRequest
|
||||
import me.wypark.blogbackend.api.dto.CommentResponse
|
||||
import me.wypark.blogbackend.api.dto.CommentSaveRequest
|
||||
import me.wypark.blogbackend.domain.comment.CommentService
|
||||
import org.springframework.http.ResponseEntity
|
||||
import org.springframework.security.core.annotation.AuthenticationPrincipal
|
||||
import org.springframework.security.core.userdetails.User
|
||||
import org.springframework.web.bind.annotation.*
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/comments")
|
||||
class CommentController(
|
||||
private val commentService: CommentService
|
||||
) {
|
||||
|
||||
// 댓글 목록 조회
|
||||
@GetMapping
|
||||
fun getComments(@RequestParam postSlug: String): ResponseEntity<ApiResponse<List<CommentResponse>>> {
|
||||
return ResponseEntity.ok(ApiResponse.success(commentService.getComments(postSlug)))
|
||||
}
|
||||
|
||||
// 댓글 작성 (회원 or 비회원)
|
||||
@PostMapping
|
||||
fun createComment(
|
||||
@RequestBody request: CommentSaveRequest,
|
||||
@AuthenticationPrincipal user: User? // 비회원이면 null이 들어옴
|
||||
): ResponseEntity<ApiResponse<Long>> {
|
||||
val email = user?.username // null이면 비회원
|
||||
val commentId = commentService.createComment(request, email)
|
||||
return ResponseEntity.ok(ApiResponse.success(commentId, "댓글이 등록되었습니다."))
|
||||
}
|
||||
|
||||
// 댓글 삭제
|
||||
@DeleteMapping("/{id}")
|
||||
fun deleteComment(
|
||||
@PathVariable id: Long,
|
||||
@RequestBody(required = false) request: CommentDeleteRequest?, // 비회원용 비밀번호 바디
|
||||
@AuthenticationPrincipal user: User?
|
||||
): ResponseEntity<ApiResponse<Nothing>> {
|
||||
val email = user?.username
|
||||
val password = request?.guestPassword
|
||||
|
||||
commentService.deleteComment(id, email, password)
|
||||
return ResponseEntity.ok(ApiResponse.success(message = "댓글이 삭제되었습니다."))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user