-
Notifications
You must be signed in to change notification settings - Fork 2
Sisc1 151 be 게시물목록조회 #70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
The head ref may contain hidden characters: "SISC1-151-BE-\uAC8C\uC2DC\uBB3C\uBAA9\uB85D\uC870\uD68C"
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a794552
SISC1-151-BE-게시물목록조회(공지/일반-분리)
wiggle01 e5e4775
Merge branch 'SISC1-151-BE-게시물목록조회(공지/일반-분리)' into SISC1-151-BE-게시물목록조회
wiggle01 64c6294
Merge branch 'main' of https://github.com/SISC-IT/sisc-web into SISC1…
nayoung04 c784405
[BE][FEAT]게시판 CRUD
nayoung04 91682b9
[BE][FIX]게시판 CRUD
nayoung04 9a666b8
[BE][FIX]resolve conflict
nayoung04 da6cda7
[BE][FEAT]파일 업로드
nayoung04 fa31c1f
[BE][FEAT]게시판 테스트 코드
nayoung04 dbbaa9e
[BE][FEAT]게시판 테스트 코드
nayoung04 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
137 changes: 137 additions & 0 deletions
137
backend/src/main/java/org/sejongisc/backend/board/controller/PostController.java
This file contains hidden or 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,137 @@ | ||
| package org.sejongisc.backend.board.controller; | ||
|
|
||
| import io.swagger.v3.oas.annotations.tags.Tag; | ||
| import jakarta.validation.Valid; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.sejongisc.backend.board.entity.BoardType; | ||
| import org.sejongisc.backend.board.entity.PostType; | ||
| import org.sejongisc.backend.board.dto.*; | ||
| import org.sejongisc.backend.board.service.PostService; | ||
| import org.sejongisc.backend.common.auth.springsecurity.CustomUserDetails; | ||
| import org.springframework.data.domain.Page; | ||
| import org.springframework.http.MediaType; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
| import org.springframework.web.bind.annotation.*; | ||
|
|
||
| import java.util.List; | ||
| import java.util.UUID; | ||
|
|
||
| @RestController | ||
| @RequiredArgsConstructor | ||
| @RequestMapping("/api/post") | ||
| @Tag( | ||
| name = "게시글 및 댓글 API", | ||
| description = "게시글 및 댓글 작성, 수정, 삭제 관련 API 제공" | ||
| ) | ||
| public class PostController { | ||
|
|
||
| private final PostService postService; | ||
|
|
||
| // 게시글 작성 | ||
| @PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE) | ||
| public ResponseEntity<Void> createPost( | ||
| @Valid @ModelAttribute PostRequest request, | ||
| @AuthenticationPrincipal CustomUserDetails customUserDetails) { | ||
| UUID userId = customUserDetails.getUserId(); | ||
| postService.savePost(request, userId); | ||
| return ResponseEntity.ok().build(); | ||
| } | ||
|
|
||
| // 게시글 수정 | ||
| @PutMapping(value = "/{postId}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) | ||
| public ResponseEntity<Void> updatePost( | ||
| @Valid @ModelAttribute PostRequest request, | ||
| @PathVariable UUID postId, | ||
| @AuthenticationPrincipal CustomUserDetails customUserDetails) { | ||
| UUID userId = customUserDetails.getUserId(); | ||
| postService.updatePost(request, postId, userId); | ||
| return ResponseEntity.ok().build(); | ||
| } | ||
|
|
||
| // 게시글 삭제 | ||
| @DeleteMapping("/{postId}") | ||
| public void deletePost( | ||
| @PathVariable UUID postId, | ||
| @AuthenticationPrincipal CustomUserDetails customUserDetails) { | ||
| UUID userId = customUserDetails.getUserId(); | ||
| postService.deletePost(postId, userId); | ||
| } | ||
|
|
||
| // 게시글 조회 (공지/일반) | ||
| @GetMapping | ||
| public ResponseEntity<Page<PostResponse>> getPosts( | ||
| @RequestParam BoardType boardType, | ||
| @RequestParam(defaultValue = "0") int pageNumber, | ||
| @RequestParam(defaultValue = "20") int pageSize) { | ||
| return ResponseEntity.ok(postService.getPosts(boardType, pageNumber, pageSize)); | ||
| } | ||
|
|
||
| // 게시글 검색 | ||
| @GetMapping("/search") | ||
| public ResponseEntity<Page<PostResponse>> searchPosts( | ||
| @RequestParam String keyword, | ||
| @RequestParam(defaultValue = "0") int pageNumber, | ||
| @RequestParam(defaultValue = "20") int pageSize) { | ||
| return ResponseEntity.ok(postService.searchPosts(keyword, pageNumber, pageSize)); | ||
| } | ||
|
|
||
| // 게시물 상세 조회 | ||
| @GetMapping("/{postId}") | ||
| public ResponseEntity<PostResponse> getPostDetail( | ||
| @PathVariable UUID postId, | ||
| @RequestParam(defaultValue = "0") int commentPageNumber, | ||
| @RequestParam(defaultValue = "20") int commentPageSize) { | ||
| PostResponse response = postService.getPostDetail(postId, commentPageNumber, commentPageSize); | ||
| return ResponseEntity.ok(response); | ||
| } | ||
|
|
||
| // 좋아요 토글 | ||
| @PostMapping("/{postId}/like") | ||
| public ResponseEntity<Void> toggleLike( | ||
| @PathVariable UUID postId, | ||
| @AuthenticationPrincipal CustomUserDetails customUserDetails) { | ||
| UUID userId = customUserDetails.getUserId(); | ||
| postService.toggleLike(postId, userId); | ||
| return ResponseEntity.ok().build(); | ||
| } | ||
|
|
||
| // 북마크 토글 | ||
| @PostMapping("/{postId}/bookmark") | ||
| public ResponseEntity<Void> toggleBookmark( | ||
| @PathVariable UUID postId, | ||
| @AuthenticationPrincipal CustomUserDetails customUserDetails) { | ||
| UUID userId = customUserDetails.getUserId(); | ||
| postService.toggleBookmark(postId, userId); | ||
| return ResponseEntity.ok().build(); | ||
| } | ||
|
|
||
| // 댓글 작성 | ||
| @PostMapping("/{postId}/comment") | ||
| public ResponseEntity<Void> createComment( | ||
| @RequestBody CommentRequest request, | ||
| @AuthenticationPrincipal CustomUserDetails customUserDetails) { | ||
| UUID userId = customUserDetails.getUserId(); | ||
| postService.createComment(request, userId); | ||
| return ResponseEntity.ok().build(); | ||
| } | ||
|
|
||
| // 댓글 수정 | ||
| @PutMapping("/comment/{commentId}") | ||
| public void updateComment( | ||
| @PathVariable UUID commentId, | ||
| @RequestBody CommentRequest request, | ||
| @AuthenticationPrincipal CustomUserDetails customUserDetails) { | ||
| UUID userId = customUserDetails.getUserId(); | ||
| postService.updateComment(request, commentId, userId); | ||
| } | ||
|
|
||
| // 댓글 삭제 | ||
| @DeleteMapping("/comment/{commentId}") | ||
| public void deleteComment( | ||
| @PathVariable UUID commentId, | ||
| @AuthenticationPrincipal CustomUserDetails customUserDetails) { | ||
| UUID userId = customUserDetails.getUserId(); | ||
| postService.deleteComment(commentId, userId); | ||
| } | ||
| } |
26 changes: 26 additions & 0 deletions
26
backend/src/main/java/org/sejongisc/backend/board/dto/CommentRequest.java
This file contains hidden or 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.sejongisc.backend.board.dto; | ||
|
|
||
| import jakarta.validation.constraints.NotBlank; | ||
| import jakarta.validation.constraints.NotNull; | ||
| import java.util.UUID; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
| import lombok.Setter; | ||
| import lombok.ToString; | ||
|
|
||
| @ToString | ||
| @AllArgsConstructor | ||
| @NoArgsConstructor | ||
| @Getter | ||
| @Setter | ||
| @Builder | ||
| public class CommentRequest { | ||
|
|
||
| @NotNull | ||
| private UUID postId; | ||
|
|
||
| @NotBlank(message = "댓글 내용은 필수 항목입니다.") | ||
| private String content; | ||
| } |
36 changes: 36 additions & 0 deletions
36
backend/src/main/java/org/sejongisc/backend/board/dto/CommentResponse.java
This file contains hidden or 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,36 @@ | ||
| package org.sejongisc.backend.board.dto; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
|
|
||
| import java.time.LocalDateTime; | ||
| import java.util.UUID; | ||
| import lombok.NoArgsConstructor; | ||
| import lombok.Setter; | ||
| import lombok.ToString; | ||
| import org.sejongisc.backend.board.entity.Comment; | ||
|
|
||
| @ToString | ||
| @AllArgsConstructor | ||
| @NoArgsConstructor | ||
| @Getter | ||
| @Setter | ||
| @Builder | ||
| public class CommentResponse { | ||
| private UUID commentId; | ||
| private UUID postId; | ||
| private String content; | ||
| private LocalDateTime createdDate; | ||
| private LocalDateTime updatedDate; | ||
|
|
||
| public static CommentResponse of(Comment comment) { | ||
| return CommentResponse.builder() | ||
| .commentId(comment.getCommentId()) | ||
| .postId(comment.getPostId()) | ||
| .content(comment.getContent()) | ||
| .createdDate(comment.getCreatedDate()) | ||
| .updatedDate(comment.getUpdatedDate()) | ||
| .build(); | ||
| } | ||
| } |
26 changes: 26 additions & 0 deletions
26
backend/src/main/java/org/sejongisc/backend/board/dto/PostAttachmentResponse.java
This file contains hidden or 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.sejongisc.backend.board.dto; | ||
|
|
||
| import java.util.UUID; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
| import org.sejongisc.backend.board.entity.PostAttachment; | ||
|
|
||
| @Getter | ||
| @Builder | ||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
| public class PostAttachmentResponse { | ||
| private UUID postAttachmentId; | ||
| private String originalFilename; | ||
| private String filePath; | ||
|
|
||
| public static PostAttachmentResponse of(PostAttachment attachment) { | ||
| return PostAttachmentResponse.builder() | ||
| .postAttachmentId(attachment.getPostAttachmentId()) | ||
| .originalFilename(attachment.getOriginalFilename()) | ||
| .filePath(attachment.getFilePath()) | ||
| .build(); | ||
| } | ||
| } |
37 changes: 37 additions & 0 deletions
37
backend/src/main/java/org/sejongisc/backend/board/dto/PostRequest.java
This file contains hidden or 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,37 @@ | ||
| package org.sejongisc.backend.board.dto; | ||
|
|
||
| import jakarta.validation.constraints.NotBlank; | ||
| import jakarta.validation.constraints.NotNull; | ||
| import java.util.List; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
| import lombok.Setter; | ||
| import lombok.ToString; | ||
| import org.sejongisc.backend.board.entity.BoardType; | ||
| import org.sejongisc.backend.board.entity.PostType; | ||
| import org.springframework.web.multipart.MultipartFile; | ||
|
|
||
| @ToString | ||
| @AllArgsConstructor | ||
| @NoArgsConstructor | ||
| @Getter | ||
| @Setter | ||
| @Builder | ||
| public class PostRequest { | ||
|
|
||
| @NotNull(message = "게시판 타입을 선택해주세요.") | ||
| private BoardType boardType; | ||
|
|
||
| @NotBlank(message = "제목은 필수 항목입니다.") | ||
| private String title; | ||
|
|
||
| @NotBlank(message = "내용은 필수 항목입니다.") | ||
| private String content; | ||
|
|
||
| @NotNull(message = "게시글 타입을 선택해주세요.") | ||
| private PostType postType; | ||
|
|
||
| private List<MultipartFile> files; | ||
| } |
40 changes: 40 additions & 0 deletions
40
backend/src/main/java/org/sejongisc/backend/board/dto/PostResponse.java
This file contains hidden or 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,40 @@ | ||
| package org.sejongisc.backend.board.dto; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
| import lombok.Setter; | ||
| import lombok.ToString; | ||
| import org.sejongisc.backend.board.entity.BoardType; | ||
| import org.sejongisc.backend.board.entity.Post; | ||
| import org.sejongisc.backend.board.entity.PostType; | ||
|
|
||
| import java.time.LocalDateTime; | ||
| import java.util.List; | ||
| import java.util.UUID; | ||
| import org.sejongisc.backend.user.entity.User; | ||
| import org.springframework.data.domain.Page; | ||
|
|
||
| @ToString | ||
| @AllArgsConstructor | ||
| @NoArgsConstructor | ||
| @Getter | ||
| @Setter | ||
| @Builder | ||
| public class PostResponse { | ||
|
|
||
| private UUID postId; | ||
| private BoardType boardType; | ||
| private User user; | ||
| private String title; | ||
| private String content; | ||
| private PostType postType; | ||
| private Integer bookmarkCount; | ||
| private Integer likeCount; | ||
| private Integer commentCount; | ||
| private LocalDateTime createdDate; | ||
| private LocalDateTime updatedDate; | ||
| private Page<CommentResponse> comments; | ||
| private List<PostAttachmentResponse> attachments; | ||
| } | ||
17 changes: 17 additions & 0 deletions
17
backend/src/main/java/org/sejongisc/backend/board/dto/PostSummaryResponse.java
This file contains hidden or 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,17 @@ | ||
| package org.sejongisc.backend.board.dto; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
|
|
||
| import java.time.LocalDateTime; | ||
| import java.util.UUID; | ||
|
|
||
| @Getter | ||
| @AllArgsConstructor | ||
| public class PostSummaryResponse { | ||
| private UUID id; | ||
| private String title; | ||
| private int likeCount; | ||
| private int commentCount; | ||
| private LocalDateTime createdAt; | ||
| } |
7 changes: 7 additions & 0 deletions
7
backend/src/main/java/org/sejongisc/backend/board/entity/BoardType.java
This file contains hidden or 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,7 @@ | ||
| package org.sejongisc.backend.board.entity; | ||
|
|
||
| public enum BoardType { | ||
| GENERAL, // 전체 게시판 | ||
| FINANCE_IT, // 금융 IT 게시판 | ||
| ASSET_MANAGEMENT // 자산 운용 게시판 | ||
| } |
31 changes: 31 additions & 0 deletions
31
backend/src/main/java/org/sejongisc/backend/board/entity/Comment.java
This file contains hidden or 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,31 @@ | ||
| package org.sejongisc.backend.board.entity; | ||
|
|
||
| import jakarta.persistence.*; | ||
| import lombok.*; | ||
| import org.hibernate.annotations.CreationTimestamp; | ||
| import java.time.LocalDateTime; | ||
| import java.util.UUID; | ||
| import org.sejongisc.backend.common.entity.postgres.BasePostgresEntity; | ||
| import org.sejongisc.backend.user.entity.User; | ||
|
|
||
| @Entity | ||
| @Getter | ||
| @Setter | ||
| @Builder | ||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
| public class Comment extends BasePostgresEntity { | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.UUID) | ||
| private UUID commentId; | ||
|
|
||
| @Column(nullable = false) | ||
| private UUID postId; | ||
|
|
||
| @ManyToOne(fetch = FetchType.LAZY) | ||
| private User user; | ||
|
|
||
| @Column(columnDefinition = "TEXT", nullable = false) | ||
| private String content; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
사용자 엔티티 직접 노출로 인한 보안/직렬화 위험 차단 필요
PostResponse가User엔티티를 그대로 반환하면 민감 정보가 외부로 노출되고, LAZY 로딩 환경에서 직렬화 시LazyInitializationException이 빈번히 발생합니다. API 전용 사용자 DTO 또는 최소한의 식별 정보만 노출하도록 구조를 바꿔주세요.🤖 Prompt for AI Agents