From c5a07250210d5b6dbe9126a974f455fa303766e5 Mon Sep 17 00:00:00 2001 From: jinseok Date: Sun, 13 Oct 2024 18:11:57 +0900 Subject: [PATCH 1/4] =?UTF-8?q?[chore]=20#131=20board=20=EB=94=94=EB=B9=84?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../homepage/application/post/controller/PostController.java | 2 ++ .../ussum/homepage/infra/jpa/post/BoardRepositoryImpl.java | 1 - .../java/ussum/homepage/infra/jpa/post/entity/BoardCode.java | 5 +++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/ussum/homepage/application/post/controller/PostController.java b/src/main/java/ussum/homepage/application/post/controller/PostController.java index b8dcdbdd..388e7e2c 100644 --- a/src/main/java/ussum/homepage/application/post/controller/PostController.java +++ b/src/main/java/ussum/homepage/application/post/controller/PostController.java @@ -1,5 +1,6 @@ package ussum.homepage.application.post.controller; +import java.util.Comparator; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.*; @@ -7,6 +8,7 @@ @RequiredArgsConstructor @RequestMapping("/boards") public class PostController { + //Comparator // private final PostService postService; // @GetMapping("/{boardCode}/posts") diff --git a/src/main/java/ussum/homepage/infra/jpa/post/BoardRepositoryImpl.java b/src/main/java/ussum/homepage/infra/jpa/post/BoardRepositoryImpl.java index c70a63b5..1ce9eb03 100644 --- a/src/main/java/ussum/homepage/infra/jpa/post/BoardRepositoryImpl.java +++ b/src/main/java/ussum/homepage/infra/jpa/post/BoardRepositoryImpl.java @@ -9,7 +9,6 @@ import ussum.homepage.infra.jpa.post.entity.BoardCode; import ussum.homepage.infra.jpa.post.repository.BoardJpaRepository; -import java.util.List; import java.util.Optional; diff --git a/src/main/java/ussum/homepage/infra/jpa/post/entity/BoardCode.java b/src/main/java/ussum/homepage/infra/jpa/post/entity/BoardCode.java index 8b511de7..54025eb3 100644 --- a/src/main/java/ussum/homepage/infra/jpa/post/entity/BoardCode.java +++ b/src/main/java/ussum/homepage/infra/jpa/post/entity/BoardCode.java @@ -3,7 +3,6 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; import ussum.homepage.global.error.exception.InvalidValueException; -import ussum.homepage.infra.jpa.postlike.entity.Reaction; import java.util.Arrays; @@ -17,7 +16,9 @@ public enum BoardCode { LOST("분실물게시판"), PARTNER("제휴게시판"), PETITION("청원게시판"), - DATA("자료집게시판"); + DATA("자료집게시판"), + SUGGESTION("건의게시판"), + RIGHTS("인권신고게시판"); private final String stringBoardCode; public static BoardCode getEnumBoardCodeFromStringBoardCode(String stringBoardCode) { From 72169e9178eecc01a16100dc230ec76ccd00444e Mon Sep 17 00:00:00 2001 From: jinseok Date: Wed, 6 Nov 2024 18:58:05 +0900 Subject: [PATCH 2/4] =?UTF-8?q?[refactor]=20:=20=EA=B2=8C=EC=8B=9C?= =?UTF-8?q?=EB=AC=BC=20=EC=83=9D=EC=84=B1=20dto=20=EA=B3=B5=ED=86=B5=20?= =?UTF-8?q?=EC=B6=94=EC=83=81=ED=81=B4=EB=9E=98=EC=8A=A4=EB=A1=9C=20?= =?UTF-8?q?=EB=A7=8C=EB=93=A4=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../post/controller/PostController.java | 2 +- .../post/controller/PostManageController.java | 11 ++- .../post/service/PostManageService.java | 20 +++--- .../application/post/service/PostService.java | 4 +- .../dto/request/GeneralPostCreateRequest.java | 51 ++++++++++++++ .../dto/request/PostCreateRequest.java | 69 ++++--------------- .../postDetail/RightsPostDetailResponse.java | 22 ++++++ .../SuggestionPostDetailResponse.java | 21 ++++++ 8 files changed, 122 insertions(+), 78 deletions(-) create mode 100644 src/main/java/ussum/homepage/application/post/service/dto/request/GeneralPostCreateRequest.java create mode 100644 src/main/java/ussum/homepage/application/post/service/dto/response/postDetail/RightsPostDetailResponse.java create mode 100644 src/main/java/ussum/homepage/application/post/service/dto/response/postDetail/SuggestionPostDetailResponse.java diff --git a/src/main/java/ussum/homepage/application/post/controller/PostController.java b/src/main/java/ussum/homepage/application/post/controller/PostController.java index 388e7e2c..d5efbc08 100644 --- a/src/main/java/ussum/homepage/application/post/controller/PostController.java +++ b/src/main/java/ussum/homepage/application/post/controller/PostController.java @@ -44,7 +44,7 @@ public class PostController { // @PostMapping("/{boardCode}/posts") // public ResponseEntity> createBoardPost(@UserId Long userId, // @PathVariable(name = "boardCode") String boardCode, -// @RequestBody PostCreateRequest postCreateRequest) { +// @RequestBody GeneralPostCreateRequest postCreateRequest) { // postService.createPost(userId, boardCode,postCreateRequest); // return ApiResponse.success(null); // } diff --git a/src/main/java/ussum/homepage/application/post/controller/PostManageController.java b/src/main/java/ussum/homepage/application/post/controller/PostManageController.java index d618449c..6fef13c4 100644 --- a/src/main/java/ussum/homepage/application/post/controller/PostManageController.java +++ b/src/main/java/ussum/homepage/application/post/controller/PostManageController.java @@ -9,10 +9,9 @@ import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import ussum.homepage.application.post.service.PostManageService; -import ussum.homepage.application.post.service.dto.request.PostCreateRequest; +import ussum.homepage.application.post.service.dto.request.GeneralPostCreateRequest; import ussum.homepage.application.post.service.dto.request.PostFileDeleteRequest; import ussum.homepage.application.post.service.dto.request.PostUpdateRequest; -import ussum.homepage.application.post.service.dto.request.PostUserRequest; import ussum.homepage.application.post.service.dto.response.TopLikedPostListResponse; import ussum.homepage.global.ApiResponse; import ussum.homepage.global.config.auth.UserId; @@ -87,8 +86,8 @@ public ResponseEntity> getBoardPost(@PathVariable(name = "boardCo @PostMapping("/{boardCode}/posts") public ResponseEntity> createBoardPost(@Parameter(hidden = true) @UserId Long userId, @PathVariable(name = "boardCode") String boardCode, - @RequestBody PostCreateRequest postCreateRequest){ - return ApiResponse.success(postManageService.createBoardPost(userId, boardCode, postCreateRequest)); + @RequestBody GeneralPostCreateRequest generalPostCreateRequest){ + return ApiResponse.success(postManageService.createBoardPost(userId, boardCode, generalPostCreateRequest)); } @Operation(summary = "자료집 게시물 생성 api", description = """ @@ -99,8 +98,8 @@ public ResponseEntity> createBoardPost(@Parameter(hidden = true) @PostMapping("/data/{fileCategory}/post") public ResponseEntity> createDataPost(@Parameter(hidden = true) @UserId Long userId, @PathVariable(name = "fileCategory") String fileCategory, - @RequestBody PostCreateRequest postCreateRequest) { - return ApiResponse.success(postManageService.createDataPost(userId, fileCategory, postCreateRequest)); + @RequestBody GeneralPostCreateRequest generalPostCreateRequest) { + return ApiResponse.success(postManageService.createDataPost(userId, fileCategory, generalPostCreateRequest)); } @Operation(summary = "게시물 생성 시 파일 및 이미지 저장 api", description = """ 게시물 생성 시 파일 및 이미지 저장하는 api입니다. diff --git a/src/main/java/ussum/homepage/application/post/service/PostManageService.java b/src/main/java/ussum/homepage/application/post/service/PostManageService.java index ff4e47a8..cb3604fc 100644 --- a/src/main/java/ussum/homepage/application/post/service/PostManageService.java +++ b/src/main/java/ussum/homepage/application/post/service/PostManageService.java @@ -1,17 +1,14 @@ package ussum.homepage.application.post.service; -import io.swagger.v3.oas.annotations.Parameter; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.StringUtils; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.multipart.MultipartFile; import ussum.homepage.application.comment.service.dto.response.PostOfficialCommentResponse; -import ussum.homepage.application.post.service.dto.request.PostCreateRequest; +import ussum.homepage.application.post.service.dto.request.GeneralPostCreateRequest; import ussum.homepage.application.post.service.dto.request.PostFileDeleteRequest; import ussum.homepage.application.post.service.dto.request.PostUpdateRequest; import ussum.homepage.application.post.service.dto.response.FileResponse; @@ -43,7 +40,6 @@ import ussum.homepage.domain.user.User; import ussum.homepage.domain.user.service.UserReader; import ussum.homepage.global.common.PageInfo; -import ussum.homepage.global.config.auth.UserId; import ussum.homepage.global.error.exception.GeneralException; import ussum.homepage.global.error.status.ErrorStatus; import ussum.homepage.infra.jpa.group.entity.GroupCode; @@ -51,7 +47,6 @@ import ussum.homepage.infra.jpa.post.entity.BoardCode; import ussum.homepage.infra.jpa.post.entity.Category; import ussum.homepage.infra.jpa.post.entity.FileCategory; -import ussum.homepage.infra.jpa.post.entity.FileType; import ussum.homepage.infra.utils.S3utils; import java.util.Comparator; @@ -173,18 +168,19 @@ public PostDetailRes getPost(Long userId, String boardCode, Long postId) { } @Transactional - public PostCreateResponse createBoardPost(Long userId, String boardCode, PostCreateRequest postCreateRequest){ + public PostCreateResponse createBoardPost(Long userId, String boardCode, GeneralPostCreateRequest generalPostCreateRequest){ Board board = boardReader.getBoardWithBoardCode(boardCode); - Post post = postAppender.createPost(postCreateRequest.toDomain(board, userId)); - postFileAppender.updatePostIdForIds(postCreateRequest.postFileList(), post.getId(), FileCategory.자료집아님); + Post post = postAppender.createPost(generalPostCreateRequest.toDomain(board, userId)); + postFileAppender.updatePostIdForIds(generalPostCreateRequest.getPostFileList(), post.getId(), FileCategory.자료집아님); return PostCreateResponse.of(post.getId(), boardCode); } @Transactional - public PostCreateResponse createDataPost(Long userId, String fileCategory, PostCreateRequest postCreateRequest){ + public PostCreateResponse createDataPost(Long userId, String fileCategory, GeneralPostCreateRequest generalPostCreateRequest){ Board board = boardReader.getBoardWithBoardCode(BoardCode.DATA.getStringBoardCode()); - Post post = postAppender.createPost(postCreateRequest.toDomain(board.getId(), userId, Category.getEnumCategoryCodeFromStringCategoryCode(postCreateRequest.categoryCode()))); - postFileAppender.updatePostIdAndFileCategoryForIds(postCreateRequest.postFileList(), post.getId(), fileCategory); + Post post = postAppender.createPost(generalPostCreateRequest.toDomain(board.getId(), userId, Category.getEnumCategoryCodeFromStringCategoryCode( + generalPostCreateRequest.getCategoryCode()))); + postFileAppender.updatePostIdAndFileCategoryForIds(generalPostCreateRequest.getPostFileList(), post.getId(), fileCategory); return PostCreateResponse.of(post.getId(), BoardCode.DATA.getStringBoardCode()); } diff --git a/src/main/java/ussum/homepage/application/post/service/PostService.java b/src/main/java/ussum/homepage/application/post/service/PostService.java index 299dfa6a..ff788710 100644 --- a/src/main/java/ussum/homepage/application/post/service/PostService.java +++ b/src/main/java/ussum/homepage/application/post/service/PostService.java @@ -6,7 +6,7 @@ //import org.springframework.stereotype.Service; //import org.springframework.transaction.annotation.Transactional; // -//import ussum.homepage.application.post.service.dto.request.PostCreateRequest; +//import ussum.homepage.application.post.service.dto.request.GeneralPostCreateRequest; //import ussum.homepage.application.post.service.dto.request.PostUpdateRequest; //import ussum.homepage.application.post.service.dto.response.*; //import ussum.homepage.domain.post.Board; @@ -54,7 +54,7 @@ //// ); //// } // -// public void createPost(Long userId, String boardCode, PostCreateRequest postCreateRequest) { +// public void createPost(Long userId, String boardCode, GeneralPostCreateRequest postCreateRequest) { // Board board = boardReader.getBoardWithBoardCode(boardCode); // // postAppender.createPost(postCreateRequest.toDomain(board, userId, Category.getEnumCategoryCodeFromStringCategoryCode(postCreateRequest.categoryCode()))); diff --git a/src/main/java/ussum/homepage/application/post/service/dto/request/GeneralPostCreateRequest.java b/src/main/java/ussum/homepage/application/post/service/dto/request/GeneralPostCreateRequest.java new file mode 100644 index 00000000..c3806409 --- /dev/null +++ b/src/main/java/ussum/homepage/application/post/service/dto/request/GeneralPostCreateRequest.java @@ -0,0 +1,51 @@ +package ussum.homepage.application.post.service.dto.request; + +import java.util.List; +import lombok.Builder; +import lombok.Getter; +import ussum.homepage.domain.post.Board; +import ussum.homepage.domain.post.Post; +import ussum.homepage.infra.jpa.post.entity.Category; + +@Getter +public class GeneralPostCreateRequest extends PostCreateRequest { + private final String categoryCode; + private final List postFileList; + + @Builder + public GeneralPostCreateRequest(String title, String content, String thumbNailImage, boolean isNotice, String categoryCode, List postFileList) { + super(title, content, thumbNailImage, isNotice); + this.categoryCode = categoryCode; + this.postFileList = postFileList; + } + + public Post toDomain(Board board, Long userId){ + String status = "새로운"; + if(builder().isNotice){ + status = "긴급공지"; + } + return Post.of(null, + title, + content, + 1, + thumbNailImage, + status, + null,null,null, + categoryCode, + userId, + board.getId()); + } + public Post toDomain(Long boardId, Long userId, Category category){ + return Post.of(null, + title, + content, + 1, + thumbNailImage, + "새로운", + null,null,null, + categoryCode, + userId, + boardId); + } + +} diff --git a/src/main/java/ussum/homepage/application/post/service/dto/request/PostCreateRequest.java b/src/main/java/ussum/homepage/application/post/service/dto/request/PostCreateRequest.java index def3f4cd..071a9182 100644 --- a/src/main/java/ussum/homepage/application/post/service/dto/request/PostCreateRequest.java +++ b/src/main/java/ussum/homepage/application/post/service/dto/request/PostCreateRequest.java @@ -1,63 +1,18 @@ package ussum.homepage.application.post.service.dto.request; -import lombok.Builder; -import ussum.homepage.domain.post.Board; -import ussum.homepage.domain.post.Post; -import ussum.homepage.domain.user.User; -import ussum.homepage.infra.jpa.post.entity.Category; +import lombok.Getter; -import java.util.List; +@Getter +public abstract class PostCreateRequest { + protected String title; + protected String content; + protected String thumbNailImage; + protected boolean isNotice; -public record PostCreateRequest( - String title, - String content, - String categoryCode, - String thumbNailImage, - boolean isNotice, - List postFileList -) { - public Post toDomain(Board board, Long userId) { - String status = "새로운"; - if (isNotice) { - status = "긴급공지"; - } - return Post.of( - null, - title, - content, - 1, - thumbNailImage, - status, -// OnGoingStatus, - null, - null, - null, - categoryCode, - userId, - board.getId() - ); + public PostCreateRequest(String title, String content, String thumbNailImage, boolean isNotice) { + this.title = title; + this.content = content; + this.thumbNailImage = thumbNailImage; + this.isNotice = isNotice; } - - public Post toDomain(Long boardId, Long userId, Category category) { -// String status = "새로운"; -// if (isNotice) { -// status = "긴급"; -// } - return Post.of( - null, - title, - content, - 1, - thumbNailImage, - "새로운", -// OnGoingStatus, - null, - null, - null, - category.getStringCategoryCode(), - userId, - boardId - ); - } - } diff --git a/src/main/java/ussum/homepage/application/post/service/dto/response/postDetail/RightsPostDetailResponse.java b/src/main/java/ussum/homepage/application/post/service/dto/response/postDetail/RightsPostDetailResponse.java new file mode 100644 index 00000000..4dfc7831 --- /dev/null +++ b/src/main/java/ussum/homepage/application/post/service/dto/response/postDetail/RightsPostDetailResponse.java @@ -0,0 +1,22 @@ +package ussum.homepage.application.post.service.dto.response.postDetail; + +import java.util.List; +import lombok.Builder; +import lombok.Getter; +import ussum.homepage.application.comment.service.dto.response.PostOfficialCommentResponse; +import ussum.homepage.application.post.service.dto.response.FileResponse; + +@Getter +public class RightsPostDetailResponse extends PostDetailResDto{ + private List fileResponseList; + private List postOfficialCommentResponseList; + + @Builder + private RightsPostDetailResponse(Long postId, String categoryName, String authorName, String studentId, String title, String content, String createdAt, String lastEditedAt, Boolean isAuthor, + List fileResponseList, List officialCommentList, + List canAuthority ){ + super(postId,categoryName,authorName,title,content,createdAt,lastEditedAt,isAuthor,canAuthority); + this.fileResponseList = fileResponseList; + this.postOfficialCommentResponseList = officialCommentList; + } +} diff --git a/src/main/java/ussum/homepage/application/post/service/dto/response/postDetail/SuggestionPostDetailResponse.java b/src/main/java/ussum/homepage/application/post/service/dto/response/postDetail/SuggestionPostDetailResponse.java new file mode 100644 index 00000000..a9816668 --- /dev/null +++ b/src/main/java/ussum/homepage/application/post/service/dto/response/postDetail/SuggestionPostDetailResponse.java @@ -0,0 +1,21 @@ +package ussum.homepage.application.post.service.dto.response.postDetail; + +import java.util.List; +import lombok.Builder; +import ussum.homepage.application.comment.service.dto.response.PostOfficialCommentResponse; +import ussum.homepage.application.post.service.dto.response.FileResponse; + +public class SuggestionPostDetailResponse extends PostDetailResDto{ + private List fileResponseList; + private String studentId; + + @Builder + public SuggestionPostDetailResponse(Long postId, String categoryName, String authorName, String studentId, String title, String content, String createdAt, String lastEditedAt, Boolean isAuthor, + List fileResponseList, List officialCommentList, + List canAuthority){ + super(postId,categoryName,authorName,title,content,createdAt,lastEditedAt,isAuthor,canAuthority); + this.fileResponseList = fileResponseList; + this.studentId = studentId; + + } +} From 622f053ac9a1957737c40d95b0a509332a812bb7 Mon Sep 17 00:00:00 2001 From: jinseok Date: Fri, 8 Nov 2024 15:57:56 +0900 Subject: [PATCH 3/4] =?UTF-8?q?[refactor]=20:=20=ED=8C=A9=ED=86=A0?= =?UTF-8?q?=EB=A6=AC=EB=A1=9C=20=EA=B2=8C=EC=8B=9C=ED=8C=90=EB=B3=84=20?= =?UTF-8?q?=EA=B2=8C=EC=8B=9C=EB=AC=BC=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../post/controller/PostManageController.java | 5 ++-- .../post/service/PostManageService.java | 10 +++++-- .../dto/request/GeneralPostCreateRequest.java | 5 ++-- .../dto/request/PostCreateRequest.java | 26 +++++++++++++++-- .../post/service/factory/PostFactory.java | 9 ++++++ .../post/service/factory/PostFactoryImpl.java | 29 +++++++++++++++++++ .../global/config/SecurityConfig.java | 2 +- .../external/oauth/KakaoApiProvider.java | 2 +- .../post/service/PostManageServiceTest.java | 1 + 9 files changed, 77 insertions(+), 12 deletions(-) create mode 100644 src/main/java/ussum/homepage/domain/post/service/factory/PostFactory.java create mode 100644 src/main/java/ussum/homepage/domain/post/service/factory/PostFactoryImpl.java diff --git a/src/main/java/ussum/homepage/application/post/controller/PostManageController.java b/src/main/java/ussum/homepage/application/post/controller/PostManageController.java index 6fef13c4..2407439c 100644 --- a/src/main/java/ussum/homepage/application/post/controller/PostManageController.java +++ b/src/main/java/ussum/homepage/application/post/controller/PostManageController.java @@ -10,6 +10,7 @@ import org.springframework.web.multipart.MultipartFile; import ussum.homepage.application.post.service.PostManageService; import ussum.homepage.application.post.service.dto.request.GeneralPostCreateRequest; +import ussum.homepage.application.post.service.dto.request.PostCreateRequest; import ussum.homepage.application.post.service.dto.request.PostFileDeleteRequest; import ussum.homepage.application.post.service.dto.request.PostUpdateRequest; import ussum.homepage.application.post.service.dto.response.TopLikedPostListResponse; @@ -86,8 +87,8 @@ public ResponseEntity> getBoardPost(@PathVariable(name = "boardCo @PostMapping("/{boardCode}/posts") public ResponseEntity> createBoardPost(@Parameter(hidden = true) @UserId Long userId, @PathVariable(name = "boardCode") String boardCode, - @RequestBody GeneralPostCreateRequest generalPostCreateRequest){ - return ApiResponse.success(postManageService.createBoardPost(userId, boardCode, generalPostCreateRequest)); + @RequestBody PostCreateRequest postCreateRequest){ + return ApiResponse.success(postManageService.createBoardPost(userId, boardCode, postCreateRequest)); } @Operation(summary = "자료집 게시물 생성 api", description = """ diff --git a/src/main/java/ussum/homepage/application/post/service/PostManageService.java b/src/main/java/ussum/homepage/application/post/service/PostManageService.java index cb3604fc..0207f099 100644 --- a/src/main/java/ussum/homepage/application/post/service/PostManageService.java +++ b/src/main/java/ussum/homepage/application/post/service/PostManageService.java @@ -9,6 +9,7 @@ import org.springframework.web.multipart.MultipartFile; import ussum.homepage.application.comment.service.dto.response.PostOfficialCommentResponse; import ussum.homepage.application.post.service.dto.request.GeneralPostCreateRequest; +import ussum.homepage.application.post.service.dto.request.PostCreateRequest; import ussum.homepage.application.post.service.dto.request.PostFileDeleteRequest; import ussum.homepage.application.post.service.dto.request.PostUpdateRequest; import ussum.homepage.application.post.service.dto.response.FileResponse; @@ -31,6 +32,7 @@ import ussum.homepage.domain.post.service.*; import ussum.homepage.domain.post.service.factory.BoardFactory; import ussum.homepage.domain.post.service.factory.BoardImpl; +import ussum.homepage.domain.post.service.factory.PostFactoryImpl; import ussum.homepage.domain.post.service.factory.postList.DataPostResponseFactory; import ussum.homepage.domain.post.service.factory.postList.PostListResponseFactory; import ussum.homepage.domain.post.service.factory.postList.PostResponseFactoryProvider; @@ -168,10 +170,12 @@ public PostDetailRes getPost(Long userId, String boardCode, Long postId) { } @Transactional - public PostCreateResponse createBoardPost(Long userId, String boardCode, GeneralPostCreateRequest generalPostCreateRequest){ + public PostCreateResponse createBoardPost(Long userId, String boardCode, PostCreateRequest postCreateRequest){ Board board = boardReader.getBoardWithBoardCode(boardCode); - Post post = postAppender.createPost(generalPostCreateRequest.toDomain(board, userId)); - postFileAppender.updatePostIdForIds(generalPostCreateRequest.getPostFileList(), post.getId(), FileCategory.자료집아님); + Post post = postAppender.createPost(postCreateRequest.toDomain(board, userId)); + PostFactoryImpl postFactory = new PostFactoryImpl(); + postCreateRequest = postFactory.convert(boardCode,postCreateRequest); + postFileAppender.updatePostIdForIds(postCreateRequest.getPostFileList(), post.getId(), FileCategory.자료집아님); return PostCreateResponse.of(post.getId(), boardCode); } diff --git a/src/main/java/ussum/homepage/application/post/service/dto/request/GeneralPostCreateRequest.java b/src/main/java/ussum/homepage/application/post/service/dto/request/GeneralPostCreateRequest.java index c3806409..4f59de1f 100644 --- a/src/main/java/ussum/homepage/application/post/service/dto/request/GeneralPostCreateRequest.java +++ b/src/main/java/ussum/homepage/application/post/service/dto/request/GeneralPostCreateRequest.java @@ -10,18 +10,17 @@ @Getter public class GeneralPostCreateRequest extends PostCreateRequest { private final String categoryCode; - private final List postFileList; @Builder public GeneralPostCreateRequest(String title, String content, String thumbNailImage, boolean isNotice, String categoryCode, List postFileList) { - super(title, content, thumbNailImage, isNotice); + super(title, content, thumbNailImage, isNotice,postFileList); this.categoryCode = categoryCode; this.postFileList = postFileList; } public Post toDomain(Board board, Long userId){ String status = "새로운"; - if(builder().isNotice){ + if(isNotice){ status = "긴급공지"; } return Post.of(null, diff --git a/src/main/java/ussum/homepage/application/post/service/dto/request/PostCreateRequest.java b/src/main/java/ussum/homepage/application/post/service/dto/request/PostCreateRequest.java index 071a9182..d8a6091e 100644 --- a/src/main/java/ussum/homepage/application/post/service/dto/request/PostCreateRequest.java +++ b/src/main/java/ussum/homepage/application/post/service/dto/request/PostCreateRequest.java @@ -1,18 +1,40 @@ package ussum.homepage.application.post.service.dto.request; +import java.util.List; import lombok.Getter; +import ussum.homepage.domain.post.Board; +import ussum.homepage.domain.post.Post; @Getter -public abstract class PostCreateRequest { +public class PostCreateRequest { protected String title; protected String content; protected String thumbNailImage; protected boolean isNotice; + protected List postFileList; - public PostCreateRequest(String title, String content, String thumbNailImage, boolean isNotice) { + public PostCreateRequest(String title, String content, String thumbNailImage, boolean isNotice, List postFileList) { this.title = title; this.content = content; this.thumbNailImage = thumbNailImage; this.isNotice = isNotice; + this.postFileList = postFileList; + } + + public Post toDomain(Board board, Long userId){ + String status = "새로운"; + if(isNotice){ + status = "긴급공지"; + } + return Post.of(null, + title, + content, + 1, + thumbNailImage, + status, + null,null,null, + null, + userId, + board.getId()); } } diff --git a/src/main/java/ussum/homepage/domain/post/service/factory/PostFactory.java b/src/main/java/ussum/homepage/domain/post/service/factory/PostFactory.java new file mode 100644 index 00000000..e0c1af1b --- /dev/null +++ b/src/main/java/ussum/homepage/domain/post/service/factory/PostFactory.java @@ -0,0 +1,9 @@ +package ussum.homepage.domain.post.service.factory; + +import org.springframework.stereotype.Component; +import ussum.homepage.application.post.service.dto.request.PostCreateRequest; + +@Component +public interface PostFactory { + PostCreateRequest convert(String boardCode, PostCreateRequest request); +} diff --git a/src/main/java/ussum/homepage/domain/post/service/factory/PostFactoryImpl.java b/src/main/java/ussum/homepage/domain/post/service/factory/PostFactoryImpl.java new file mode 100644 index 00000000..b6b62c07 --- /dev/null +++ b/src/main/java/ussum/homepage/domain/post/service/factory/PostFactoryImpl.java @@ -0,0 +1,29 @@ +package ussum.homepage.domain.post.service.factory; + +import ussum.homepage.application.post.service.dto.request.GeneralPostCreateRequest; +import ussum.homepage.application.post.service.dto.request.PostCreateRequest; + +public class PostFactoryImpl implements PostFactory { + + @Override + public PostCreateRequest convert(String boardCode, PostCreateRequest request) { + return switch (boardCode){ + case "인권신고게시판" -> + GeneralPostCreateRequest.builder() + .title(request.getTitle()) + .content(request.getContent()) + .isNotice(request.isNotice()) + .thumbNailImage(request.getThumbNailImage()) + .postFileList(request.getPostFileList()) + .build(); + default -> + GeneralPostCreateRequest.builder() + .title(request.getTitle()) + .content(request.getContent()) + .isNotice(request.isNotice()) + .thumbNailImage(request.getThumbNailImage()) + .postFileList(request.getPostFileList()) + .build(); + }; + } +} diff --git a/src/main/java/ussum/homepage/global/config/SecurityConfig.java b/src/main/java/ussum/homepage/global/config/SecurityConfig.java index b80f3ba0..c14b79cf 100644 --- a/src/main/java/ussum/homepage/global/config/SecurityConfig.java +++ b/src/main/java/ussum/homepage/global/config/SecurityConfig.java @@ -103,7 +103,7 @@ public class SecurityConfig { "/onboarding/mail", "/actuator", "/actuator/prometheus", - "/users/user-info" // passu 정보 조회 + "/users/user-info", // passu 정보 조회 }; @Bean public PasswordEncoder passwordEncoder() { diff --git a/src/main/java/ussum/homepage/global/external/oauth/KakaoApiProvider.java b/src/main/java/ussum/homepage/global/external/oauth/KakaoApiProvider.java index 16d68561..ec78ad3d 100644 --- a/src/main/java/ussum/homepage/global/external/oauth/KakaoApiProvider.java +++ b/src/main/java/ussum/homepage/global/external/oauth/KakaoApiProvider.java @@ -38,7 +38,7 @@ public class KakaoApiProvider { public String getKakaoLogin(){ String authUrl = authorize_uri + "?client_id=" + clientId + - "&redirect_uri=" + redirectUri + + "&redirect_uri="+ redirectUri + "&response_type=code"; return authUrl; } diff --git a/src/test/java/ussum/homepage/application/post/service/PostManageServiceTest.java b/src/test/java/ussum/homepage/application/post/service/PostManageServiceTest.java index 09d324c5..2e6bf2d3 100644 --- a/src/test/java/ussum/homepage/application/post/service/PostManageServiceTest.java +++ b/src/test/java/ussum/homepage/application/post/service/PostManageServiceTest.java @@ -258,4 +258,5 @@ static List createMultiplePosts(int count) { Category.values()[i % Category.values().length].getStringCategoryCode(), "Active")) .collect(Collectors.toList()); } + } \ No newline at end of file From 6bf4fa4618e2c5ed17d48039cab42e7ebb596c7f Mon Sep 17 00:00:00 2001 From: jinseok Date: Fri, 8 Nov 2024 22:55:11 +0900 Subject: [PATCH 4/4] =?UTF-8?q?[feat]:=EC=9D=B8=EA=B6=8C=EC=8B=A0=EA=B3=A0?= =?UTF-8?q?=EA=B2=8C=EC=8B=9C=ED=8C=90=20=EC=B6=94=EA=B0=80=20=EC=97=94?= =?UTF-8?q?=ED=8B=B0=ED=8B=B0=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/request/RigthPostCreateRequest.java | 14 +++++ .../jpa/post/entity/RightsDetailEntity.java | 60 +++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 src/main/java/ussum/homepage/application/post/service/dto/request/RigthPostCreateRequest.java create mode 100644 src/main/java/ussum/homepage/infra/jpa/post/entity/RightsDetailEntity.java diff --git a/src/main/java/ussum/homepage/application/post/service/dto/request/RigthPostCreateRequest.java b/src/main/java/ussum/homepage/application/post/service/dto/request/RigthPostCreateRequest.java new file mode 100644 index 00000000..e68ff4bf --- /dev/null +++ b/src/main/java/ussum/homepage/application/post/service/dto/request/RigthPostCreateRequest.java @@ -0,0 +1,14 @@ +package ussum.homepage.application.post.service.dto.request; + +import java.util.List; +import lombok.Getter; + +@Getter +public class RigthPostCreateRequest extends PostCreateRequest { + private final List relatedPeople; + + public RigthPostCreateRequest(String title, String content, String thumbNailImage, boolean isNotice, + List postFileList) { + super(title, content, thumbNailImage, isNotice, postFileList); + } +} diff --git a/src/main/java/ussum/homepage/infra/jpa/post/entity/RightsDetailEntity.java b/src/main/java/ussum/homepage/infra/jpa/post/entity/RightsDetailEntity.java new file mode 100644 index 00000000..5ec746ad --- /dev/null +++ b/src/main/java/ussum/homepage/infra/jpa/post/entity/RightsDetailEntity.java @@ -0,0 +1,60 @@ +package ussum.homepage.infra.jpa.post.entity; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.persistence.FetchType; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.validation.constraints.NotNull; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Entity +public class RightsDetailEntity { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "post_id") + private PostEntity postEntity; + + @NotNull + private String name; + + private String studentId; + + private String major; + + @Enumerated(EnumType.STRING) + @Column(nullable = false) + private PersonType personType; + + @RequiredArgsConstructor + @Getter + public enum PersonType { + + REPORTER("신고자"), + + VICTIM("피침해자"), + + ATTACKER("침해자"); + + private final String type; + + public PersonType getEnumPersonTypeFromStringType(String type) { + for (PersonType person : values()) { + if (person.getType().equals(type)) { + return person; + } + } + throw new IllegalArgumentException("Unknown rights person type: " + type); + } + + } +}