Skip to content

Commit

Permalink
Merge pull request #158 from fastcampus-711/develop
Browse files Browse the repository at this point in the history
[정기배포] 240611
  • Loading branch information
having-dlrow authored Jun 11, 2024
2 parents da723c4 + 15ea0af commit b5d0268
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 37 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/aptner/v3/board/comment/CommentDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public CommentDto.CommentResponse toResponseDto() {
.parentCommentId(dto.getParentCommentId())
// comment info
.reactionColumns(isSecret ? null : dto.getReactionColumnsDto())
.reactionType(isSecret ? ReactionType.DEFAULT : dto.getReactionType())
.reactionType(isSecret || dto.getReactionType() == null ? ReactionType.DEFAULT : dto.getReactionType())
.visible(dto.isVisible())
.isTop(dto.isTop())
.isAdminComment(isAdmin(dto.getMemberDto()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

import com.aptner.v3.board.category.BoardGroup;
import com.aptner.v3.board.common_post.domain.CommonPost;
import com.aptner.v3.board.complain.Complain;
import com.aptner.v3.board.complain.ComplainStatus;
import com.aptner.v3.board.market.Market;
import com.aptner.v3.board.market.MarketStatus;
import com.aptner.v3.board.qna.Qna;
import com.aptner.v3.board.qna.QnaStatus;
import com.aptner.v3.board.qna.Status;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -35,26 +38,36 @@ public static <E extends CommonPost> Specification<E> hasCategoryId(Long categor
}

public static <E extends CommonPost> Specification<E> hasStatus(Status status, BoardGroup boardGroup) {
return (root, query, criteriaBuilder) -> {
if (status != null) {
log.debug("specification - status : {} {}", status, boardGroup.getTable());
if (boardGroup.getTable().equals(BoardGroup.MARKETS.getTable())) {
log.debug("마켓");
return criteriaBuilder.equal(root.get("status"), (MarketStatus) status);
} else if (boardGroup.getTable().equals(BoardGroup.COMPLAINT.getTable())) {
log.debug("complaint");
return criteriaBuilder.equal(root.get("status"), (ComplainStatus) status);
} else if (boardGroup.getTable().equals(BoardGroup.QNAS.getTable())) {
log.debug("qna");
return criteriaBuilder.equal(root.get("status"), (QnaStatus) status);
} else {
log.debug("etc");
return criteriaBuilder.conjunction();
}
} else {
return criteriaBuilder.conjunction();
}
};
if (status == null) {
return (root, query, criteriaBuilder) -> criteriaBuilder.conjunction();
}

switch (boardGroup.getTable()) {
case "MarketPost":
log.debug("specification - market status : {} {}", status, boardGroup.getTable());
return (Specification<E>) marketHasStatus((MarketStatus) status);
case "ComplaintPost":
log.debug("specification - complaint status : {} {}", status, boardGroup.getTable());
return (Specification<E>) complainHasStatus((ComplainStatus) status);
case "QnaPost":
log.debug("specification - qna status : {} {}", status, boardGroup.getTable());
return (Specification<E>) qnaHasStatus((QnaStatus) status);
default:
log.debug("specification - etc");
return (root, query, criteriaBuilder) -> criteriaBuilder.conjunction();
}
}

private static Specification<Market> marketHasStatus(MarketStatus status) {
return (root, query, criteriaBuilder) -> criteriaBuilder.equal(criteriaBuilder.treat(root, Market.class).get("status"), status);
}

private static Specification<Complain> complainHasStatus(ComplainStatus status) {
return (root, query, criteriaBuilder) -> criteriaBuilder.equal(criteriaBuilder.treat(root, Complain.class).get("status"), status);
}

private static Specification<Qna> qnaHasStatus(QnaStatus status) {
return (root, query, criteriaBuilder) -> criteriaBuilder.equal(criteriaBuilder.treat(root, Qna.class).get("status"), status);
}

public static <E extends CommonPost> Specification<E> hasKeyword(String keyword) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ public static boolean isOwner(CommonPostDto dto) {
}

public static boolean isNew(CommonPostDto dto) {
LocalDateTime fourteenDaysAgo = LocalDateTime.now().minusHours(48);
return dto.getCreatedAt().isAfter(fourteenDaysAgo);
LocalDateTime fortyEightHoursAgo = LocalDateTime.now().minusHours(48);
return dto.getCreatedAt().isAfter(fortyEightHoursAgo);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ public ApiResponse<?> setStatus(
@RequestBody ComplainStatusDto.ComplainStatusRequest request
, @AuthenticationPrincipal CustomUserDetails user) {

ComplainDto dto = ComplainDto.of(
ComplainStatusDto dto = ComplainStatusDto.of(
getBoardGroup(),
user.toDto(),
ComplainDto.ComplainRequest.of(request.getPostId(), null)
request
);

return ResponseUtil.ok(complainService.setStatus(dto).toResponse());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import com.aptner.v3.board.common_post.CommonPostRepository;
import com.aptner.v3.board.common_post.service.CommonPostService;
import com.aptner.v3.board.complain.dto.ComplainDto;
import com.aptner.v3.board.complain.dto.ComplainStatusDto;
import com.aptner.v3.global.error.ErrorCode;
import com.aptner.v3.global.exception.PostException;
import com.aptner.v3.member.repository.MemberRepository;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
Expand All @@ -25,8 +28,9 @@ public ComplainService(MemberRepository memberRepository,
this.complainRepository = complainRepository;
}

public ComplainDto setStatus(ComplainDto dto) {
Complain complain = verifyPost(dto);
public ComplainDto setStatus(ComplainStatusDto dto) {
// check
Complain complain = complainRepository.findById(dto.getPostId()).orElseThrow(() -> new PostException(ErrorCode._NOT_FOUND));
// update
complain.setStatus(dto.getStatus());
complainRepository.flush();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.aptner.v3.board.complain.dto;

import com.aptner.v3.board.category.BoardGroup;
import com.aptner.v3.board.complain.ComplainStatus;
import com.aptner.v3.member.dto.MemberDto;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand All @@ -20,7 +22,18 @@ public class ComplainStatusDto {

Long postId;
ComplainStatus status;
MemberDto memberDto;

public static ComplainStatusDto of(BoardGroup boardGroup, MemberDto memberDto, ComplainStatusDto.ComplainStatusRequest request) {
return ComplainStatusDto.builder()
// post
.postId(request.getPostId())
// member
.memberDto(memberDto)
// complain
.status(request.getStatus())
.build();
}
@Getter
@AllArgsConstructor
@NoArgsConstructor
Expand Down
20 changes: 10 additions & 10 deletions src/main/resources/data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -289,18 +289,18 @@ insert into market (id, type, status, price) values (129, '무료나눔','RESERV
insert into market (id, type, status, price) values (130, '무료나눔','RESERVED', 9000);

-- qna comments
insert into comment (post_id,content,created_at,created_by,deleted,is_top,user_id,modified_at,modified_by,parent_comment_id,count_reaction_type_bad,count_reaction_type_good,visible,id) values (41,'QNA 댓글입니다.','2024-06-02 00:14:23','user',false,false,21,'2024-06-02 00:14:23','user',NULL,0,0,true,default);
insert into comment (post_id,content,created_at,created_by,deleted,is_top,user_id,modified_at,modified_by,parent_comment_id,count_reaction_type_bad,count_reaction_type_good,visible,id) values (41,'QNA 대 댓글입니다.','2024-06-02 00:14:23','user',false,false,21,'2024-06-02 00:14:23','user',1,0,0,true,default);
insert into comment (post_id,content,created_at,created_by,deleted,is_top,user_id,modified_at,modified_by,parent_comment_id,count_reaction_type_bad,count_reaction_type_good,visible,id) values (41,'QNA 대 댓글입니다.2','2024-06-02 00:14:23','user',false,false,21,'2024-06-02 00:14:23','user',1,3,0,true,default);
insert into comment (post_id,content,created_at,created_by,deleted,is_top,user_id,modified_at,modified_by,parent_comment_id,count_reaction_type_bad,count_reaction_type_good,visible,id) values (41,'QNA 어드민 작성 댓글입니다.상단','2024-06-02 00:14:23','admin',false,true,22,'2024-06-02 00:14:23','admin',NULL,1,0,true,default); -- admin comment
insert into comment (post_id,content,created_at,created_by,deleted,is_top,user_id,modified_at,modified_by,parent_comment_id,count_reaction_type_bad,count_reaction_type_good,visible,id) values (41,'QNA 댓글입니다.3','2024-06-02 00:14:23','user',false,false,21,'2024-06-02 00:14:23','user',NULL,1,0,true,default);
insert into comment (post_id,content,created_at,created_by,deleted,is_top,user_id,modified_at,modified_by,parent_comment_id,count_reaction_type_bad,count_reaction_type_good,visible,id) values (41,'QNA 댓글입니다.4','2024-06-02 00:14:23','user',false,false,21,'2024-06-02 00:14:23','user',NULL,1,0,true,default);
insert into comment (post_id,content,created_at,created_by,deleted,is_top,user_id,modified_at,modified_by,parent_comment_id,count_reaction_type_bad,count_reaction_type_good,visible,id) values (41,'QNA 댓글입니다.','2024-06-02 00:14:23','user',false,false,1,'2024-06-02 00:14:23','user',NULL,0,0,true,default);
insert into comment (post_id,content,created_at,created_by,deleted,is_top,user_id,modified_at,modified_by,parent_comment_id,count_reaction_type_bad,count_reaction_type_good,visible,id) values (41,'QNA 대 댓글입니다.','2024-06-02 00:14:23','user',false,false,1,'2024-06-02 00:14:23','user',1,0,0,true,default);
insert into comment (post_id,content,created_at,created_by,deleted,is_top,user_id,modified_at,modified_by,parent_comment_id,count_reaction_type_bad,count_reaction_type_good,visible,id) values (41,'QNA 대 댓글입니다.2','2024-06-02 00:14:23','user',false,false,1,'2024-06-02 00:14:23','user',1,3,0,true,default);
insert into comment (post_id,content,created_at,created_by,deleted,is_top,user_id,modified_at,modified_by,parent_comment_id,count_reaction_type_bad,count_reaction_type_good,visible,id) values (41,'QNA 어드민 작성 댓글입니다.상단','2024-06-02 00:14:23','admin',false,true,2,'2024-06-02 00:14:23','admin',NULL,1,0,true,default); -- admin comment
insert into comment (post_id,content,created_at,created_by,deleted,is_top,user_id,modified_at,modified_by,parent_comment_id,count_reaction_type_bad,count_reaction_type_good,visible,id) values (41,'QNA 댓글입니다.3','2024-06-02 00:14:23','user',false,false,1,'2024-06-02 00:14:23','user',NULL,1,0,true,default);
insert into comment (post_id,content,created_at,created_by,deleted,is_top,user_id,modified_at,modified_by,parent_comment_id,count_reaction_type_bad,count_reaction_type_good,visible,id) values (41,'QNA 댓글입니다.4','2024-06-02 00:14:23','user',false,false,1,'2024-06-02 00:14:23','user',NULL,1,0,true,default);

-- complain comments
insert into comment (post_id,content,created_at,created_by,deleted,is_top,user_id,modified_at,modified_by,parent_comment_id,count_reaction_type_bad,count_reaction_type_good,visible,id) values (61,'댓글입니다.','2024-06-02 00:14:23','user',false,false,22,'2024-06-02 00:14:23','user',NULL,0,0,true,default);
insert into comment (post_id,content,created_at,created_by,deleted,is_top,user_id,modified_at,modified_by,parent_comment_id,count_reaction_type_bad,count_reaction_type_good,visible,id) values (61,'대 댓글입니다.','2024-06-02 00:14:23','user',false,false,22,'2024-06-02 00:14:23','user',7,0,0,true,default);
insert into comment (post_id,content,created_at,created_by,deleted,is_top,user_id,modified_at,modified_by,parent_comment_id,count_reaction_type_bad,count_reaction_type_good,visible,id) values (61,'대 댓글입니다.2','2024-06-02 00:14:23','user',false,false,22,'2024-06-02 00:14:23','user',7,3,0,true,default);
insert into comment (post_id,content,created_at,created_by,deleted,is_top,user_id,modified_at,modified_by,parent_comment_id,count_reaction_type_bad,count_reaction_type_good,visible,id) values (61,'댓글입니다.2','2024-06-02 00:14:23','admin',false,true,22,'2024-06-02 00:14:23','admin',NULL,1,0,true,default); -- admin comment
insert into comment (post_id,content,created_at,created_by,deleted,is_top,user_id,modified_at,modified_by,parent_comment_id,count_reaction_type_bad,count_reaction_type_good,visible,id) values (61,'댓글입니다.','2024-06-02 00:14:23','user',false,false,2,'2024-06-02 00:14:23','user',NULL,0,0,true,default);
insert into comment (post_id,content,created_at,created_by,deleted,is_top,user_id,modified_at,modified_by,parent_comment_id,count_reaction_type_bad,count_reaction_type_good,visible,id) values (61,'대 댓글입니다.','2024-06-02 00:14:23','user',false,false,2,'2024-06-02 00:14:23','user',7,0,0,true,default);
insert into comment (post_id,content,created_at,created_by,deleted,is_top,user_id,modified_at,modified_by,parent_comment_id,count_reaction_type_bad,count_reaction_type_good,visible,id) values (61,'대 댓글입니다.2','2024-06-02 00:14:23','user',false,false,2,'2024-06-02 00:14:23','user',7,3,0,true,default);
insert into comment (post_id,content,created_at,created_by,deleted,is_top,user_id,modified_at,modified_by,parent_comment_id,count_reaction_type_bad,count_reaction_type_good,visible,id) values (61,'댓글입니다.2','2024-06-02 00:14:23','admin',false,true,2,'2024-06-02 00:14:23','admin',NULL,1,0,true,default); -- admin comment

insert into reaction(id, user_id, target_id, reaction_type, dtype) values (1, 1, 1, 0, 'PostReaction');
insert into reaction(id, user_id, target_id, reaction_type, dtype) values (2, 1, 2, 1, 'CommentReaction');
Expand Down

0 comments on commit b5d0268

Please sign in to comment.