diff --git a/gateway/src/main/resources/db/migration/V202402071837__add_familyId_column_to_MemberRealEmoji.sql b/gateway/src/main/resources/db/migration/V202402071837__add_familyId_column_to_MemberRealEmoji.sql new file mode 100644 index 00000000..52f2c2cb --- /dev/null +++ b/gateway/src/main/resources/db/migration/V202402071837__add_familyId_column_to_MemberRealEmoji.sql @@ -0,0 +1,3 @@ +ALTER TABLE `member_real_emoji` ADD COLUMN (`family_id` CHAR(26) NOT NULL DEFAULT '0' COMMENT 'ULID'); +UPDATE member_real_emoji JOIN member ON member_real_emoji.member_id = member.member_id +SET member_real_emoji.family_id = member.family_id; diff --git a/gateway/src/test/java/com/oing/restapi/MemberPostRealEmojiApiTest.java b/gateway/src/test/java/com/oing/restapi/MemberPostRealEmojiApiTest.java index 3d160560..9e7766d9 100644 --- a/gateway/src/test/java/com/oing/restapi/MemberPostRealEmojiApiTest.java +++ b/gateway/src/test/java/com/oing/restapi/MemberPostRealEmojiApiTest.java @@ -56,7 +56,7 @@ public class MemberPostRealEmojiApiTest { @BeforeEach void setUp() { - memberRepository.save(new Member(TEST_MEMBER_ID, "testUser1", LocalDate.now(), "", + memberRepository.save(new Member(TEST_MEMBER_ID, TEST_FAMILY_ID, LocalDate.now(), "", "", "", LocalDateTime.now())); TEST_MEMBER_TOKEN = tokenGenerator.generateTokenPair(TEST_MEMBER_ID).accessToken(); @@ -64,7 +64,7 @@ void setUp() { memberPostRepository.save(new MemberPost(TEST_POST_ID, TEST_MEMBER_ID, TEST_FAMILY_ID, "img", "img", "content")); - memberRealEmojiRepository.save(new MemberRealEmoji(TEST_REAL_EMOJI_ID, TEST_MEMBER_ID, Emoji.EMOJI_1, + memberRealEmojiRepository.save(new MemberRealEmoji(TEST_REAL_EMOJI_ID, TEST_MEMBER_ID, TEST_FAMILY_ID, Emoji.EMOJI_1, "https://test.com/bucket/real-emoji.jpg", "bucket/real-emoji.jpg")); } diff --git a/gateway/src/test/java/com/oing/restapi/MemberRealEmojiApiTest.java b/gateway/src/test/java/com/oing/restapi/MemberRealEmojiApiTest.java index c0478b78..3a256ad9 100644 --- a/gateway/src/test/java/com/oing/restapi/MemberRealEmojiApiTest.java +++ b/gateway/src/test/java/com/oing/restapi/MemberRealEmojiApiTest.java @@ -42,6 +42,7 @@ public class MemberRealEmojiApiTest { private ObjectMapper objectMapper; private String TEST_MEMBER_ID = "01HGW2N7EHJVJ4CJ999RRS2E97"; + private String TEST_FAMILY_ID = "01HGW2N7EHJVJ4CJ999RRS2E44"; private String TEST_MEMBER_REAL_EMOJI_ID = "01HGW2N7EHJVJ4CJ999RRS2A97"; private String TEST_MEMBER_TOKEN; @@ -55,7 +56,7 @@ void setUp() { memberRepository.save( new Member( TEST_MEMBER_ID, - "testUser1", + TEST_FAMILY_ID, LocalDate.now(), "", "", "", LocalDateTime.now() @@ -116,6 +117,7 @@ void setUp() { new MemberRealEmoji( TEST_MEMBER_REAL_EMOJI_ID, TEST_MEMBER_ID, + TEST_FAMILY_ID, Emoji.EMOJI_1, "https://test.com/bucket/images/defaultEmoji.jpg", "images/defaultEmoji.jpg" @@ -144,6 +146,7 @@ void setUp() { new MemberRealEmoji( TEST_MEMBER_REAL_EMOJI_ID, TEST_MEMBER_ID, + TEST_FAMILY_ID, Emoji.EMOJI_1, realEmojiImageUrl, "images/defaultEmoji.jpg" diff --git a/member/src/main/java/com/oing/domain/Member.java b/member/src/main/java/com/oing/domain/Member.java index 6728dffd..a8dd7e0a 100644 --- a/member/src/main/java/com/oing/domain/Member.java +++ b/member/src/main/java/com/oing/domain/Member.java @@ -44,10 +44,6 @@ public class Member extends DeletableBaseAuditEntity { private LocalDateTime familyJoinAt; - public void setProfileImgKey(String profileImgKey) { - this.profileImgKey = profileImgKey; - } - public void updateProfileImg(String profileImgUrl, String profileImgKey) { this.profileImgUrl = profileImgUrl; diff --git a/post/src/main/java/com/oing/controller/MemberPostRealEmojiController.java b/post/src/main/java/com/oing/controller/MemberPostRealEmojiController.java index 36508bc3..78cfa65e 100644 --- a/post/src/main/java/com/oing/controller/MemberPostRealEmojiController.java +++ b/post/src/main/java/com/oing/controller/MemberPostRealEmojiController.java @@ -45,13 +45,13 @@ public class MemberPostRealEmojiController implements MemberPostRealEmojiApi { */ @Transactional @Override - public PostRealEmojiResponse createPostRealEmoji(String postId, PostRealEmojiRequest request) { + public PostRealEmojiResponse createPostRealEmoji(String postId, String familyId, PostRealEmojiRequest request) { String memberId = authenticationHolder.getUserId(); MemberPost post = memberPostService.getMemberPostById(postId); if (!memberBridge.isInSameFamily(memberId, post.getMemberId())) throw new AuthorizationFailedException(); - MemberRealEmoji realEmoji = memberRealEmojiService.getMemberRealEmojiById(request.realEmojiId()); + MemberRealEmoji realEmoji = memberRealEmojiService.getMemberRealEmojiByIdAndFamilyId(request.realEmojiId(), familyId); validatePostRealEmojiForAddition(post, memberId, realEmoji); MemberPostRealEmoji postRealEmoji = new MemberPostRealEmoji(identityGenerator.generateIdentity(), realEmoji, post, memberId); diff --git a/post/src/main/java/com/oing/controller/MemberRealEmojiController.java b/post/src/main/java/com/oing/controller/MemberRealEmojiController.java index 55853b18..a9d58c0d 100644 --- a/post/src/main/java/com/oing/controller/MemberRealEmojiController.java +++ b/post/src/main/java/com/oing/controller/MemberRealEmojiController.java @@ -42,40 +42,40 @@ public PreSignedUrlResponse requestPresignedUrl(String memberId, PreSignedUrlReq @Transactional @Override - public RealEmojiResponse createMemberRealEmoji(String memberId, CreateMyRealEmojiRequest request) { + public RealEmojiResponse createMemberRealEmoji(String memberId, String familyId, CreateMyRealEmojiRequest request) { validateMemberId(memberId); String emojiId = identityGenerator.generateIdentity(); String emojiImgKey = preSignedUrlGenerator.extractImageKey(request.imageUrl()); Emoji emoji = Emoji.fromString(request.type()); - if (isExistsSameRealEmojiType(emoji, memberId)) { + if (isExistsSameRealEmojiType(emoji, memberId, familyId)) { throw new DuplicateRealEmojiException(); } - MemberRealEmoji realEmoji = new MemberRealEmoji(emojiId, memberId, emoji, request.imageUrl(), emojiImgKey); + MemberRealEmoji realEmoji = new MemberRealEmoji(emojiId, memberId, familyId, emoji, request.imageUrl(), emojiImgKey); MemberRealEmoji addedRealEmoji = memberRealEmojiService.save(realEmoji); return RealEmojiResponse.from(addedRealEmoji); } - private boolean isExistsSameRealEmojiType(Emoji emoji, String memberId) { - return memberRealEmojiService.findRealEmojiByEmojiTypeAndMemberId(emoji, memberId); + private boolean isExistsSameRealEmojiType(Emoji emoji, String memberId, String familyId) { + return memberRealEmojiService.findRealEmojiByEmojiTypeAndMemberIdAndFamilyId(emoji, memberId, familyId); } @Transactional @Override - public RealEmojiResponse changeMemberRealEmoji(String memberId, String realEmojiId, UpdateMyRealEmojiRequest request) { + public RealEmojiResponse changeMemberRealEmoji(String memberId, String familyId, String realEmojiId, UpdateMyRealEmojiRequest request) { validateMemberId(memberId); String emojiImgKey = preSignedUrlGenerator.extractImageKey(request.imageUrl()); - MemberRealEmoji findEmoji = memberRealEmojiService.findRealEmojiById(realEmojiId); + MemberRealEmoji findEmoji = memberRealEmojiService.getMemberRealEmojiByIdAndFamilyId(realEmojiId, familyId); findEmoji.updateRealEmoji(request.imageUrl(), emojiImgKey); return RealEmojiResponse.from(findEmoji); } @Override - public RealEmojisResponse getMemberRealEmojis(String memberId) { + public RealEmojisResponse getMemberRealEmojis(String memberId, String familyId) { validateMemberId(memberId); - List realEmojis = memberRealEmojiService.findRealEmojisByMemberId(memberId); + List realEmojis = memberRealEmojiService.findRealEmojisByMemberIdAndFamilyId(memberId, familyId); List emojiResponses = realEmojis.stream() .map(RealEmojiResponse::from) .collect(Collectors.toList()); diff --git a/post/src/main/java/com/oing/domain/MemberRealEmoji.java b/post/src/main/java/com/oing/domain/MemberRealEmoji.java index 75812233..56377052 100644 --- a/post/src/main/java/com/oing/domain/MemberRealEmoji.java +++ b/post/src/main/java/com/oing/domain/MemberRealEmoji.java @@ -20,6 +20,9 @@ public class MemberRealEmoji extends BaseAuditEntity { @Column(name = "member_id", columnDefinition = "CHAR(26)", nullable = false) private String memberId; + @Column(name = "family_id", columnDefinition = "CHAR(26)", nullable = false) + private String familyId; + @Enumerated(EnumType.STRING) @Column(name = "type", nullable = false) private Emoji type; diff --git a/post/src/main/java/com/oing/repository/MemberRealEmojiRepository.java b/post/src/main/java/com/oing/repository/MemberRealEmojiRepository.java index 27f871bd..87a2cac2 100644 --- a/post/src/main/java/com/oing/repository/MemberRealEmojiRepository.java +++ b/post/src/main/java/com/oing/repository/MemberRealEmojiRepository.java @@ -9,7 +9,9 @@ public interface MemberRealEmojiRepository extends JpaRepository { - Optional findByTypeAndMemberId(Emoji emoji, String memberId); + Optional findByIdAndFamilyId(String realEmojiId, String familyId); - List findAllByMemberId(String memberId); + Optional findByTypeAndMemberIdAndFamilyId(Emoji emoji, String memberId, String familyId); + + List findAllByMemberIdAndFamilyId(String memberId, String familyId); } diff --git a/post/src/main/java/com/oing/restapi/MemberPostRealEmojiApi.java b/post/src/main/java/com/oing/restapi/MemberPostRealEmojiApi.java index 640da1be..d85a628b 100644 --- a/post/src/main/java/com/oing/restapi/MemberPostRealEmojiApi.java +++ b/post/src/main/java/com/oing/restapi/MemberPostRealEmojiApi.java @@ -2,6 +2,7 @@ import com.oing.dto.request.PostRealEmojiRequest; import com.oing.dto.response.*; +import com.oing.util.security.FamilyId; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; @@ -21,6 +22,10 @@ PostRealEmojiResponse createPostRealEmoji( @PathVariable String postId, + @Parameter(hidden = true) + @FamilyId + String familyId, + @Valid @RequestBody PostRealEmojiRequest request diff --git a/post/src/main/java/com/oing/restapi/MemberRealEmojiApi.java b/post/src/main/java/com/oing/restapi/MemberRealEmojiApi.java index 0279d30d..01df3458 100644 --- a/post/src/main/java/com/oing/restapi/MemberRealEmojiApi.java +++ b/post/src/main/java/com/oing/restapi/MemberRealEmojiApi.java @@ -6,6 +6,7 @@ import com.oing.dto.response.PreSignedUrlResponse; import com.oing.dto.response.RealEmojiResponse; import com.oing.dto.response.RealEmojisResponse; +import com.oing.util.security.FamilyId; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; @@ -37,6 +38,10 @@ RealEmojiResponse createMemberRealEmoji( @PathVariable String memberId, + @Parameter(hidden = true) + @FamilyId + String familyId, + @Valid @RequestBody CreateMyRealEmojiRequest request @@ -49,6 +54,10 @@ RealEmojiResponse changeMemberRealEmoji( @PathVariable String memberId, + @Parameter(hidden = true) + @FamilyId + String familyId, + @Parameter(description = "리얼 이모지 ID", example = "01HGW2N7EHJVJ4CJ999RRS2E97") @PathVariable String realEmojiId, @@ -63,6 +72,10 @@ RealEmojiResponse changeMemberRealEmoji( RealEmojisResponse getMemberRealEmojis( @Parameter(description = "회원 ID", example = "01HGW2N7EHJVJ4CJ999RRS2E97") @PathVariable - String memberId + String memberId, + + @Parameter(hidden = true) + @FamilyId + String familyId ); } diff --git a/post/src/main/java/com/oing/service/MemberRealEmojiService.java b/post/src/main/java/com/oing/service/MemberRealEmojiService.java index 9ca4b08a..1f329600 100644 --- a/post/src/main/java/com/oing/service/MemberRealEmojiService.java +++ b/post/src/main/java/com/oing/service/MemberRealEmojiService.java @@ -16,8 +16,9 @@ public class MemberRealEmojiService { private final MemberRealEmojiRepository memberRealEmojiRepository; - public MemberRealEmoji getMemberRealEmojiById(String realEmojiId) { - return memberRealEmojiRepository.findById(realEmojiId) + public MemberRealEmoji getMemberRealEmojiByIdAndFamilyId(String realEmojiId, String familyId) { + return memberRealEmojiRepository + .findByIdAndFamilyId(realEmojiId, familyId) .orElseThrow(RealEmojiNotFoundException::new); } @@ -25,20 +26,13 @@ public MemberRealEmoji save(MemberRealEmoji emoji) { return memberRealEmojiRepository.save(emoji); } - public MemberRealEmoji findRealEmojiById(String realEmojiId) { - return memberRealEmojiRepository - .findById(realEmojiId) - .orElseThrow(RealEmojiNotFoundException::new); - } - - public boolean findRealEmojiByEmojiTypeAndMemberId(Emoji emoji, String memberId) { + public boolean findRealEmojiByEmojiTypeAndMemberIdAndFamilyId(Emoji emoji, String memberId, String familyId) { return memberRealEmojiRepository - .findByTypeAndMemberId(emoji, memberId) + .findByTypeAndMemberIdAndFamilyId(emoji, memberId, familyId) .isPresent(); } - public List findRealEmojisByMemberId(String memberId) { - return memberRealEmojiRepository.findAllByMemberId(memberId); + public List findRealEmojisByMemberIdAndFamilyId(String memberId, String familyId) { + return memberRealEmojiRepository.findAllByMemberIdAndFamilyId(memberId, familyId); } - } diff --git a/post/src/test/java/com/oing/controller/MemberPostRealEmojiControllerTest.java b/post/src/test/java/com/oing/controller/MemberPostRealEmojiControllerTest.java index 5587be7b..fa2a96d0 100644 --- a/post/src/test/java/com/oing/controller/MemberPostRealEmojiControllerTest.java +++ b/post/src/test/java/com/oing/controller/MemberPostRealEmojiControllerTest.java @@ -57,14 +57,15 @@ public class MemberPostRealEmojiControllerTest { void 게시물_리얼이모지_등록_테스트() { //given String memberId = "1"; + String familyId = "1"; when(authenticationHolder.getUserId()).thenReturn(memberId); when(memberBridge.isInSameFamily(memberId, memberId)).thenReturn(true); - MemberPost post = new MemberPost("1", memberId, "1", "https://oing.com/post.jpg", "post.jpg", + MemberPost post = new MemberPost("1", memberId, familyId, "https://oing.com/post.jpg", "post.jpg", "안녕.오잉."); - MemberRealEmoji realEmoji = new MemberRealEmoji("1", memberId, + MemberRealEmoji realEmoji = new MemberRealEmoji("1", memberId, familyId, Emoji.EMOJI_1, "https://oing.com/emoji.jpg", "emoji.jpg"); when(memberPostService.getMemberPostById(post.getId())).thenReturn(post); - when(memberRealEmojiService.getMemberRealEmojiById(realEmoji.getId())).thenReturn(realEmoji); + when(memberRealEmojiService.getMemberRealEmojiByIdAndFamilyId(realEmoji.getId(), familyId)).thenReturn(realEmoji); MemberPostRealEmoji postRealEmoji = new MemberPostRealEmoji("1", realEmoji, post, memberId); when(memberPostRealEmojiService.savePostRealEmoji(any(MemberPostRealEmoji.class))).thenReturn(postRealEmoji); @@ -72,7 +73,7 @@ public class MemberPostRealEmojiControllerTest { PostRealEmojiRequest request = new PostRealEmojiRequest(realEmoji.getId()); //when - PostRealEmojiResponse response = memberPostRealEmojiController.createPostRealEmoji(post.getId(), request); + PostRealEmojiResponse response = memberPostRealEmojiController.createPostRealEmoji(post.getId(), familyId, request); //then assertEquals(post.getId(), response.postId()); @@ -83,10 +84,11 @@ public class MemberPostRealEmojiControllerTest { void 권한없는_memberId로_게시물_리얼이모지_등록_예외_테스트() { // given String memberId = "1"; + String familyId = "1"; when(authenticationHolder.getUserId()).thenReturn(memberId); - MemberPost post = new MemberPost("1", memberId, "1", "https://oing.com/post.jpg", "post.jpg", + MemberPost post = new MemberPost("1", memberId, familyId, "https://oing.com/post.jpg", "post.jpg", "안녕.오잉."); - MemberRealEmoji realEmoji = new MemberRealEmoji("1", memberId, + MemberRealEmoji realEmoji = new MemberRealEmoji("1", memberId, familyId, Emoji.EMOJI_1, "https://oing.com/emoji.jpg", "emoji.jpg"); when(memberPostService.getMemberPostById(post.getId())).thenReturn(post); @@ -96,21 +98,22 @@ public class MemberPostRealEmojiControllerTest { // then assertThrows(AuthorizationFailedException.class, - () -> memberPostRealEmojiController.createPostRealEmoji(post.getId(), request)); + () -> memberPostRealEmojiController.createPostRealEmoji(post.getId(), familyId, request)); } @Test void 게시물_중복된_리얼이모지_등록_예외_테스트() { //given String memberId = "1"; + String familyId = "1"; when(authenticationHolder.getUserId()).thenReturn(memberId); when(memberBridge.isInSameFamily(memberId, memberId)).thenReturn(true); - MemberPost post = new MemberPost("1", memberId, "1", "https://oing.com/post.jpg", "post.jpg", + MemberPost post = new MemberPost("1", memberId, familyId, "https://oing.com/post.jpg", "post.jpg", "안녕.오잉."); - MemberRealEmoji realEmoji = new MemberRealEmoji("1", memberId, Emoji.EMOJI_1, + MemberRealEmoji realEmoji = new MemberRealEmoji("1", memberId, familyId, Emoji.EMOJI_1, "https://oing.com/emoji.jpg", "emoji.jpg"); when(memberPostService.getMemberPostById(post.getId())).thenReturn(post); - when(memberRealEmojiService.getMemberRealEmojiById(realEmoji.getId())).thenReturn(realEmoji); + when(memberRealEmojiService.getMemberRealEmojiByIdAndFamilyId(realEmoji.getId(), familyId)).thenReturn(realEmoji); //when when(memberPostRealEmojiService.isMemberPostRealEmojiExists(post, memberId, realEmoji)).thenReturn(true); @@ -118,16 +121,17 @@ public class MemberPostRealEmojiControllerTest { //then assertThrows(RealEmojiAlreadyExistsException.class, - () -> memberPostRealEmojiController.createPostRealEmoji(post.getId(), request)); + () -> memberPostRealEmojiController.createPostRealEmoji(post.getId(), familyId, request)); } @Test void 게시물_리얼이모지_삭제_테스트() { //given String memberId = "1"; - MemberPost post = new MemberPost("1", memberId, "1", "https://oing.com/post.jpg", "post.jpg", + String familyId = "1"; + MemberPost post = new MemberPost("1", memberId, familyId, "https://oing.com/post.jpg", "post.jpg", "안녕.오잉."); - MemberRealEmoji realEmoji = new MemberRealEmoji("1", memberId, + MemberRealEmoji realEmoji = new MemberRealEmoji("1", memberId, familyId, Emoji.EMOJI_1, "https://oing.com/emoji.jpg", "emoji.jpg"); when(memberPostService.getMemberPostById(post.getId())).thenReturn(post); @@ -142,10 +146,11 @@ public class MemberPostRealEmojiControllerTest { void 게시물_등록되지_않은_리얼이모지_삭제_예외_테스트() { //given String memberId = "1"; + String familyId = "1"; when(authenticationHolder.getUserId()).thenReturn(memberId); - MemberPost post = new MemberPost("1", memberId, "1","https://oing.com/post.jpg", "post.jpg", + MemberPost post = new MemberPost("1", memberId, familyId,"https://oing.com/post.jpg", "post.jpg", "안녕.오잉."); - MemberRealEmoji realEmoji = new MemberRealEmoji("1", memberId, + MemberRealEmoji realEmoji = new MemberRealEmoji("1", memberId, familyId, Emoji.EMOJI_1, "https://oing.com/emoji.jpg", "emoji.jpg"); when(memberPostService.getMemberPostById(post.getId())).thenReturn(post); diff --git a/post/src/test/java/com/oing/controller/MemberRealEmojiControllerTest.java b/post/src/test/java/com/oing/controller/MemberRealEmojiControllerTest.java index db09fe88..5566ef05 100644 --- a/post/src/test/java/com/oing/controller/MemberRealEmojiControllerTest.java +++ b/post/src/test/java/com/oing/controller/MemberRealEmojiControllerTest.java @@ -65,15 +65,16 @@ public class MemberRealEmojiControllerTest { void 회원_리얼이모지_생성_테스트() { // given String memberId = "1"; + String familyId = "1"; String realEmojiImageUrl = "https://test.com/realEmoji.jpg"; Emoji emoji = Emoji.EMOJI_1; // when when(authenticationHolder.getUserId()).thenReturn(memberId); CreateMyRealEmojiRequest request = new CreateMyRealEmojiRequest(emoji.getTypeKey(), realEmojiImageUrl); - when(memberRealEmojiService.save(any())).thenReturn(new MemberRealEmoji("1", memberId, emoji, + when(memberRealEmojiService.save(any())).thenReturn(new MemberRealEmoji("1", memberId, familyId, emoji, realEmojiImageUrl, "realEmoji.jpg")); - RealEmojiResponse response = memberRealEmojiController.createMemberRealEmoji(memberId, request); + RealEmojiResponse response = memberRealEmojiController.createMemberRealEmoji(memberId, familyId, request); // then assertEquals(emoji.getTypeKey(), response.type()); @@ -84,6 +85,7 @@ public class MemberRealEmojiControllerTest { void 권한없는_memberId로_리얼이모지_생성_예외_테스트() { // given String memberId = "1"; + String familyId = "1"; String realEmojiImageUrl = "https://test.com/realEmoji.jpg"; Emoji emoji = Emoji.EMOJI_1; @@ -93,39 +95,41 @@ public class MemberRealEmojiControllerTest { // then assertThrows(AuthorizationFailedException.class, - () -> memberRealEmojiController.createMemberRealEmoji(memberId, request)); + () -> memberRealEmojiController.createMemberRealEmoji(memberId, familyId, request)); } @Test void 중복된_리얼이모지_생성_예외_테스트() { // given String memberId = "1"; + String familyId = "1"; String realEmojiImageUrl = "https://test.com/realEmoji.jpg"; Emoji emoji = Emoji.EMOJI_1; // when when(authenticationHolder.getUserId()).thenReturn(memberId); CreateMyRealEmojiRequest request = new CreateMyRealEmojiRequest(emoji.getTypeKey(), realEmojiImageUrl); - when(memberRealEmojiService.findRealEmojiByEmojiTypeAndMemberId(emoji, memberId)).thenReturn(true); + when(memberRealEmojiService.findRealEmojiByEmojiTypeAndMemberIdAndFamilyId(emoji, memberId, familyId)).thenReturn(true); // then assertThrows(DuplicateRealEmojiException.class, - () -> memberRealEmojiController.createMemberRealEmoji(memberId, request)); + () -> memberRealEmojiController.createMemberRealEmoji(memberId, familyId, request)); } @Test void 회원_리얼이모지_수정_테스트() { // given String memberId = "1"; + String familyId = "1"; String realEmojiId = "1"; String realEmojiImageUrl = "https://test.com/realEmoji.jpg"; // when when(authenticationHolder.getUserId()).thenReturn(memberId); UpdateMyRealEmojiRequest request = new UpdateMyRealEmojiRequest(realEmojiImageUrl); - when(memberRealEmojiService.findRealEmojiById(realEmojiId)).thenReturn(new MemberRealEmoji("1", memberId, - Emoji.EMOJI_1, realEmojiImageUrl, "realEmoji.jpg")); - RealEmojiResponse response = memberRealEmojiController.changeMemberRealEmoji(memberId, realEmojiId, request); + when(memberRealEmojiService.getMemberRealEmojiByIdAndFamilyId(realEmojiId, familyId)).thenReturn( + new MemberRealEmoji("1", memberId, familyId, Emoji.EMOJI_1, realEmojiImageUrl, "realEmoji.jpg")); + RealEmojiResponse response = memberRealEmojiController.changeMemberRealEmoji(memberId, familyId, realEmojiId, request); // then assertEquals(request.imageUrl(), response.imageUrl()); @@ -135,6 +139,7 @@ public class MemberRealEmojiControllerTest { void 회원_리얼이모지_조회_테스트() { // given String memberId = "1"; + String familyId = "1"; String realEmojiImageUrl1 = "https://test.com/realEmoji1.jpg"; String realEmojiImageUrl2 = "https://test.com/realEmoji2.jpg"; Emoji emoji1 = Emoji.EMOJI_1; @@ -142,19 +147,19 @@ public class MemberRealEmojiControllerTest { when(authenticationHolder.getUserId()).thenReturn(memberId); CreateMyRealEmojiRequest request1 = new CreateMyRealEmojiRequest(emoji1.getTypeKey(), realEmojiImageUrl1); CreateMyRealEmojiRequest request2 = new CreateMyRealEmojiRequest(emoji1.getTypeKey(), realEmojiImageUrl2); - when(memberRealEmojiService.save(any())).thenReturn(new MemberRealEmoji("1", memberId, emoji1, + when(memberRealEmojiService.save(any())).thenReturn(new MemberRealEmoji("1", memberId, familyId, emoji1, realEmojiImageUrl1, "realEmoji1.jpg")); - memberRealEmojiController.createMemberRealEmoji(memberId, request1); - when(memberRealEmojiService.save(any())).thenReturn(new MemberRealEmoji("2", memberId, emoji2, + memberRealEmojiController.createMemberRealEmoji(memberId, familyId, request1); + when(memberRealEmojiService.save(any())).thenReturn(new MemberRealEmoji("2", memberId, familyId, emoji2, realEmojiImageUrl2, "realEmoji2.jpg")); - memberRealEmojiController.createMemberRealEmoji(memberId, request2); + memberRealEmojiController.createMemberRealEmoji(memberId, familyId, request2); // when - when(memberRealEmojiService.findRealEmojisByMemberId(memberId)).thenReturn(List.of( - new MemberRealEmoji("1", memberId, emoji1, realEmojiImageUrl1, "realEmoji1.jpg"), - new MemberRealEmoji("2", memberId, emoji2, realEmojiImageUrl2, "realEmoji2.jpg") + when(memberRealEmojiService.findRealEmojisByMemberIdAndFamilyId(memberId, familyId)).thenReturn(List.of( + new MemberRealEmoji("1", memberId, familyId, emoji1, realEmojiImageUrl1, "realEmoji1.jpg"), + new MemberRealEmoji("2", memberId, familyId, emoji2, realEmojiImageUrl2, "realEmoji2.jpg") )); - RealEmojisResponse response = memberRealEmojiController.getMemberRealEmojis(memberId); + RealEmojisResponse response = memberRealEmojiController.getMemberRealEmojis(memberId, familyId); // then assertEquals(2, response.myRealEmojiList().size()); @@ -165,4 +170,25 @@ public class MemberRealEmojiControllerTest { assertEquals(request1.imageUrl(), response.myRealEmojiList().get(0).imageUrl()); assertEquals(request2.imageUrl(), response.myRealEmojiList().get(1).imageUrl()); } + + @Test + void 다른_가족에서_생성된_회원_리얼이모지_조회_테스트() { + // given + String memberId = "1"; + String otherFamilyId = "1"; + String familyId = "2"; + String realEmojiImageUrl = "https://test.com/realEmoji1.jpg"; + Emoji emoji = Emoji.EMOJI_1; + when(authenticationHolder.getUserId()).thenReturn(memberId); + CreateMyRealEmojiRequest request = new CreateMyRealEmojiRequest(emoji.getTypeKey(), realEmojiImageUrl); + when(memberRealEmojiService.save(any())).thenReturn(new MemberRealEmoji("1", memberId, otherFamilyId, emoji, + realEmojiImageUrl, "realEmoji.jpg")); + memberRealEmojiController.createMemberRealEmoji(memberId, otherFamilyId, request); + + // when + RealEmojisResponse response = memberRealEmojiController.getMemberRealEmojis(memberId, familyId); + + // then + assertEquals(0, response.myRealEmojiList().size()); + } }