Skip to content

Commit

Permalink
[OING-383] refact: saveVoiceComment RequestBody 변경 (#281)
Browse files Browse the repository at this point in the history
* refact: change request body in saveVoiceComment

* test: fix failedTest due to changes

* refact: delete unused import
  • Loading branch information
Ji-soo708 authored Jan 7, 2025
1 parent bf35c20 commit 3d5bc95
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.oing.domain.CommentType;
import com.oing.domain.Post;
import com.oing.domain.VoiceComment;
import com.oing.dto.request.CreatePostCommentRequest;
import com.oing.dto.request.CreatePostVoiceCommentRequest;
import com.oing.dto.request.PreSignedUrlRequest;
import com.oing.dto.response.DefaultResponse;
import com.oing.dto.response.PostCommentResponseV2;
Expand Down Expand Up @@ -34,7 +34,7 @@ public PreSignedUrlResponse requestPresignedUrl(PreSignedUrlRequest request, Str
@Override
@Transactional
public PostCommentResponseV2 createPostVoiceComment(String postId,
CreatePostCommentRequest request, String loginMemberId) {
CreatePostVoiceCommentRequest request, String loginMemberId) {
log.info("Member {} is trying to create voice-comment", loginMemberId);
Post post = postService.getMemberPostById(postId);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.oing.dto.request;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;

@Schema(description = "피드 게시물 음성 댓글 생성 요청")
public record CreatePostVoiceCommentRequest(
@NotBlank
@Size(max = 255)
@Schema(description = "fileUrl", example = "음성 댓글 파일 주소", maxLength = 255)
String fileUrl
) {
}
4 changes: 2 additions & 2 deletions post/src/main/java/com/oing/restapi/VoiceCommentApi.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.oing.restapi;

import com.oing.dto.request.CreatePostCommentRequest;
import com.oing.dto.request.CreatePostVoiceCommentRequest;
import com.oing.dto.request.PreSignedUrlRequest;
import com.oing.dto.response.DefaultResponse;
import com.oing.dto.response.PostCommentResponseV2;
Expand Down Expand Up @@ -38,7 +38,7 @@ PostCommentResponseV2 createPostVoiceComment(

@Valid
@RequestBody
CreatePostCommentRequest request,
CreatePostVoiceCommentRequest request,

@Parameter(hidden = true)
@LoginMemberId
Expand Down
6 changes: 3 additions & 3 deletions post/src/main/java/com/oing/service/VoiceCommentService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.oing.domain.Post;
import com.oing.domain.VoiceComment;
import com.oing.dto.request.CreatePostCommentRequest;
import com.oing.dto.request.CreatePostVoiceCommentRequest;
import com.oing.dto.response.PreSignedUrlResponse;
import com.oing.exception.AuthorizationFailedException;
import com.oing.exception.MemberVoiceCommentNotFoundException;
Expand Down Expand Up @@ -37,14 +37,14 @@ public PreSignedUrlResponse requestPresignedUrl(String loginMemberId, String fil
}

@Transactional
public VoiceComment saveVoiceComment(Post post, CreatePostCommentRequest request, String loginMemberId) {
public VoiceComment saveVoiceComment(Post post, CreatePostVoiceCommentRequest request, String loginMemberId) {
validateFamilyMember(loginMemberId, post);

VoiceComment voiceComment = new VoiceComment(
identityGenerator.generateIdentity(),
post,
loginMemberId,
request.content()
request.fileUrl()
);
VoiceComment savedVoiceComment = voiceCommentRepository.save(voiceComment);
post.addVoiceComment(savedVoiceComment);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.oing.domain.Post;
import com.oing.domain.PostType;
import com.oing.domain.VoiceComment;
import com.oing.dto.request.CreatePostCommentRequest;
import com.oing.dto.request.CreatePostVoiceCommentRequest;
import com.oing.repository.VoiceCommentRepository;
import com.oing.util.IdentityGenerator;
import com.oing.util.PreSignedUrlGenerator;
Expand Down Expand Up @@ -42,7 +42,7 @@ public class VoiceCommentServiceTest {
String familyId = "1";
Post post = new Post("1", memberId, familyId, PostType.SURVIVAL, "https://oing.com/post.jpg", "post.jpg",
"안녕.오잉.");
CreatePostCommentRequest request = new CreatePostCommentRequest("1");
CreatePostVoiceCommentRequest request = new CreatePostVoiceCommentRequest("1");
VoiceComment comment = new VoiceComment("1", null, "1", "https://oing.com/audio.mp3");

when(memberBridge.isInSameFamily(memberId, post.getMemberId())).thenReturn(true);
Expand Down

0 comments on commit 3d5bc95

Please sign in to comment.