Skip to content

Commit

Permalink
[feat] : merge commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeoongu committed Aug 24, 2024
2 parents fe9c254 + 77e92b3 commit 4cc0db3
Show file tree
Hide file tree
Showing 13 changed files with 90 additions and 74 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package ussum.homepage.application.post.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import ussum.homepage.application.post.service.PostService;
import ussum.homepage.application.post.service.dto.request.PostCreateRequest;
import ussum.homepage.application.post.service.dto.request.PostUpdateRequest;
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 @@ -65,8 +63,12 @@ public ResponseEntity<ApiResponse<?>> createBoardPost(@UserId Long userId,
// return ApiResponse.success(post);
// }

@Operation(summary = "게시물 삭제 api", description = """
게시물을 삭제하는 api 입니다.
""")
@DeleteMapping("/{boardCode}/posts/{postId}")
public ResponseEntity<ApiResponse<?>> deleteBoardPost(@PathVariable(name = "boardCode") String boardCode,
public ResponseEntity<ApiResponse<?>> deleteBoardPost(@Parameter(hidden = true) @UserId Long userId,
@PathVariable(name = "boardCode") String boardCode,
@PathVariable(name = "postId") Long postId) {
postService.deletePost(boardCode, postId);
return ApiResponse.success(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
Expand All @@ -17,6 +18,7 @@
@RestController
@RequiredArgsConstructor
@RequestMapping("/board")
@Tag(name = "post", description = "게시물 전체 조회(자료집 조회는 별도), 단건 조회, 생성(자료집 생성은 별도), 파일 이미지 업로드, 수정 api")
public class PostManageController {

private final PostManageService postManageService;
Expand Down Expand Up @@ -85,6 +87,11 @@ public ResponseEntity<ApiResponse<?>> createBoardPost(@Parameter(hidden = true)
return ApiResponse.success(postManageService.createBoardPost(userId, boardCode, postCreateRequest));
}

@Operation(summary = "자료집 게시물 생성 api", description = """
자료집 게시물을 생성하는 api입니다.
기본적으로 액세스 토큰을 필요로 합니다.
요청 path에 subCategory(소분류) 값을 문자열 형태로 넣으면 됩니다.
""")
@PostMapping("data/{subCategory}/post")
public ResponseEntity<ApiResponse<?>> createDataPost(@Parameter(hidden = true) @UserId Long userId,
@PathVariable(name = "subCategory") String subCategory,
Expand Down Expand Up @@ -115,6 +122,9 @@ public ResponseEntity<ApiResponse<?>> createBoardPostFile(@Parameter(hidden = tr
}


@Operation(summary = "게시물 수정 api", description = """
게시물을 수정하는 api 입니다.
""")
@PatchMapping("/{boardCode}/posts/{postId}")
public ResponseEntity<ApiResponse<?>> editBoardPost(@Parameter(hidden = true) @UserId Long userId,
@PathVariable(name = "boardCode") String boardCode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@
import ussum.homepage.application.post.service.dto.response.postList.*;

import ussum.homepage.application.post.service.dto.response.postSave.PostFileListResponse;
import ussum.homepage.domain.comment.service.formatter.TriFunction;
import ussum.homepage.domain.comment.service.formatter.QuadFunction;

import ussum.homepage.application.post.service.dto.response.postSave.PostCreateResponse;
import ussum.homepage.application.post.service.dto.response.postSave.PostFileResponse;
import ussum.homepage.domain.comment.PostComment;
import ussum.homepage.domain.comment.service.PostCommentReader;
import ussum.homepage.domain.comment.service.PostOfficialCommentFormatter;

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;
Expand Down Expand Up @@ -64,7 +63,6 @@ public class PostManageService {
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 All @@ -74,14 +72,13 @@ public class PostManageService {
private final PostOfficialCommentFormatter postOfficialCommentFormatter;
private final S3utils s3utils;

private final Map<String, TriFunction<Post, Integer, User, ? extends PostListResDto>> postResponseMap = Map.of(
"공지사항게시판", (post, ignored1, user) -> NoticePostResponse.of(post, user),
"분실물게시판", (post, ignored1, ignored2) -> LostPostResponse.of(post),
"제휴게시판", (post, ignored1, ignored2) -> PartnerPostResponse.of(post),
"감사기구게시판", (post, ignored1, ignored2) -> AuditPostResponseDto.of(post),
"청원게시판", (post, likeCount, ignored2) -> PetitionPostResponse.of(post, likeCount),
"자료집게시판", (post, likeCount, ignored2) -> DataPostResponse.of(post)

private final Map<String, QuadFunction<Post, List<PostFile>, Integer, User, ? extends PostListResDto>> postResponseMap = Map.of(
"공지사항게시판", (post, ignored1, ignored2, user) -> NoticePostResponse.of(post, user),
"분실물게시판", (post, ignored1, ignored2, ignored3) -> LostPostResponse.of(post),
"제휴게시판", (post, ignored1, ignored2, ignored3) -> PartnerPostResponse.of(post),
"감사기구게시판", (post, ignored1, ignored2, ignored3) -> AuditPostResponseDto.of(post),
"청원게시판", (post, ignored1, likeCount, ignored2) -> PetitionPostResponse.of(post, likeCount),
"자료집게시판", (post, postFiles, ignored1, ignored2) -> DataPostResponse.of(post, postFiles)
);

private final Map<String, PostDetailFunction<Post, Boolean, String, Integer, String, String, String, PostOfficialCommentResponse, ? extends PostDetailResDto>> postDetailResponseMap = Map.of(
Expand All @@ -93,6 +90,7 @@ public class PostManageService {
);


@Transactional
public PostListRes<?> getPostList(int page, int take, String boardCode, String groupCode, String memberCode, String category) {
Board board = boardReader.getBoardWithBoardCode(boardCode);
// Pageable pageable = PageInfo.of(page, take);
Expand All @@ -116,7 +114,7 @@ public PostListRes<?> getPostList(int page, int take, String boardCode, String g

PageInfo pageInfo = PageInfo.of(postList);

TriFunction<Post, Integer, User, ? extends PostListResDto> responseFunction = postResponseMap.get(board.getName());
QuadFunction<Post, List<PostFile>, Integer, User, ? extends PostListResDto> responseFunction = postResponseMap.get(board.getName());

if (responseFunction == null) {
throw new IllegalArgumentException("Unknown board type: " + board.getName());
Expand All @@ -129,15 +127,17 @@ public PostListRes<?> getPostList(int page, int take, String boardCode, String g
switch (board.getName()) {
case "공지사항게시판":
user = userReader.getUserWithId(post.getUserId());
return responseFunction.apply(post, null, user);
return responseFunction.apply(post, null, null,user);
case "분실물게시판":
case "제휴게시판":
case "감사기구게시판":
case "자료집":
return responseFunction.apply(post, null, null);
return responseFunction.apply(post, null, null, null);
case "청원게시판":
likeCount = postReactionReader.countPostReactionsByType(post.getId(), "like");
return responseFunction.apply(post, likeCount, null);

Post updatedPost = postStatusProcessor.processStatus(post);
return responseFunction.apply(post, null, likeCount,null);
default:
throw new EntityNotFoundException(String.valueOf(POST_NOT_FOUND));
}
Expand All @@ -154,8 +154,8 @@ public PostListRes<?> getDataList(int page, int take, String majorCategory, Stri

Page<Post> postList = postReader.getPostListByGroupCodeAndMemberCodeAndSubCategory(groupCodeEnum, memberCodeEnum, subCategory, pageable);
PageInfo pageInfo = PageInfo.of(postList);
TriFunction<Post, Integer, User, ? extends PostListResDto> responseFunction = postResponseMap.get("자료집게시판");
List<? extends PostListResDto> responseList = postList.getContent().stream().map(post -> responseFunction.apply(post, null, null)).toList();
QuadFunction<Post, List<PostFile> , Integer, User, ? extends PostListResDto> responseFunction = postResponseMap.get("자료집게시판");
List<? extends PostListResDto> responseList = postList.getContent().stream().map(post -> responseFunction.apply(post, postFileReader.getPostFileListByPostId(post.getId()), null, null)).toList();
return PostListRes.of(responseList, pageInfo);
}

Expand All @@ -182,12 +182,12 @@ public PostDetailRes<?> getPost(PostUserRequest postUserRequest, String boardCod
PostDetailResDto response = null;
if (board.getName().equals("청원게시판")) {
Integer likeCount = postReactionReader.countPostReactionsByType(post.getId(), "like");
String postOnGoingStatus = postStatusProcessor.processStatus(post);
Post updatedPost = postStatusProcessor.processStatus(post);
List<PostComment> officialPostComments = postCommentReader.getCommentListWithPostIdAndCommentType(userId, postId, "OFFICIAL");
List<PostOfficialCommentResponse> postOfficialCommentResponses = officialPostComments.stream()
.map(postOfficialComment -> postOfficialCommentFormatter.format(postOfficialComment, userId))
.toList();
response = responseFunction.apply(post, isAuthor, user.getName(), likeCount, postOnGoingStatus, imageList, null, postOfficialCommentResponses);
response = responseFunction.apply(updatedPost, isAuthor, user.getName(), likeCount, updatedPost.getOnGoingStatus(), imageList, null, postOfficialCommentResponses);
} else if (board.getName().equals("제휴게시판") || board.getName().equals("공지사항게시판") || board.getName().equals("감사기구게시판")) {
response = responseFunction.apply(post, isAuthor, user.getName(), null, post.getCategory(), imageList, fileList,null);
} else if (board.getName().equals("분실물게시판")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,33 @@
import ussum.homepage.application.post.service.dto.response.postList.PetitionPostResponse;
import ussum.homepage.application.post.service.dto.response.postList.PostListResDto;
import ussum.homepage.domain.post.Post;
import ussum.homepage.domain.post.PostFile;

import java.util.List;

@Getter
public class DataPostResponse extends PostListResDto {
private final Boolean isNotice;
private final List<String> fileNames;
private final List<String> files;

@Builder
private DataPostResponse(Long postId, String title, /*String content,*/ String date, String category, Boolean isNotice) {
private DataPostResponse(Long postId, String title, /*String content,*/ String date, String category, Boolean isNotice, List<String> fileNames, List<String> files) {
super(postId, title, null, date, category);
this.isNotice = isNotice;
this.fileNames = fileNames;
this.files = files;
}

public static DataPostResponse of(Post post) {
public static DataPostResponse of(Post post, List<PostFile> postFiles) {
return DataPostResponse.builder()
.postId(post.getId())
.title(post.getTitle())
// .content(post.getContent())
.date(post.getCreatedAt().toString())
.isNotice(post.getTitle().equals("총학생회칙"))
.fileNames(postFiles.stream().map(postFile ->postFile.getSubCategory()).toList())
.files(postFiles.stream().map(postFile -> postFile.getUrl()).toList())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public record SimplePostResponse(
String content,
String date,
String onGoingStatus,
Integer like
Integer likeCount
) {
public static SimplePostResponse of(Post post,
Integer like){
Expand All @@ -21,7 +21,7 @@ public static SimplePostResponse of(Post post,
.content(post.getContent())
.date(post.getCreatedAt())
.onGoingStatus(post.getOnGoingStatus())
.like(like)
.likeCount(like)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
import java.util.List;
@Builder(access = AccessLevel.PRIVATE)
public record TopLikedPostListResponse(
List<SimplePostResponse> posts,
List<SimplePostResponse> postListResDto,
PageInfo pageInfo
) {
public static TopLikedPostListResponse of(List<SimplePostResponse> posts, PageInfo pageInfo){
public static TopLikedPostListResponse of(List<SimplePostResponse> postListResDto, PageInfo pageInfo){
return TopLikedPostListResponse.builder()
.posts(posts)
.postListResDto(postListResDto)
.pageInfo(pageInfo)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
Expand All @@ -14,6 +15,7 @@
@RequiredArgsConstructor
@RequestMapping("/onboarding")
@RestController
@Tag(name = "on-boarding", description = "온보딩 api, 온보딩 실패 시 메일로 문의하는 api")
public class OnBoardingController {
private final OnBoardingService onBoardingService;

Expand All @@ -30,9 +32,11 @@ public ResponseEntity<ApiResponse<?>> createUserOnBoarding(@Parameter(hidden = t
return ApiResponse.success(null);
}

@Operation(summary = "온보딩 실패 시 메일로 문의하는 api", description = """
온보딩 실패 시 메일로 문의하는 api 입니다.
""")
@PostMapping("/mail")
public ResponseEntity<ApiResponse<?>> sendEmail(@Parameter(hidden = true) @UserId Long userId,
@RequestBody OnBoardingEmailRequest onBoardingEmailRequest) {
public ResponseEntity<ApiResponse<?>> sendEmail(@RequestBody OnBoardingEmailRequest onBoardingEmailRequest) {
onBoardingService.sendEmail(onBoardingEmailRequest);
return ApiResponse.success(null);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package ussum.homepage.domain.comment.service.formatter;

@FunctionalInterface
public interface QuadFunction<T, U, V, W, R> {
R apply(T t, U u, V v, W w);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import ussum.homepage.domain.comment.service.PostCommentReader;
import ussum.homepage.domain.member.service.MemberManager;
import ussum.homepage.domain.post.Post;
Expand All @@ -24,45 +25,44 @@ public class PostStatusProcessor {
private final PostReactionReader postReactionReader;
private final MemberManager memberManager;

public String processStatus(Post post) {
public Post processStatus(Post post) {
//현재 게시물 상태 checking
String currentStatus = Optional.ofNullable(post.getOnGoingStatus())
.orElseThrow(() -> new PostException(POST_ONGOING_STATUS_IS_NOT_UPDATED));
//게시물의 좋아요 수를 미리 가져옴
Integer likeCountOfPost = postReactionReader.countPostReactionsByType(post.getId(), "like");
switch (currentStatus) {
case "진행중":
return handleInProgressStatus(post,likeCountOfPost);
return handleInProgressStatus(post, likeCountOfPost);
case "접수완료":
return handleReceivedStatus(post);
}
return currentStatus;
return post;
}

/**
* 해당 로직은 실제 청원게시물의 OnGoingStatus를 변경하는 로직
*/
public String updatePostOngoingStatus(Long postId, String onGoingStatus) {
return postRepository.updatePostOngoingStatus(postId, onGoingStatus, Category.getEnumCategoryCodeFromStringCategoryCode(onGoingStatus)).getOnGoingStatus();
public Post updatePostCategoryAndOngoingStatus(Long postId, String onGoingStatus) {
return postRepository.updatePostOngoingStatus(postId, onGoingStatus, Category.getEnumCategoryCodeFromStringCategoryCode(onGoingStatus));
}

/**
* '진행중' 청원일 때 30일이 지난 시점에 좋아요 100개를 달성하지 못하면 '종료됨'
* '진행중' 청원일 때 30일이 지난 시점에 좋아요 100개를 달성하면 '접수된' 청원으로 변경
*/
private String handleInProgressStatus(Post post, Integer likeCountOfPost) {
// LocalDateTime createdAt = LocalDateTime.parse(post.getCreatedAt());
private Post handleInProgressStatus(Post post, Integer likeCountOfPost) {
LocalDateTime createdAt = DateUtils.parseHourMinSecFromCustomString(post.getCreatedAt());
// 30일이 경과한 경우
if (LocalDateTime.now().isAfter(createdAt.plusDays(30))) {
// 30일 동안 좋아요 100개를 달성하지 못한 경우에만 종료됨 상태로 변경
if (likeCountOfPost < 100) {
return updatePostOngoingStatus(post.getId(), "종료됨");
} else return updatePostOngoingStatus(post.getId(), "접수완료");
return updatePostCategoryAndOngoingStatus(post.getId(), "종료됨");
} else return updatePostCategoryAndOngoingStatus(post.getId(), "접수완료");
} else {
if (likeCountOfPost >= 100) {
return updatePostOngoingStatus(post.getId(), "접수완료");
} else return "진행중";
return updatePostCategoryAndOngoingStatus(post.getId(), "접수완료");
} else return post;
}
// 30일 이내면 아직 상태를 변경하지 않음
// return "IN_PROGRESS";
Expand All @@ -71,11 +71,11 @@ private String handleInProgressStatus(Post post, Integer likeCountOfPost) {
/**
* '접수된' 청원에서 관리자가 댓글을 달면 '답변완료' 청원으로 변경
*/
private String handleReceivedStatus(Post post) {
private Post handleReceivedStatus(Post post) {
if (isAnsweredByAdmin(post)) {
return updatePostOngoingStatus(post.getId(),"답변완료");
return updatePostCategoryAndOngoingStatus(post.getId(),"답변완료");
}
return "접수완료";
return post;
}

/**
Expand Down
Loading

0 comments on commit 4cc0db3

Please sign in to comment.