Skip to content

Commit

Permalink
Merge pull request #141 from ssu-student-union/feat/131-infra
Browse files Browse the repository at this point in the history
Feat/131 infra
  • Loading branch information
beakgugong authored Nov 10, 2024
2 parents 3548843 + 39c4fd7 commit acf9418
Show file tree
Hide file tree
Showing 17 changed files with 250 additions and 65 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package ussum.homepage.application.post.controller;

import java.util.Comparator;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
@RequestMapping("/boards")
public class PostController {
//Comparator
// private final PostService postService;

// @GetMapping("/{boardCode}/posts")
Expand Down Expand Up @@ -42,7 +44,7 @@ public class PostController {
// @PostMapping("/{boardCode}/posts")
// public ResponseEntity<ApiResponse<?>> createBoardPost(@UserId Long userId,
// @PathVariable(name = "boardCode") String boardCode,
// @RequestBody PostCreateRequest postCreateRequest) {
// @RequestBody GeneralPostCreateRequest postCreateRequest) {
// postService.createPost(userId, boardCode,postCreateRequest);
// return ApiResponse.success(null);
// }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -99,8 +99,8 @@ public ResponseEntity<ApiResponse<?>> createBoardPost(@Parameter(hidden = true)
@PostMapping("/data/{fileCategory}/post")
public ResponseEntity<ApiResponse<?>> 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입니다.
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -43,15 +42,13 @@
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;
import ussum.homepage.infra.jpa.member.entity.MemberCode;
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;
Expand Down Expand Up @@ -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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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())));
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Long> 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);
}

}
Original file line number Diff line number Diff line change
@@ -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<Long> postFileList;

public record PostCreateRequest(
String title,
String content,
String categoryCode,
String thumbNailImage,
boolean isNotice,
List<Long> postFileList
) {
public Post toDomain(Board board, Long userId) {
public PostCreateRequest(String title, String content, String thumbNailImage, boolean isNotice, List<Long> 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
);
}

}
Original file line number Diff line number Diff line change
@@ -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> relatedPeople;

public RigthPostCreateRequest(String title, String content, String thumbNailImage, boolean isNotice,
List<Long> postFileList) {
super(title, content, thumbNailImage, isNotice, postFileList);
}
}
Original file line number Diff line number Diff line change
@@ -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<FileResponse> fileResponseList;
private List<PostOfficialCommentResponse> postOfficialCommentResponseList;

@Builder
private RightsPostDetailResponse(Long postId, String categoryName, String authorName, String studentId, String title, String content, String createdAt, String lastEditedAt, Boolean isAuthor,
List<FileResponse> fileResponseList, List<PostOfficialCommentResponse> officialCommentList,
List<String> canAuthority ){
super(postId,categoryName,authorName,title,content,createdAt,lastEditedAt,isAuthor,canAuthority);
this.fileResponseList = fileResponseList;
this.postOfficialCommentResponseList = officialCommentList;
}
}
Original file line number Diff line number Diff line change
@@ -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<FileResponse> 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<FileResponse> fileResponseList, List<PostOfficialCommentResponse> officialCommentList,
List<String> canAuthority){
super(postId,categoryName,authorName,title,content,createdAt,lastEditedAt,isAuthor,canAuthority);
this.fileResponseList = fileResponseList;
this.studentId = studentId;

}
}
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -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();
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public class SecurityConfig {
"/onboarding/mail",
"/actuator",
"/actuator/prometheus",
"/users/user-info" // passu 정보 조회
"/users/user-info", // passu 정보 조회
};
@Bean
public PasswordEncoder passwordEncoder() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;


Expand Down
Loading

0 comments on commit acf9418

Please sign in to comment.