-
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 #20 from Alpha-mon/14-feat-board-and-comment
14 feat board and comment
- Loading branch information
Showing
42 changed files
with
1,456 additions
and
155 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
src/main/java/org/ai/roboadvisor/domain/community/controller/BoardController.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,50 @@ | ||
package org.ai.roboadvisor.domain.community.controller; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.ai.roboadvisor.domain.community.dto.response.BoardResponse; | ||
import org.ai.roboadvisor.domain.community.service.BoardService; | ||
import org.ai.roboadvisor.domain.community.swagger_annotation.board.getAllPostsByType.*; | ||
import org.ai.roboadvisor.domain.tendency.entity.Tendency; | ||
import org.ai.roboadvisor.global.common.dto.SuccessApiResponse; | ||
import org.ai.roboadvisor.global.exception.SuccessCode; | ||
import org.ai.roboadvisor.global.swagger_annotation.ApiResponse_Internal_Server_Error; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.domain.Sort; | ||
import org.springframework.data.web.PageableDefault; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.List; | ||
|
||
@Slf4j | ||
@RequiredArgsConstructor | ||
@Tag(name = "community] board", description = "게시글 전체 불러오기 API") | ||
@RestController | ||
@RequestMapping("/api/community/board") | ||
public class BoardController { | ||
|
||
private final BoardService boardService; | ||
|
||
private final int PAGE_SIZE = 10; | ||
|
||
@Operation(summary = "게시글 전체 조회", description = "게시글 전체 불러오기 API") | ||
@getAllPostsByType_OK | ||
@getAllPostsByType_BAD_REQUEST | ||
@ApiResponse_Internal_Server_Error | ||
@GetMapping() | ||
public ResponseEntity<SuccessApiResponse<List<BoardResponse>>> getAllPostsByType( | ||
@RequestParam("tendency") Tendency tendency, @PageableDefault(size = PAGE_SIZE, sort = {"id"}, | ||
direction = Sort.Direction.ASC) Pageable pageable) { | ||
return ResponseEntity.status(HttpStatus.OK) | ||
.body(SuccessApiResponse.success(SuccessCode.BOARD_ALL_VIEW_SUCCESS, | ||
boardService.getAllPostsByType(tendency, pageable))); | ||
} | ||
|
||
} |
69 changes: 69 additions & 0 deletions
69
src/main/java/org/ai/roboadvisor/domain/community/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,69 @@ | ||
package org.ai.roboadvisor.domain.community.controller; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.ai.roboadvisor.domain.community.dto.request.CommentDeleteRequest; | ||
import org.ai.roboadvisor.domain.community.dto.request.CommentRequest; | ||
import org.ai.roboadvisor.domain.community.dto.request.CommentUpdateRequest; | ||
import org.ai.roboadvisor.domain.community.dto.response.CommentResponse; | ||
import org.ai.roboadvisor.domain.community.service.CommentService; | ||
import org.ai.roboadvisor.domain.community.swagger_annotation.comment.delete.*; | ||
import org.ai.roboadvisor.domain.community.swagger_annotation.comment.save.*; | ||
import org.ai.roboadvisor.domain.community.swagger_annotation.comment.update.*; | ||
import org.ai.roboadvisor.global.common.dto.SuccessApiResponse; | ||
import org.ai.roboadvisor.global.exception.SuccessCode; | ||
import org.ai.roboadvisor.global.swagger_annotation.ApiResponse_Internal_Server_Error; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@Slf4j | ||
@RequiredArgsConstructor | ||
@Tag(name = "community] comment", description = "댓글 작성, 수정, 삭제 API") | ||
@RestController | ||
@RequestMapping("/api/community/comment") | ||
public class CommentController { | ||
|
||
private final CommentService commentService; | ||
|
||
@Operation(summary = "댓글 작성", description = "댓글 작성 API") | ||
@save_CREATED | ||
@save_BAD_REQUEST | ||
@save_UNAUTHORIZED | ||
@ApiResponse_Internal_Server_Error | ||
@PostMapping("/{postId}") | ||
public ResponseEntity<SuccessApiResponse<CommentResponse>> save(@PathVariable("postId") Long postId, | ||
@RequestBody CommentRequest commentRequest) { | ||
return ResponseEntity.status(HttpStatus.CREATED) | ||
.body(SuccessApiResponse.success(SuccessCode.COMMENT_CREATED_SUCCESS, | ||
commentService.save(postId, commentRequest))); | ||
} | ||
|
||
@Operation(summary = "댓글 수정", description = "댓글 수정 API") | ||
@update_OK | ||
@update_BAD_REQUEST | ||
@update_UNAUTHORIZED | ||
@ApiResponse_Internal_Server_Error | ||
@PutMapping("/{postId}") | ||
public ResponseEntity<SuccessApiResponse<CommentResponse>> update(@PathVariable("postId") Long postId, | ||
@RequestBody CommentUpdateRequest commentUpdateRequest) { | ||
return ResponseEntity.status(HttpStatus.OK) | ||
.body(SuccessApiResponse.success(SuccessCode.COMMENT_UPDATE_SUCCESS, | ||
commentService.update(postId, commentUpdateRequest))); | ||
} | ||
|
||
@Operation(summary = "댓글 삭제", description = "댓글 삭제 API") | ||
@delete_OK | ||
@delete_BAD_REQUEST | ||
@delete_UNAUTHORIZED | ||
@ApiResponse_Internal_Server_Error | ||
@DeleteMapping("/{postId}") | ||
public ResponseEntity<SuccessApiResponse<CommentResponse>> delete(@PathVariable("postId") Long postId, | ||
@RequestBody CommentDeleteRequest commentDeleteRequest) { | ||
return ResponseEntity.status(HttpStatus.OK) | ||
.body(SuccessApiResponse.success(SuccessCode.COMMENT_DELETE_SUCCESS, | ||
commentService.delete(postId, commentDeleteRequest))); | ||
} | ||
} |
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
26 changes: 26 additions & 0 deletions
26
src/main/java/org/ai/roboadvisor/domain/community/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,26 @@ | ||
package org.ai.roboadvisor.domain.community.dto; | ||
|
||
import com.fasterxml.jackson.annotation.JsonFormat; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.ai.roboadvisor.domain.community.entity.Comment; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public class CommentDto { | ||
|
||
private Long id; | ||
private String nickname; | ||
private String content; | ||
|
||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Seoul") | ||
private LocalDateTime createdDateTime; | ||
|
||
public static CommentDto fromComment(Comment comment) { | ||
return new CommentDto(comment.getId(), comment.getNickname(), | ||
comment.getContent(), comment.getCreatedDateTime()); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/org/ai/roboadvisor/domain/community/dto/request/CommentDeleteRequest.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,21 @@ | ||
package org.ai.roboadvisor.domain.community.dto.request; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import javax.validation.constraints.NotBlank; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class CommentDeleteRequest { | ||
|
||
@Schema(description = "댓글 번호", example = "1") | ||
private Long commentId; | ||
|
||
@Schema(description = "사용자의 닉네임", example = "testUser") | ||
@NotBlank | ||
private String nickname; | ||
} |
Oops, something went wrong.