From 3692e61b1c6c8fce54096df06d0021a0c8393ecb Mon Sep 17 00:00:00 2001 From: hy001 Date: Sat, 16 May 2026 00:54:00 +0800 Subject: [PATCH] fix: sync profile background update response --- .../command/user/UpdateUserProfileCmdExe.java | 40 ++++++++++---- .../user/UpdateUserProfileCmdExeTest.java | 55 +++++++++++++++++++ 2 files changed, 83 insertions(+), 12 deletions(-) diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/UpdateUserProfileCmdExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/UpdateUserProfileCmdExe.java index 4119e0f5..11a1d899 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/UpdateUserProfileCmdExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/UpdateUserProfileCmdExe.java @@ -134,10 +134,10 @@ public class UpdateUserProfileCmdExe { userProfileGateway.removeCacheAll(cmd.requiredReqUserId()); } - syncProperty(userProfile, cmd); log.warn("cmd: {},{}", cmd, userProfile); updateUserProfile.setOriginSys(cmd.requireReqSysOrigin()); submitApproval(updateUserProfile, userProfile); + syncProperty(userProfile, updateUserProfile, cmd); if (cmd.getCountryId() != null && cmd.getCountryId() > 0) { // 更改国家 设置redis表示已修改 两年过期 redisService.setString("IS_UPDATE_COUNTRY:" + cmd.requiredReqUserId(), "1", 730, TimeUnit.DAYS); @@ -236,27 +236,43 @@ public class UpdateUserProfileCmdExe { || originalPhotos.stream().noneMatch(item -> Objects.equals(item.getUrl(), photo.getUrl())); } - private void syncProperty(UserProfile oldProfile, UserProfileModifyCmd cmd) { + private void syncProperty(UserProfile oldProfile, UserProfile updateProfile, + UserProfileModifyCmd cmd) { - if (StringUtils.isNotBlank(cmd.getUserNickname())) { - oldProfile.setUserNickname(cmd.getUserNickname()); + if (StringUtils.isNotBlank(updateProfile.getUserNickname())) { + oldProfile.setUserNickname(updateProfile.getUserNickname()); } - if (StringUtils.isNotBlank(cmd.getUserAvatar())) { - oldProfile.setUserAvatar(cmd.getUserAvatar()); + if (StringUtils.isNotBlank(updateProfile.getUserAvatar())) { + oldProfile.setUserAvatar(updateProfile.getUserAvatar()); } if (cmd.age() > 0) { - oldProfile.setAge(cmd.age()); - oldProfile.setBornYear(cmd.getBornYear()); - oldProfile.setBornMonth(cmd.getBornMonth()); - oldProfile.setBornDay(cmd.getBornDay()); + oldProfile.setAge(updateProfile.getAge()); + oldProfile.setBornYear(updateProfile.getBornYear()); + oldProfile.setBornMonth(updateProfile.getBornMonth()); + oldProfile.setBornDay(updateProfile.getBornDay()); } - if (Objects.nonNull(cmd.getUserSex())) { - oldProfile.setUserSex(cmd.getUserSex()); + if (Objects.nonNull(updateProfile.getUserSex())) { + oldProfile.setUserSex(updateProfile.getUserSex()); } + if (StringUtils.isNotBlank(updateProfile.getAutograph())) { + oldProfile.setAutograph(updateProfile.getAutograph()); + } + + if (StringUtils.isNotBlank(updateProfile.getHobby())) { + oldProfile.setHobby(updateProfile.getHobby()); + } + + if (cmd.getBackgroundPhotos() != null) { + oldProfile.setBackgroundPhotos(updateProfile.getBackgroundPhotos()); + } + + if (cmd.getPersonalPhotos() != null) { + oldProfile.setPersonalPhotos(updateProfile.getPersonalPhotos()); + } } private void processAge(UserProfile userProfile) { diff --git a/rc-service/rc-service-other/other-application/src/test/java/com/red/circle/other/app/command/user/UpdateUserProfileCmdExeTest.java b/rc-service/rc-service-other/other-application/src/test/java/com/red/circle/other/app/command/user/UpdateUserProfileCmdExeTest.java index 67196ddd..37a3374e 100644 --- a/rc-service/rc-service-other/other-application/src/test/java/com/red/circle/other/app/command/user/UpdateUserProfileCmdExeTest.java +++ b/rc-service/rc-service-other/other-application/src/test/java/com/red/circle/other/app/command/user/UpdateUserProfileCmdExeTest.java @@ -1,6 +1,7 @@ package com.red.circle.other.app.command.user; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.ArgumentMatchers.anyList; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -17,8 +18,11 @@ import com.red.circle.other.infra.database.mongo.service.live.RoomProfileManager import com.red.circle.other.infra.database.rds.entity.sys.SysCountryCode; import com.red.circle.other.infra.database.rds.service.sys.SysCountryCodeService; import com.red.circle.other.infra.database.rds.service.user.user.BaseInfoService; +import com.red.circle.other.inner.model.dto.user.PhotoItem; import com.red.circle.other.inner.model.dto.user.UserProfileDTO; import com.red.circle.component.redis.service.RedisService; +import java.util.Collections; +import java.util.List; import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; @@ -78,4 +82,55 @@ class UpdateUserProfileCmdExeTest { assertEquals("Japan", persistedUpdate.getCountryName()); verify(roomProfileManagerService).updateUserCountry(1L, "JP", "Japan"); } + + @Test + void execute_shouldSyncBackgroundPhotosToReturnedProfileWhenBackgroundChanges() { + OssServiceClient ossServiceClient = mock(OssServiceClient.class); + UserProfileGateway userProfileGateway = mock(UserProfileGateway.class); + RedisService redisService = mock(RedisService.class); + BaseInfoService baseInfoService = mock(BaseInfoService.class); + SysCountryCodeService sysCountryCodeService = mock(SysCountryCodeService.class); + ProfileApprovalGateway profileApprovalGateway = mock(ProfileApprovalGateway.class); + UserProfileAppConvertor userProfileAppConvertor = mock(UserProfileAppConvertor.class); + RoomProfileManagerService roomProfileManagerService = mock(RoomProfileManagerService.class); + CpRelationshipCacheService cpRelationshipCacheService = mock(CpRelationshipCacheService.class); + UpdateUserProfileCmdExe exe = new UpdateUserProfileCmdExe( + ossServiceClient, + userProfileGateway, + redisService, + baseInfoService, + sysCountryCodeService, + profileApprovalGateway, + userProfileAppConvertor, + roomProfileManagerService, + cpRelationshipCacheService + ); + + String backgroundUrl = "https://example.com/profile-bg.jpg"; + UserProfileModifyCmd cmd = new UserProfileModifyCmd(); + cmd.setReqUserId(1L); + cmd.setReqSysOrigin(ReqSysOrigin.of("LIKEI", "LIKEI")); + cmd.setBackgroundPhotos(Collections.singletonList(backgroundUrl)); + + UserProfile currentUserProfile = new UserProfile(); + currentUserProfile.setId(1L); + UserProfile updateUserProfile = new UserProfile(); + List updatedPhotos = Collections.singletonList( + new PhotoItem().setUrl(backgroundUrl) + ); + + when(userProfileGateway.getByUserId(1L)).thenReturn(currentUserProfile); + when(userProfileAppConvertor.toUserProfile(cmd)).thenReturn(updateUserProfile); + when(userProfileAppConvertor.toPhotoItems(cmd.getBackgroundPhotos())).thenReturn(updatedPhotos); + when(userProfileAppConvertor.toUserProfileDTO(currentUserProfile)).thenReturn(new UserProfileDTO()); + + exe.execute(cmd); + + ArgumentCaptor updateCaptor = ArgumentCaptor.forClass(UserProfile.class); + verify(userProfileGateway).updateSelectiveById(updateCaptor.capture()); + assertEquals(updatedPhotos, updateCaptor.getValue().getBackgroundPhotos()); + assertEquals(updatedPhotos, currentUserProfile.getBackgroundPhotos()); + verify(profileApprovalGateway).submitApprovalBatch(anyList()); + verify(userProfileAppConvertor).toUserProfileDTO(currentUserProfile); + } }