Skip to content

Commit

Permalink
[hotfix]: 자료집 수정 카테고리
Browse files Browse the repository at this point in the history
  • Loading branch information
qogustj committed Oct 13, 2024
1 parent 49c5d5d commit 8df84b5
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ 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());
postFileAppender.updatePostIdForIds(postCreateRequest.postFileList(), post.getId(), FileCategory.자료집아님);
return PostCreateResponse.of(post.getId(), boardCode);
}

Expand Down Expand Up @@ -272,14 +272,14 @@ public Long editBoardPost(String boardCode, Long postId, PostUpdateRequest postU
Post post = postReader.getPostWithId(postId);
Board board = boardReader.getBoardWithBoardCode(boardCode);
Post newPost = postModifier.updatePost(postUpdateRequest.toDomain(post, board));
postFileAppender.updatePostIdForIds(postUpdateRequest.postFileList(), newPost.getId());
postFileAppender.updatePostIdForIds(postUpdateRequest.postFileList(), newPost.getId(), FileCategory.자료집아님);
return post.getId();
}
@Transactional
public Long editBoardDatePost(String fileCategory, Long postId, PostUpdateRequest postUpdateRequest){
Post post = postReader.getPostWithId(postId);
Post newPost = postModifier.updateDataPost(post, postUpdateRequest.categoryCode());
postFileAppender.updatePostIdForIds(postUpdateRequest.postFileList(), newPost.getId());
postFileAppender.updatePostIdForIds(postUpdateRequest.postFileList(), newPost.getId(), FileCategory.fromString(fileCategory));
return post.getId();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ private DataPostResponse(Long postId, String title, String content, String date,
this.files = files;
}

public static DataPostResponse of(Post post, List<FileResponse> files) {
public static DataPostResponse of(Post post, List<FileResponse> files, String content) {
return DataPostResponse.builder()
.postId(post.getId())
.title(post.getTitle())
.content(post.getContent())
.content(content)
.category(post.getCategory())
.date(post.getCreatedAt())
.isNotice(post.getTitle().equals("총학생회칙"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ public interface PostFileRepository {
Long deleteAllByUrl(List<String> urlList);
Optional<PostFile> findById(Long id);
List<PostFile> saveAll(List<PostFile> postFiles);
void updatePostIdForIds(List<Long> postFileIds, Long postId);
void updatePostIdForIds(List<Long> postFileIds, Long postId, FileCategory fileCategory);
void updatePostIdAndFileCategoryForIds(List<Long> postFileIds, Long postId, FileCategory fileCategory);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public List<PostFile> saveAllPostFile(List<PostFile> fileList) {
}

@Transactional
public void updatePostIdForIds(List<Long> postFileIds, Long postId) {
postFileRepository.updatePostIdForIds(postFileIds, postId);
public void updatePostIdForIds(List<Long> postFileIds, Long postId, FileCategory fileCategory) {
postFileRepository.updatePostIdForIds(postFileIds, postId, fileCategory);
}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public PostListResDto createResponse(Post post, PostReader postReader, PostReact
@Override
public PostListResDto createDataResponse(Post post, List<PostFile> postFiles) {
List<FileResponse> fileResponses = postFiles.stream().map(postFile -> FileResponse.of(postFile)).toList();
return DataPostResponse.of(post, fileResponses);
String content = postFiles.get(0).getFileCategory();
return DataPostResponse.of(post, fileResponses, content);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@ public List<PostFile> saveAll(List<PostFile> fileList) {
}

@Override
public void updatePostIdForIds(List<Long> postFileIds, Long postId) {
public void updatePostIdForIds(List<Long> postFileIds, Long postId, FileCategory fileCategory) {
queryFactory
.update(postFileEntity)
.set(postFileEntity.postEntity.id, postId)
.set(postFileEntity.fileCategory, fileCategory)
.where(postFileEntity.id.in(postFileIds))
.execute();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ public enum FileCategory {
단과대회의록("단과대", "접속계정", "회의록"),
예결산안("단과대", "접속계정", "예결산안"),
단과대활동보고("단과대", "접속계정", "활동보고"),
대표자회의결과보고("단과대", "접속계정", "대표자회의결과보고");
대표자회의결과보고("단과대", "접속계정", "대표자회의결과보고"),

자료집아님("","","");
private final String majorCategory;
private final String middleCategory;
private final String subCategory;
Expand Down Expand Up @@ -97,4 +99,12 @@ public static List<FileCategory> getFileCategoriesByCategories(String majorCateg
private static boolean matchCategory(String categoryValue, String filterValue) {
return filterValue == null || categoryValue.equals(filterValue);
}

public static FileCategory fromString(String value) {
try {
return FileCategory.valueOf(value);
} catch (IllegalArgumentException e) {
throw new InvalidValueException(INVALID_FILE_CATEGORY);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public class PostEntity extends BaseEntity {
@JoinColumn(name = "board_id")
private BoardEntity boardEntity;

public PostEntity(Long postId) {
}

public static PostEntity from(Long id){
return new PostEntity(id, null, null, null, null, null, null, null, null, null);
}
Expand Down

0 comments on commit 8df84b5

Please sign in to comment.