Skip to content

Commit

Permalink
Merge pull request #158 from sharemindteam/feature/156-comment-customer
Browse files Browse the repository at this point in the history
feat: 구매자 사이드 일대다 상담 댓글 조회 구현
  • Loading branch information
letskuku authored Mar 26, 2024
2 parents e889f25 + f7323ee commit f52b1e1
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import java.util.List;

public interface CommentService {
List<CommentGetResponse> getCommentsByPost(Long postId, Long customerId);
List<CommentGetResponse> getCounselorComments(Long postId, Long customerId);

List<CommentGetResponse> getCustomerComments(Long postId, Long customerId);

void createComment(CommentCreateRequest commentCreateRequest, Long customerId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
public class CommentServiceImpl implements CommentService {

private static final Integer MAX_COMMENTS = 5;
private static final Boolean COMMENT_IS_NOT_LIKED = false;

private final PostService postService;
private final CounselorService counselorService;
Expand All @@ -34,7 +35,7 @@ public class CommentServiceImpl implements CommentService {
private final CommentLikeRepository commentLikeRepository;

@Override
public List<CommentGetResponse> getCommentsByPost(Long postId, Long customerId) {
public List<CommentGetResponse> getCounselorComments(Long postId, Long customerId) {
Post post = postService.checkAndGetCounselorPost(postId, customerId);
Customer customer = customerService.getCustomerByCustomerId(customerId);

Expand All @@ -46,6 +47,28 @@ public List<CommentGetResponse> getCommentsByPost(Long postId, Long customerId)
.toList();
}

@Override
public List<CommentGetResponse> getCustomerComments(Long postId, Long customerId) {
Post post = postService.getPostByPostId(postId);
post.checkReadAuthority(customerId);

List<Comment> comments = commentRepository.findByPostAndIsActivatedIsTrue(post);

if (customerId != 0) {
Customer customer = customerService.getCustomerByCustomerId(customerId);

return comments.stream()
.map(comment -> CommentGetResponse.of(comment,
commentLikeRepository.existsByCommentAndCustomerAndIsActivatedIsTrue(
comment, customer)))
.toList();
}

return comments.stream()
.map(comment -> CommentGetResponse.of(comment, COMMENT_IS_NOT_LIKED))
.toList();
}

@Transactional
@Override
public void createComment(CommentCreateRequest commentCreateRequest, Long customerId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,35 +34,57 @@ public class CommentController {
- 주소 형식: /api/v1/comments/counselors/1""")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "조회 성공"),
@ApiResponse(responseCode = "400", description = "1. 진행중이지 않은 상담 2. 마감된 상담 중 상담사 본인이 답변을 작성하지 않은 상담",
@ApiResponse(responseCode = "400", description = "1. 진행중이지 않은 상담\n 2. 마감된 상담 중 상담사 본인이 답변을 작성하지 않은 상담",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = CustomExceptionResponse.class))
)
})
@Parameters({
@Parameter(name = "postId", description = """
- 일대다 상담 ID""")
@Parameter(name = "postId", description = "일대다 상담 ID")
})
@GetMapping("/counselors/{postId}")
public ResponseEntity<List<CommentGetResponse>> getCounselorComments(@PathVariable Long postId,
@AuthenticationPrincipal CustomUserDetails customUserDetails) {
return ResponseEntity.ok(commentService.getCommentsByPost(postId, customUserDetails.getCustomer().getCustomerId()));
@AuthenticationPrincipal CustomUserDetails customUserDetails) {
return ResponseEntity.ok(commentService.getCounselorComments(postId,
customUserDetails.getCustomer().getCustomerId()));
}

@Operation(summary = "상담사 사이드 일대다 상담 댓글 작성", description = """
- 상담사 사이드 일대다 상담 댓글 작성 API
- 주소 형식: /api/v1/comments/counselors""")
@ApiResponses({
@ApiResponse(responseCode = "201", description = "댓글 생성 성공"),
@ApiResponse(responseCode = "400", description = "1. 진행중이지 않은 상담 2. 마감된 상담 중 상담사 본인이 답변을 작성하지 않은 상담 3. 이미 답변을 작성한 상담",
@ApiResponse(responseCode = "400", description = "1. 진행중이지 않은 상담\n 2. 마감된 상담 중 상담사 본인이 답변을 작성하지 않은 상담 3. 이미 답변을 작성한 상담",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = CustomExceptionResponse.class))
)
})
@PostMapping("/counselors")
public ResponseEntity<Void> createComments(@RequestBody CommentCreateRequest commentCreateRequest,
@AuthenticationPrincipal CustomUserDetails customUserDetails) {
commentService.createComment(commentCreateRequest, customUserDetails.getCustomer().getCustomerId());
public ResponseEntity<Void> createComments(
@RequestBody CommentCreateRequest commentCreateRequest,
@AuthenticationPrincipal CustomUserDetails customUserDetails) {
commentService.createComment(commentCreateRequest,
customUserDetails.getCustomer().getCustomerId());
return ResponseEntity.status(HttpStatus.CREATED).build();
}

@Operation(summary = "구매자 사이드 일대다 상담 질문 단건의 댓글 목록 조회", description = """
- 구매자&비로그인 사용자 일대다 상담 질문 단건의 댓글 목록 조회
- 로그인한 사용자일 경우 헤더에 accessToken을 넣어주세요""")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "조회 성공"),
@ApiResponse(responseCode = "400", description = "접근 권한이 없는 상담(다른 회원의 비공개 상담 접근 시도)",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = CustomExceptionResponse.class))
)
})
@Parameters({
@Parameter(name = "postId", description = "일대다 상담 ID")
})
@GetMapping("/customers/{postId}")
public ResponseEntity<List<CommentGetResponse>> getCustomerComments(@PathVariable Long postId,
@AuthenticationPrincipal CustomUserDetails customUserDetails) {
return ResponseEntity.ok(commentService.getCustomerComments(postId,
customUserDetails == null ? 0 : customUserDetails.getCustomer().getCustomerId()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
"/counselor.html").permitAll()
.requestMatchers(HttpMethod.GET, "/api/v1/posts/{postId}").permitAll()
.requestMatchers(HttpMethod.GET, "/api/v1/posts/customers/public/**").permitAll()
.requestMatchers(HttpMethod.GET, "/api/v1/comments/customers/{postId}").permitAll()
.requestMatchers("/api/v1/admins/**").hasRole(ROLE_ADMIN)
.requestMatchers("/api/v1/letters/counselors/**", "/api/v1/reviews/counselors**").hasRole(ROLE_COUNSELOR)
.requestMatchers("/api/v1/chats/counselors/**").hasRole(ROLE_COUNSELOR)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,15 @@ public PostGetIsSavedResponse getIsSaved(Long postId) {
@Override
public PostGetResponse getPost(Long postId, Long customerId) {
Post post = getPostByPostId(postId);
post.checkReadAuthority(customerId);

if (customerId != 0) {
Customer customer = customerService.getCustomerByCustomerId(customerId);

post.checkReadAuthority(customerId);
return PostGetResponse.of(post,
postLikeRepository.existsByPostAndCustomerAndIsActivatedIsTrue(post, customer));
}

post.checkReadAuthority(customerId);
return PostGetResponse.of(post, POST_IS_NOT_LIKED);
}

Expand Down

0 comments on commit f52b1e1

Please sign in to comment.