Files
YouAndMe/src/main/java/com/yam/app/comment/presentation/CommentCommandApi.java
JiwonDev a9d7523f10 Refactor Code
- Runtime Exception을 IllegalStateException으로 변경
- apache.commons.lang3 의존성 추가
- 문자열 테스트에서 apache.commons.lang3.RandomStringUtils 를 사용하도록 변경
2021-10-11 12:14:27 +09:00

66 lines
2.2 KiB
Java

package com.yam.app.comment.presentation;
import com.yam.app.comment.application.CommentFacade;
import com.yam.app.common.Authentication;
import com.yam.app.common.AuthenticationPrincipal;
import java.net.URI;
import javax.validation.Valid;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
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;
@RestController
@RequestMapping(
produces = MediaType.APPLICATION_JSON_VALUE,
consumes = MediaType.APPLICATION_JSON_VALUE
)
public final class CommentCommandApi {
private final CommentFacade commentFacade;
public CommentCommandApi(CommentFacade commentFacade) {
this.commentFacade = commentFacade;
}
@PostMapping("/api/comments/")
public ResponseEntity<Void> createComment(
@RequestBody @Valid CreateCommentCommand request,
@AuthenticationPrincipal Authentication authentication) {
final Long commentId = commentFacade.create(request, authentication.getMemberId());
return ResponseEntity
.created(URI.create("/comments/" + commentId))
.build();
}
@PatchMapping("api/comments/{commentId}")
public ResponseEntity<Void> updateComment(
@PathVariable Long commentId,
@RequestBody @Valid UpdateCommentCommand request,
@AuthenticationPrincipal Authentication authentication) {
commentFacade.update(request, commentId, authentication.getMemberId());
return ResponseEntity.ok().build();
}
@DeleteMapping("api/comments/{commentId}")
public ResponseEntity<Void> deleteComment(
@PathVariable Long commentId,
@AuthenticationPrincipal Authentication authentication) {
commentFacade.delete(commentId, authentication.getMemberId());
return ResponseEntity.ok().build();
}
}