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..d5efbc08 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") @@ -42,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..2407439c 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,10 @@ 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.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.request.PostUserRequest; import ussum.homepage.application.post.service.dto.response.TopLikedPostListResponse; import ussum.homepage.global.ApiResponse; import ussum.homepage.global.config.auth.UserId; @@ -99,8 +99,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..0207f099 100644 --- a/src/main/java/ussum/homepage/application/post/service/PostManageService.java +++ b/src/main/java/ussum/homepage/application/post/service/PostManageService.java @@ -1,16 +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.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; @@ -34,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; @@ -43,7 +42,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 +49,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; @@ -176,15 +173,18 @@ public PostDetailRes getPost(Long userId, String boardCode, Long postId) { public PostCreateResponse createBoardPost(Long userId, String boardCode, PostCreateRequest postCreateRequest){ Board board = boardReader.getBoardWithBoardCode(boardCode); Post post = postAppender.createPost(postCreateRequest.toDomain(board, userId)); - postFileAppender.updatePostIdForIds(postCreateRequest.postFileList(), post.getId(), FileCategory.자료집아님); + PostFactoryImpl postFactory = new PostFactoryImpl(); + postCreateRequest = postFactory.convert(boardCode,postCreateRequest); + postFileAppender.updatePostIdForIds(postCreateRequest.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..4f59de1f --- /dev/null +++ b/src/main/java/ussum/homepage/application/post/service/dto/request/GeneralPostCreateRequest.java @@ -0,0 +1,50 @@ +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; + + @Builder + public GeneralPostCreateRequest(String title, String content, String thumbNailImage, boolean isNotice, String categoryCode, List postFileList) { + super(title, content, thumbNailImage, isNotice,postFileList); + this.categoryCode = categoryCode; + 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, + 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..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,63 +1,40 @@ package ussum.homepage.application.post.service.dto.request; -import lombok.Builder; +import java.util.List; +import lombok.Getter; 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 java.util.List; +@Getter +public class PostCreateRequest { + protected String title; + protected String content; + protected String thumbNailImage; + protected boolean isNotice; + protected List postFileList; -public record PostCreateRequest( - String title, - String content, - String categoryCode, - String thumbNailImage, - boolean isNotice, - List postFileList -) { - public Post toDomain(Board board, Long userId) { + 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) { + if(isNotice){ status = "긴급공지"; } - return Post.of( - null, + return Post.of(null, title, content, 1, thumbNailImage, status, -// OnGoingStatus, + null,null,null, null, - null, - null, - categoryCode, userId, - board.getId() - ); + board.getId()); } - - 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/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/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; + + } +} 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/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) { 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); + } + + } +} 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