-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from jwpark1211/develop
Develop
- Loading branch information
Showing
21 changed files
with
544 additions
and
60 deletions.
There are no files selected for viewing
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
126 changes: 126 additions & 0 deletions
126
src/main/java/capstone/bookitty/domain/controller/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,126 @@ | ||
package capstone.bookitty.domain.controller; | ||
|
||
import capstone.bookitty.domain.dto.ResponseType.BasicResponse; | ||
import capstone.bookitty.domain.dto.ResponseType.ResponseCounter; | ||
import capstone.bookitty.domain.dto.ResponseType.ResponseString; | ||
import capstone.bookitty.domain.service.CommentService; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.domain.Sort; | ||
import org.springframework.data.web.PageableDefault; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import static capstone.bookitty.domain.dto.CommentDTO.*; | ||
|
||
@Tag(name="코멘트", description = "코멘트 관리 api 입니다.") | ||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/comment") | ||
public class CommentController { | ||
|
||
private final CommentService commentService; | ||
|
||
@Operation(summary = "코멘트 생성") | ||
@PostMapping(path = "/new") | ||
public ResponseEntity<? extends BasicResponse> saveComment( | ||
@RequestBody @Valid SaveRequest request | ||
){ | ||
return ResponseEntity.ok() | ||
.body(new ResponseCounter<IdResponse>( | ||
commentService.saveComment(request))); | ||
} | ||
|
||
@Operation(summary = "commentId로 코멘트 가져오기") | ||
@GetMapping(path="/{comment-id}") | ||
public ResponseEntity<? extends BasicResponse> getCommentById( | ||
@PathVariable("comment-id") Long commentId | ||
){ | ||
return ResponseEntity.ok() | ||
.body(new ResponseCounter<InfoResponse>( | ||
commentService.findCommentByCommentId(commentId))); | ||
} | ||
|
||
@Operation(summary = "전체 코멘트 가져오기 / page는 requestParam으로 요청할 수 있습니다. / "+ | ||
"size(한 페이지 당 element 수, default = 10), page(요청하는 페이지, 0부터 시작)") | ||
@GetMapping(path = "/all") | ||
public ResponseEntity<? extends BasicResponse> getAll( | ||
@PageableDefault(size = 10, sort = "createdAt", direction = Sort.Direction.DESC) Pageable pageable | ||
){ | ||
return ResponseEntity.ok() | ||
.body(new ResponseCounter<Page<InfoResponse>>( | ||
commentService.findAllComment(pageable))); | ||
} | ||
|
||
@Operation(summary = "isbn으로 코멘트 리스트 가져오기 / page는 requestParam으로 요청할 수 있습니다. / "+ | ||
"size(한 페이지 당 element 수, default = 10), page(요청하는 페이지, 0부터 시작)") | ||
@GetMapping(path = "/isbn/{isbn}") | ||
public ResponseEntity<? extends BasicResponse> getCommentByISBN( | ||
@PathVariable("isbn") String isbn, | ||
@PageableDefault(size = 10, sort = "createdAt", direction = Sort.Direction.DESC) Pageable pageable | ||
){ | ||
return ResponseEntity.ok() | ||
.body(new ResponseCounter<Page<InfoResponse>>( | ||
commentService.findCommentByIsbn(isbn, pageable))); | ||
} | ||
|
||
@Operation(summary = "memberId로 코멘트 리스트 가져오기 / page는 requestParam으로 요청할 수 있습니다. / "+ | ||
"size(한 페이지 당 element 수, default = 10), page(요청하는 페이지, 0부터 시작)") | ||
@GetMapping(path = "/member/{member-id}") | ||
public ResponseEntity<? extends BasicResponse> getCommentByMemberId( | ||
@PathVariable("member-id") Long memberId, | ||
@PageableDefault(size = 10, sort = "createdAt", direction = Sort.Direction.DESC) Pageable pageable | ||
){ | ||
return ResponseEntity.ok() | ||
.body(new ResponseCounter<Page<InfoResponse>>( | ||
commentService.findCommentByMemberId(memberId, pageable))); | ||
} | ||
|
||
@Operation(summary = "코멘트 수정") | ||
@PatchMapping(path = "/{comment-id}") | ||
public ResponseEntity<? extends BasicResponse> updateComment( | ||
@PathVariable("comment-id") Long commentId, | ||
@RequestBody @Valid UpdateRequest request | ||
){ | ||
commentService.updateComment(commentId, request); | ||
return ResponseEntity.ok() | ||
.body(new ResponseString("update Comment!")); | ||
} | ||
|
||
@Operation(summary = "코멘트 삭제") | ||
@DeleteMapping(path = "/{comment-id}") | ||
public ResponseEntity<? extends BasicResponse> deleteComment( | ||
@PathVariable("comment-id") Long commentId | ||
){ | ||
commentService.deleteComment(commentId); | ||
return ResponseEntity.ok() | ||
.body(new ResponseString("delete Comment!")); | ||
} | ||
|
||
@Operation(summary = "코멘트 좋아요 등록") | ||
@PostMapping(path = "/{comment-id}/member/{member-id}/like/increase") | ||
public ResponseEntity<? extends BasicResponse> increaseLike( | ||
@PathVariable("comment-id") Long commentId, | ||
@PathVariable("member-id") Long memberId | ||
){ | ||
commentService.increaseLike(commentId,memberId); | ||
return ResponseEntity.ok() | ||
.body(new ResponseString("increase Like!")); | ||
} | ||
|
||
@Operation(summary = "코멘트 좋아요 삭제") | ||
@PostMapping(path = "/{comment-id}/member/{member-id}/like/decrease") | ||
public ResponseEntity<? extends BasicResponse> decreaseLike( | ||
@PathVariable("comment-id") Long commentId, | ||
@PathVariable("member-id") Long memberId | ||
){ | ||
commentService.decreaseLike(commentId,memberId); | ||
return ResponseEntity.ok() | ||
.body(new ResponseString("decrease Like!")); | ||
} | ||
|
||
} |
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
67 changes: 67 additions & 0 deletions
67
src/main/java/capstone/bookitty/domain/dto/CommentDTO.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,67 @@ | ||
package capstone.bookitty.domain.dto; | ||
|
||
import capstone.bookitty.domain.entity.Comment; | ||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.NotEmpty; | ||
import jakarta.validation.constraints.NotNull; | ||
import jakarta.validation.constraints.Size; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.springframework.format.annotation.DateTimeFormat; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
public class CommentDTO { | ||
|
||
@Data | ||
public static class SaveRequest{ | ||
@NotBlank(message = "Isbn is a required entry value.") | ||
private String isbn; | ||
@NotNull(message = "memberId is a required entry value.") | ||
private Long memberId; | ||
@NotEmpty(message = "content is a required entry value.") | ||
@Size(min = 1, max = 100, message = "Name must be between 1 and 100 characters") | ||
private String content; | ||
} | ||
|
||
@Data | ||
public static class UpdateRequest{ | ||
@NotEmpty(message = "content is a required entry value.") | ||
@Size(min = 1, max = 100, message = "Name must be between 1 and 100 characters") | ||
private String content; | ||
} | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public static class IdResponse{ | ||
private Long id; | ||
public static IdResponse of(Comment comment){ | ||
return new IdResponse(comment.getId()); | ||
} | ||
} | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public static class InfoResponse{ | ||
private Long id; | ||
private Long memberId; | ||
private String isbn; | ||
private String content; | ||
private int like_count; | ||
@DateTimeFormat(pattern = "yyyy-mm-dd'T'HH:mm:ss") | ||
private LocalDateTime createdAt; | ||
@DateTimeFormat(pattern = "yyyy-mm-dd'T'HH:mm:ss") | ||
private LocalDateTime modifiedAt; | ||
|
||
public static InfoResponse of(Comment comment, int like_count){ | ||
return new InfoResponse(comment.getId(), comment.getMember().getId(),comment.getIsbn(), | ||
comment.getContent(), like_count ,comment.getCreatedAt(), | ||
comment.getModifiedAt()); | ||
} | ||
|
||
} | ||
} |
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
Oops, something went wrong.