Skip to content

Commit

Permalink
Merge pull request #225 from sharemindteam/fix/211-envelop-consult
Browse files Browse the repository at this point in the history
fix: 아이디 그대로 넘겨줘서 사용자가 유추할 수 있는 부분 수정
  • Loading branch information
aeyongdodam authored Jul 21, 2024
2 parents e549503 + ff09e24 commit 21911a5
Show file tree
Hide file tree
Showing 17 changed files with 149 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@
import com.example.sharemind.comment.dto.response.CommentGetResponse;

import java.util.List;
import java.util.UUID;

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

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

void createComment(CommentCreateRequest commentCreateRequest, Long customerId);

Comment getCommentByCommentId(Long commentId);

void updateCustomerChosenComment(Long postId, Long commentId, Long customerId);
void updateCustomerChosenComment(UUID postUuid, Long commentId, Long customerId);

Boolean getIsCommentOwner(Long postId, Long customerId);
Boolean getIsCommentOwner(UUID postUuid, Long customerId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.example.sharemind.post.application.PostService;
import com.example.sharemind.post.content.PostStatus;
import com.example.sharemind.post.domain.Post;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -33,7 +34,8 @@ public class CommentServiceImpl implements CommentService {
private final CommentLikeRepository commentLikeRepository;

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

Expand All @@ -46,7 +48,8 @@ public List<CommentGetResponse> getCounselorComments(Long postId, Long customerI
}

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

Expand All @@ -70,7 +73,8 @@ public List<CommentGetResponse> getCustomerComments(Long postId, Long customerId
@Transactional
@Override
public void createComment(CommentCreateRequest commentCreateRequest, Long customerId) {
Post post = postService.checkAndGetCounselorPost(commentCreateRequest.getPostId(),
Long postId = postService.getPostByPostUuid(commentCreateRequest.getPostUuid()).getPostId();
Post post = postService.checkAndGetCounselorPost(postId,
customerId);
Customer customer = post.getCustomer();
Counselor counselor = counselorService.getCounselorByCustomerId(customerId);
Expand All @@ -95,9 +99,9 @@ public Comment getCommentByCommentId(Long commentId) {

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

Expand All @@ -110,8 +114,8 @@ public void updateCustomerChosenComment(Long postId, Long commentId, Long custom
}

@Override
public Boolean getIsCommentOwner(Long postId, Long customerId) {
Post post = postService.getPostByPostId(postId);
public Boolean getIsCommentOwner(UUID postUuid, Long customerId) {
Post post = postService.getPostByPostUuid(postUuid);
Counselor counselor = counselorService.getCounselorByCustomerId(customerId);

return commentRepository.findByPostAndCounselorAndIsActivatedIsTrue(post, counselor) != null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
import com.example.sharemind.post.domain.Post;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import java.util.UUID;
import lombok.Getter;

@Getter
public class CommentCreateRequest {

@Schema(description = "상담 id")
@NotNull
private Long postId;
private UUID postUuid;

@Schema(description = "content")
private String content;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
Expand All @@ -31,7 +32,7 @@ public class CommentController {

@Operation(summary = "상담사 사이드 일대다 상담 질문 단건의 댓글 조회", description = """
- 상담사가 일대다 상담 질문에 대답하기 위한 상담 질문 단건의 댓글 조회
- 주소 형식: /api/v1/comments/counselors/1""")
- 주소 형식: /api/v1/comments/counselors/dd88d0d8-fc70-4394-b64a-726f31f48f9e""")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "조회 성공"),
@ApiResponse(responseCode = "400", description = "1. 진행중이지 않은 상담\n 2. 마감된 상담 중 상담사 본인이 답변을 작성하지 않은 상담",
Expand All @@ -43,7 +44,7 @@ public class CommentController {
@Parameter(name = "postId", description = "일대다 상담 ID")
})
@GetMapping("/counselors/{postId}")
public ResponseEntity<List<CommentGetResponse>> getCounselorComments(@PathVariable Long postId,
public ResponseEntity<List<CommentGetResponse>> getCounselorComments(@PathVariable UUID postId,
@AuthenticationPrincipal CustomUserDetails customUserDetails) {
return ResponseEntity.ok(commentService.getCounselorComments(postId,
customUserDetails.getCustomer().getCustomerId()));
Expand Down Expand Up @@ -83,7 +84,7 @@ public ResponseEntity<Void> createComments(
@Parameter(name = "postId", description = "일대다 상담 ID")
})
@GetMapping("/customers/{postId}")
public ResponseEntity<List<CommentGetResponse>> getCustomerComments(@PathVariable Long postId,
public ResponseEntity<List<CommentGetResponse>> getCustomerComments(@PathVariable UUID postId,
@AuthenticationPrincipal CustomUserDetails customUserDetails) {
return ResponseEntity.ok(commentService.getCustomerComments(postId,
customUserDetails == null ? 0 : customUserDetails.getCustomer().getCustomerId()));
Expand Down Expand Up @@ -112,7 +113,7 @@ public ResponseEntity<List<CommentGetResponse>> getCustomerComments(@PathVariabl
@Parameter(name = "commentId", description = "답변 ID")
})
@PatchMapping("/customers/{postId}")
public ResponseEntity<Void> updateCustomerChosenComment(@PathVariable Long postId, @RequestParam Long commentId,
public ResponseEntity<Void> updateCustomerChosenComment(@PathVariable UUID postId, @RequestParam Long commentId,
@AuthenticationPrincipal CustomUserDetails customUserDetails) {
commentService.updateCustomerChosenComment(postId, commentId, customUserDetails.getCustomer().getCustomerId());
return ResponseEntity.ok().build();
Expand All @@ -131,7 +132,7 @@ public ResponseEntity<Void> updateCustomerChosenComment(@PathVariable Long postI
@Parameter(name = "postId", description = "일대다 상담 ID"),
})
@GetMapping("/counselors/authentication/{postId}")
public Boolean getIsCommentOwner(@PathVariable Long postId,
public Boolean getIsCommentOwner(@PathVariable UUID postId,
@AuthenticationPrincipal CustomUserDetails customUserDetails) {
return commentService.getIsCommentOwner(postId, customUserDetails.getCustomer().getCustomerId());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.example.sharemind.review.domain.Review;
import com.example.sharemind.customer.domain.Customer;
import jakarta.persistence.*;
import java.util.UUID;
import lombok.*;

import java.time.LocalDateTime;
Expand All @@ -28,6 +29,9 @@ public class Consult extends BaseEntity {
@Column(name = "consult_id")
private Long consultId;

@Column(columnDefinition = "BINARY(16)", updatable = false)
private UUID consultUuid;

@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "customer_id")
private Customer customer;
Expand Down Expand Up @@ -66,6 +70,11 @@ public class Consult extends BaseEntity {
@JoinColumn(name = "payment_id", unique = true)
private Payment payment;

@PrePersist
public void prePersist() {
this.consultUuid = UUID.randomUUID();
}

@Builder
public Consult(Customer customer, Counselor counselor, Long cost, ConsultType consultType) {
this.customer = customer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.example.sharemind.global.utils.*;
import com.example.sharemind.letter.dto.response.LetterGetResponse;
import io.swagger.v3.oas.annotations.media.Schema;
import java.util.UUID;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -47,8 +48,8 @@ public class ChatLetterGetResponse {
@Schema(description = "리뷰 작성 여부")
private final Boolean reviewCompleted;

@Schema(description = "상담 아이디")
private final Long consultId;
@Schema(description = "상담 uuid")
private final UUID consultUuid;

@Schema(description = "채팅/편지 여부")
private final Boolean isChat;
Expand All @@ -57,7 +58,8 @@ public static ChatLetterGetResponse of(LetterGetResponse letterGetResponse) {
return new ChatLetterGetResponse(letterGetResponse.getLetterId(), letterGetResponse.getConsultStyle(),
letterGetResponse.getLetterStatus(), letterGetResponse.getOpponentName(),
letterGetResponse.getUpdatedAt(), letterGetResponse.getRecentContent(), null,
null, letterGetResponse.getReviewCompleted(), letterGetResponse.getConsultId(),
null, letterGetResponse.getReviewCompleted(),
letterGetResponse.getConsultUuid(),
IS_LETTER);
}

Expand All @@ -70,7 +72,7 @@ public static ChatLetterGetResponse of(String nickname, int unreadMessageCount,
chat.changeChatStatusForChatList().getDisplayName(), nickname,
TimeUtil.getUpdatedAt(chat.getConsult().getUpdatedAt()),
counselor.getNickname() + "님께 고민내용을 남겨주세요. " + counselor.getNickname() + "님이 24시간 내에 채팅 요청을 드립니다.",
null, 0, reviewCompleted, chat.getConsult().getConsultId(),
null, 0, reviewCompleted, chat.getConsult().getConsultUuid(),
IS_CHAT);
}
String chatMessageContent = chatMessage.getContent();
Expand All @@ -87,6 +89,6 @@ public static ChatLetterGetResponse of(String nickname, int unreadMessageCount,
chat.changeChatStatusForChatList().getDisplayName(), nickname,
TimeUtil.getUpdatedAt(chatMessage.getUpdatedAt()),
chatMessageContent, chatMessage.getIsCustomer(), unreadMessageCount, reviewCompleted,
chat.getConsult().getConsultId(), IS_CHAT);
chat.getConsult().getConsultUuid(), IS_CHAT);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.example.sharemind.letter.domain.Letter;
import com.example.sharemind.letterMessage.domain.LetterMessage;
import io.swagger.v3.oas.annotations.media.Schema;
import java.util.UUID;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -35,8 +36,8 @@ public class LetterGetResponse {
@Schema(description = "리뷰 작성 여부")
private final Boolean reviewCompleted;

@Schema(description = "상담 아이디")
private final Long consultId;
@Schema(description = "상담 uuid")
private final UUID consultUuid;

public static ChatLetterGetResponse of(Letter letter, LetterMessage recentMessage, Boolean isCustomer) {
String letterStatus;
Expand All @@ -58,12 +59,13 @@ public static ChatLetterGetResponse of(Letter letter, LetterMessage recentMessag
if (recentMessage == null) {
return ChatLetterGetResponse.of(new LetterGetResponse(letter.getLetterId(), letterStatus,
letter.getConsult().getCounselor().getConsultStyle().getDisplayName(), opponentName,
TimeUtil.getUpdatedAt(letter.getConsult().getUpdatedAt()), null, reviewCompleted, letter.getConsult().getConsultId()));
TimeUtil.getUpdatedAt(letter.getConsult().getUpdatedAt()), null, reviewCompleted,
letter.getConsult().getConsultUuid()));
}

return ChatLetterGetResponse.of(new LetterGetResponse(letter.getLetterId(), letterStatus,
letter.getConsult().getCounselor().getConsultStyle().getDisplayName(), opponentName,
TimeUtil.getUpdatedAt((recentMessage.getUpdatedAt())), recentMessage.getContent(), reviewCompleted,
letter.getConsult().getConsultId()));
letter.getConsult().getConsultUuid()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.example.sharemind.searchWord.dto.request.SearchWordPostFindRequest;
import java.time.LocalDateTime;
import java.util.List;
import java.util.UUID;

public interface PostService {

Expand All @@ -19,30 +20,32 @@ public interface PostService {

Post getPostByPostId(Long postId);

Post getPostByPostUuid(UUID postUuid);

void updatePost(PostUpdateRequest postUpdateRequest, Long customerId);

PostGetResponse getPost(Long postId, Long customerId);
PostGetResponse getPost(UUID postId, Long customerId);

List<PostGetCustomerListResponse> getPostsByCustomer(Boolean filter, Long postId,
List<PostGetCustomerListResponse> getPostsByCustomer(Boolean filter, UUID postId,
Long customerId);

List<PostGetCounselorListResponse> getPostsByCounselor(Boolean filter, Long postId,
List<PostGetCounselorListResponse> getPostsByCounselor(Boolean filter, UUID postUuid,
Long customerId);

List<PostGetPublicListResponse> getPublicPostsByCustomer(Long postId, LocalDateTime finishedAt,
List<PostGetPublicListResponse> getPublicPostsByCustomer(UUID postUuid, LocalDateTime finishedAt,
Long customerId);

List<PostGetPublicListResponse> getPopularityPosts(Long postId, LocalDateTime finishedAt,
List<PostGetPublicListResponse> getPopularityPosts(UUID postUuid, LocalDateTime finishedAt,
Long customerId);

List<Long> getRandomPosts();
List<UUID> getRandomPosts();

PostGetResponse getCounselorPostContent(Long postId, Long customerId);
PostGetResponse getCounselorPostContent(UUID postId, Long customerId);

Post checkAndGetCounselorPost(Long postId, Long customerId);

List<Post> getPostByWordWithPagination(SearchWordPostFindRequest searchWordPostFindRequest,
String sortType);

Boolean getIsPostOwner(Long postId, Long customerId);
Boolean getIsPostOwner(UUID postUuid, Long customerId);
}
Loading

0 comments on commit 21911a5

Please sign in to comment.