Skip to content

Commit

Permalink
Merge pull request #170 from sharemindteam/feature/165-accept-post
Browse files Browse the repository at this point in the history
feat: 일대다 상담 채택 기능 구현
  • Loading branch information
aeyongdodam authored Apr 6, 2024
2 parents 7d4cafc + 41abcc1 commit 5c6d7c0
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ public interface CommentService {
void createComment(CommentCreateRequest commentCreateRequest, Long customerId);

Comment getCommentByCommentId(Long commentId);

void updateCustomerChosenComment(Long postId, Long commentId, Long customerId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.example.sharemind.customer.application.CustomerService;
import com.example.sharemind.customer.domain.Customer;
import com.example.sharemind.post.application.PostService;
import com.example.sharemind.post.content.PostStatus;
import com.example.sharemind.post.domain.Post;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -91,4 +92,20 @@ public Comment getCommentByCommentId(Long commentId) {
() -> new CommentException(CommentErrorCode.COMMENT_NOT_FOUND,
commentId.toString()));
}

@Transactional
@Override
public void updateCustomerChosenComment(Long postId, Long commentId, Long customerId) {
Customer customer = customerService.getCustomerByCustomerId(customerId);
Post post = postService.getPostByPostId(postId);
post.checkWriteAuthority(customer);
post.checkPostProceeding();

Comment comment = getCommentByCommentId(commentId);
comment.checkCommentIsForPost(post);

comment.updateIsChosen();

post.updatePostStatus(PostStatus.COMPLETED);
}
}
12 changes: 12 additions & 0 deletions src/main/java/com/example/sharemind/comment/domain/Comment.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.example.sharemind.comment.domain;

import com.example.sharemind.comment.exception.CommentErrorCode;
import com.example.sharemind.comment.exception.CommentException;
import com.example.sharemind.counselor.domain.Counselor;
import com.example.sharemind.global.common.BaseEntity;
import com.example.sharemind.post.domain.Post;
Expand Down Expand Up @@ -53,4 +55,14 @@ public void increaseTotalLike() {
public void decreaseTotalLike() {
this.totalLike--;
}

public void checkCommentIsForPost(Post post) {
if (!post.getPostId().equals(this.post.getPostId())) {
throw new CommentException(CommentErrorCode.COMMENT_NOT_FOUND, commentId.toString());
}
}

public void updateIsChosen() {
this.isChosen = true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class CommentController {
})
@GetMapping("/counselors/{postId}")
public ResponseEntity<List<CommentGetResponse>> getCounselorComments(@PathVariable Long postId,
@AuthenticationPrincipal CustomUserDetails customUserDetails) {
@AuthenticationPrincipal CustomUserDetails customUserDetails) {
return ResponseEntity.ok(commentService.getCounselorComments(postId,
customUserDetails.getCustomer().getCustomerId()));
}
Expand Down Expand Up @@ -84,8 +84,37 @@ public ResponseEntity<Void> createComments(
})
@GetMapping("/customers/{postId}")
public ResponseEntity<List<CommentGetResponse>> getCustomerComments(@PathVariable Long postId,
@AuthenticationPrincipal CustomUserDetails customUserDetails) {
@AuthenticationPrincipal CustomUserDetails customUserDetails) {
return ResponseEntity.ok(commentService.getCustomerComments(postId,
customUserDetails == null ? 0 : customUserDetails.getCustomer().getCustomerId()));
}

@Operation(summary = "구매자 사이드 답변 채택", description = """
- 구매자(게시물 작성자)일 경우 답변 채택을 하는 API""")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "채택 성공"),
@ApiResponse(responseCode = "400", description = "1. 진행중인 상담이 아닐 때",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = CustomExceptionResponse.class))
),
@ApiResponse(responseCode = "403", description = "1. 구매자가 작성하지 않은 postId로 요청했을 때",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = CustomExceptionResponse.class))
),
@ApiResponse(responseCode = "404", description = "1. 존재하지 않는 사용자일 때 2. 존재하지 않는 일대다 상담 ID 일 때 "
+ "3. 존재하지 않는 답변 ID 일 때 4. 해당 게시물에 달린 답변이 아닐 때",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = CustomExceptionResponse.class))
)
})
@Parameters({
@Parameter(name = "postId", description = "일대다 상담 ID"),
@Parameter(name = "commentId", description = "답변 ID")
})
@PatchMapping("/customers/{postId}")
public ResponseEntity<Void> updateCustomerChosenComment(@PathVariable Long postId, @RequestParam Long commentId,
@AuthenticationPrincipal CustomUserDetails customUserDetails) {
commentService.updateCustomerChosenComment(postId, commentId, customUserDetails.getCustomer().getCustomerId());
return ResponseEntity.ok().build();
}
}

0 comments on commit 5c6d7c0

Please sign in to comment.