Skip to content

Commit

Permalink
[feat] #50 자료집 게시판 생성 로직 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
qogustj committed Aug 18, 2024
1 parent c5ba17d commit 0c0f5bb
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ public ResponseEntity<ApiResponse<?>> createBoardPost(@UserId Long userId,
@RequestBody PostCreateRequest postCreateRequest){
return ApiResponse.success(postManageService.createBoardPost(userId, boardCode, postCreateRequest));
}
@PostMapping("data/{subCategory}/post")
public ResponseEntity<ApiResponse<?>> createDataPost(@UserId Long userId,
@PathVariable(name = "subCategory") String subCategory,
@RequestBody PostCreateRequest postCreateRequest){
return ApiResponse.success(postManageService.createDataPost(userId, subCategory, postCreateRequest));
}

@PostMapping("/{boardCode}/files")
public ResponseEntity<ApiResponse<?>> createBoardPostFile(@UserId Long userId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
import ussum.homepage.domain.comment.service.PostCommentReader;
import ussum.homepage.domain.comment.service.PostOfficialCommentFormatter;

import ussum.homepage.domain.group.Group;
import ussum.homepage.domain.group.service.GroupReader;
import ussum.homepage.domain.member.Member;
import ussum.homepage.domain.member.service.MemberReader;
import ussum.homepage.domain.post.Board;
import ussum.homepage.domain.post.Post;
import ussum.homepage.domain.post.PostFile;
Expand All @@ -35,6 +39,7 @@
import ussum.homepage.global.common.PageInfo;
import ussum.homepage.global.error.exception.GeneralException;
import ussum.homepage.global.error.status.ErrorStatus;
import ussum.homepage.infra.jpa.post.entity.BoardCode;
import ussum.homepage.infra.jpa.post.entity.Category;
import ussum.homepage.infra.utils.S3utils;

Expand All @@ -54,6 +59,8 @@ public class PostManageService {
private final PostReader postReader;
private final PostReactionReader postReactionReader;
private final UserReader userReader;
private final MemberReader memberReader;
private final GroupReader groupReader;
private final PostCommentReader postCommentReader;
private final PostFileReader postFileReader;
private final PostAppender postAppender;
Expand Down Expand Up @@ -168,14 +175,21 @@ public PostDetailRes<?> getPost(PostUserRequest postUserRequest, String boardCod
@Transactional
public PostCreateResponse createBoardPost(Long userId, String boardCode, PostCreateRequest postCreateRequest){
Board board = boardReader.getBoardWithBoardCode(boardCode);
User user = userReader.getUserWithId(userId);
String onGoingStatus = Objects.equals(boardCode, "PETITION") ? postCreateRequest.categoryCode() : null;

Post post = postAppender.createPost(postCreateRequest.toDomain(board, user, Category.getEnumCategoryCodeFromStringCategoryCode(postCreateRequest.categoryCode()), onGoingStatus));
Post post = postAppender.createPost(postCreateRequest.toDomain(board, userId, Category.getEnumCategoryCodeFromStringCategoryCode(postCreateRequest.categoryCode()), onGoingStatus));
postFileAppender.updatePostIdForIds(postCreateRequest.postFileList(), post.getId());
return PostCreateResponse.of(post.getId(), boardCode);
}

@Transactional
public PostCreateResponse createDataPost(Long userId, String subCategory, PostCreateRequest postCreateRequest){
Board board = boardReader.getBoardWithBoardCode(BoardCode.DATA.getStringBoardCode());
Post post = postAppender.createPost(postCreateRequest.toDomain(board.getId(), userId, Category.getEnumCategoryCodeFromStringCategoryCode(postCreateRequest.categoryCode()), null));
postFileAppender.updatePostIdAndSubCategoryForIds(postCreateRequest.postFileList(), post.getId(), subCategory);
return PostCreateResponse.of(post.getId(), BoardCode.DATA.getStringBoardCode());
}

@Transactional
public List<PostFileResponse> createBoardPostFile(Long userId, String boardCode, MultipartFile[] files, String typeName){
List<String> urlList = s3utils.uploadFileWithPath(userId, boardCode, files, typeName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,8 @@ public TopLikedPostListResponse getTopLikedPostList(int page, int take, String b

public void createPost(Long userId, String boardCode, PostCreateRequest postCreateRequest) {
Board board = boardReader.getBoardWithBoardCode(boardCode);
//user도 찾아 와야 하지 않을까
User user = userReader.getUserWithId(userId);

postAppender.createPost(postCreateRequest.toDomain(board, user, Category.getEnumCategoryCodeFromStringCategoryCode(postCreateRequest.categoryCode()), null));
postAppender.createPost(postCreateRequest.toDomain(board, userId, Category.getEnumCategoryCodeFromStringCategoryCode(postCreateRequest.categoryCode()), null));
}

// public PostResponse editPost(String boardCode,Long postId, PostUpdateRequest postUpdateRequest) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public record PostCreateRequest(
String thumbNailImage,
List<Long> postFileList
) {
public Post toDomain(Board board, User user, Category category, String OnGoingStatus) {
public Post toDomain(Board board, Long userId, Category category, String OnGoingStatus) {
return Post.of(
null,
title,
Expand All @@ -27,9 +27,27 @@ public Post toDomain(Board board, User user, Category category, String OnGoingSt
null,
null,
category,
user.getId(), //이건 채워넣어야 함, user쪽 개발되면
userId, //이건 채워넣어야 함, user쪽 개발되면
board.getId()
);
}

public Post toDomain(Long boardId, Long userId, Category category, String OnGoingStatus) {
return Post.of(
null,
title,
content,
1,
thumbNailImage,
"새로운",
OnGoingStatus,
null,
null,
null,
category,
userId, //이건 채워넣어야 함, user쪽 개발되면
boardId
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ public interface PostFileRepository {
Optional<PostFile> findById(Long id);
List<PostFile> saveAll(List<PostFile> postFiles);
void updatePostIdForIds(List<Long> postFileIds, Long postId);
void updatePostIdAndSubCategoryForIds(List<Long> postFileIds, Long postId, String subCategory);
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,9 @@ public List<PostFile> saveAllPostFile(List<PostFile> fileList) {
public void updatePostIdForIds(List<Long> postFileIds, Long postId) {
postFileRepository.updatePostIdForIds(postFileIds, postId);
}

@Transactional
public void updatePostIdAndSubCategoryForIds(List<Long> postFileIds, Long postId, String subCategory){
postFileRepository.updatePostIdAndSubCategoryForIds(postFileIds, postId, subCategory);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,14 @@ public void updatePostIdForIds(List<Long> postFileIds, Long postId) {
.where(postFileEntity.id.in(postFileIds))
.execute();
}

@Override
public void updatePostIdAndSubCategoryForIds(List<Long> postFileIds, Long postId, String subCategory) {
queryFactory
.update(postFileEntity)
.set(postFileEntity.postEntity.id, postId)
.set(postFileEntity.subCategory, subCategory)
.where(postFileEntity.id.in(postFileIds))
.execute();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public enum BoardCode {
NOTICE("NOTICE"),
LOST("LOST"),
PARTNER("PARTNER"),
PETITION("PETITION");
PETITION("PETITION"),
DATA("DATA");

private final String stringBoardCode;
public static BoardCode getEnumBoardCodeFromStringBoardCode(String stringBoardCode) {
Expand Down

0 comments on commit 0c0f5bb

Please sign in to comment.