diff --git a/src/main/java/com/postgraduate/domain/senior/application/mapper/SeniorMapper.java b/src/main/java/com/postgraduate/domain/senior/application/mapper/SeniorMapper.java index dca2f377..1f128199 100644 --- a/src/main/java/com/postgraduate/domain/senior/application/mapper/SeniorMapper.java +++ b/src/main/java/com/postgraduate/domain/senior/application/mapper/SeniorMapper.java @@ -27,12 +27,48 @@ private SeniorMapper() { public static Senior mapToSenior(User user, SeniorSignUpRequest request) { return Senior.builder() .user(user) - .info(mapToInfo(user, request)) + .info(mapToInfo(request)) .certification(request.certification()) .build(); } - public static Info mapToInfo(User user, SeniorSignUpRequest request) { + public static Senior mapToSenior(User user, SeniorChangeRequest request) { + return Senior.builder() + .user(user) + .info(mapToInfo(request)) + .certification(request.certification()) + .build(); + } + + public static Info mapToInfo(SeniorChangeRequest request) { + String[] fields = request.field().split(","); + Set fieldNames = Field.fieldNames(); + Set postgraduNames = Postgradu.postgraduNames(); + + Info.InfoBuilder infoBuilder = Info.builder() + .major(request.major()) + .postgradu(request.postgradu()) + .professor(request.professor()) + .lab(request.lab()) + .keyword(request.keyword()) + .field(request.field()) + .etcPostgradu(true) + .etcField(true) + .totalInfo(request.major() + request.lab() + request.field() + + request.professor() + request.postgradu() + request.keyword()); + + for (String field : fields) { + if (fieldNames.contains(field)) { + infoBuilder.etcField(false); + break; + } + } + if (postgraduNames.contains(request.postgradu())) + infoBuilder.etcPostgradu(false); + return infoBuilder.build(); + } + + public static Info mapToInfo(SeniorSignUpRequest request) { String[] fields = request.field().split(","); Set fieldNames = Field.fieldNames(); Set postgraduNames = Postgradu.postgraduNames(); @@ -47,7 +83,7 @@ public static Info mapToInfo(User user, SeniorSignUpRequest request) { .etcPostgradu(false) .etcField(false) .totalInfo(request.major() + request.lab() + request.field() - + request.professor() + request.postgradu() + request.keyword() + user.getNickName()); + + request.professor() + request.postgradu() + request.keyword()); for (String field : fields) { if (!fieldNames.contains(field)) { @@ -61,6 +97,34 @@ public static Info mapToInfo(User user, SeniorSignUpRequest request) { return infoBuilder.build(); } + public static Info mapToInfo(Senior senior, SeniorMyPageProfileRequest request) { + Info info = senior.getInfo(); + String[] fields = request.field().split(","); + Set fieldNames = Field.fieldNames(); + + Info.InfoBuilder infoBuilder = Info.builder() + .major(info.getMajor()) + .postgradu(info.getPostgradu()) + .professor(info.getProfessor()) + .lab(request.lab()) + .keyword(request.keyword()) + .field(request.field()) + .etcPostgradu(false) + .etcField(false) + .totalInfo(info.getMajor() + request.lab() + request.field() + + info.getProfessor() + info.getPostgradu() + request.keyword()); + + for (String field : fields) { + if (!fieldNames.contains(field)) { + infoBuilder.etcField(true); + break; + } + } + infoBuilder.etcPostgradu(info.getEtcPostgradu()); + + return infoBuilder.build(); + } + public static Profile mapToProfile(SeniorProfileRequest profileRequest) { return Profile.builder() .info(profileRequest.info()) @@ -79,42 +143,6 @@ public static Profile mapToProfile(SeniorMyPageProfileRequest profileRequest) { .build(); } - public static Senior mapToSenior(User user, SeniorChangeRequest request) { - return Senior.builder() - .user(user) - .info(mapToInfo(user, request)) - .certification(request.certification()) - .build(); - } - - public static Info mapToInfo(User user, SeniorChangeRequest request) { - String[] fields = request.field().split(","); - Set fieldNames = Field.fieldNames(); - Set postgraduNames = Postgradu.postgraduNames(); - - Info.InfoBuilder infoBuilder = Info.builder() - .major(request.major()) - .postgradu(request.postgradu()) - .professor(request.professor()) - .lab(request.lab()) - .keyword(request.keyword()) - .field(request.field()) - .etcPostgradu(true) - .etcField(true) - .totalInfo(request.major() + request.lab() + request.field() - + request.professor() + request.postgradu() + request.keyword() + user.getNickName()); - - for (String field : fields) { - if (fieldNames.contains(field)) { - infoBuilder.etcField(false); - break; - } - } - if (postgraduNames.contains(request.postgradu())) - infoBuilder.etcPostgradu(false); - return infoBuilder.build(); - } - public static SeniorMyPageResponse mapToSeniorMyPageInfo(Senior senior, Status certificationRegister, boolean profileRegister) { User user = senior.getUser(); return new SeniorMyPageResponse(user.getSocialId(), senior.getSeniorId(), user.getNickName(), user.getProfile(), certificationRegister, profileRegister); diff --git a/src/main/java/com/postgraduate/domain/senior/application/usecase/SeniorManageUseCase.java b/src/main/java/com/postgraduate/domain/senior/application/usecase/SeniorManageUseCase.java index c8753bb8..686e48b6 100644 --- a/src/main/java/com/postgraduate/domain/senior/application/usecase/SeniorManageUseCase.java +++ b/src/main/java/com/postgraduate/domain/senior/application/usecase/SeniorManageUseCase.java @@ -15,6 +15,7 @@ import com.postgraduate.domain.senior.application.dto.req.*; import com.postgraduate.domain.senior.application.dto.res.SeniorProfileUpdateResponse; import com.postgraduate.domain.senior.application.utils.SeniorUtils; +import com.postgraduate.domain.senior.domain.entity.Info; import com.postgraduate.domain.senior.domain.entity.Profile; import com.postgraduate.domain.senior.domain.entity.Senior; import com.postgraduate.domain.senior.domain.service.SeniorGetService; @@ -34,6 +35,7 @@ import static com.postgraduate.domain.account.application.mapper.AccountMapper.mapToAccount; import static com.postgraduate.domain.available.application.util.AvailableUtil.sortAvailable; import static com.postgraduate.domain.salary.application.mapper.SalaryMapper.mapToSalaryAccount; +import static com.postgraduate.domain.senior.application.mapper.SeniorMapper.mapToInfo; import static com.postgraduate.domain.senior.application.mapper.SeniorMapper.mapToProfile; @Service @@ -81,7 +83,8 @@ public SeniorProfileUpdateResponse updateSeniorMyPageProfile(User user, SeniorMy seniorUtils.checkKeyword(myPageProfileRequest.keyword()); Senior senior = seniorGetService.byUser(user); Profile profile = mapToProfile(myPageProfileRequest); - seniorUpdateService.updateMyPageProfile(senior, myPageProfileRequest, profile); + Info info = mapToInfo(senior, myPageProfileRequest); + seniorUpdateService.updateMyPageProfile(senior, info, profile); availableDeleteService.delete(senior); List availableCreateRequests = myPageProfileRequest.times(); List sortedAvailable = sortAvailable(availableCreateRequests, senior); diff --git a/src/main/java/com/postgraduate/domain/senior/domain/entity/Info.java b/src/main/java/com/postgraduate/domain/senior/domain/entity/Info.java index f221d537..e8f59cf0 100644 --- a/src/main/java/com/postgraduate/domain/senior/domain/entity/Info.java +++ b/src/main/java/com/postgraduate/domain/senior/domain/entity/Info.java @@ -1,7 +1,5 @@ package com.postgraduate.domain.senior.domain.entity; -import com.postgraduate.domain.senior.application.dto.req.SeniorMyPageProfileRequest; -import com.postgraduate.domain.senior.domain.entity.constant.Field; import jakarta.persistence.Column; import jakarta.persistence.Embeddable; import lombok.AllArgsConstructor; @@ -9,8 +7,6 @@ import lombok.Getter; import lombok.NoArgsConstructor; -import java.util.Set; - @Getter @AllArgsConstructor @NoArgsConstructor @@ -45,24 +41,4 @@ public class Info { @Column(nullable = false, columnDefinition = "TEXT") private String totalInfo; // 모든 Info정보 String으로 가지는 컬럼 - 검색시 사용 - - protected void updateMyPage(String nickName, SeniorMyPageProfileRequest request) { - String[] fileds = request.field().split(","); - Set fieldNames = Field.fieldNames(); - this.keyword = request.keyword(); - this.lab = request.lab(); - this.field = request.field(); - for (String newField : fileds) { - if (fieldNames.contains(newField)) { - this.etcField = false; - return; - } - this.etcField = true; - } - combineTotalInfo(nickName); - } - - private void combineTotalInfo(String nickName) { - this.totalInfo = major + lab + field + professor + postgradu + keyword + nickName; - } } diff --git a/src/main/java/com/postgraduate/domain/senior/domain/entity/Senior.java b/src/main/java/com/postgraduate/domain/senior/domain/entity/Senior.java index b8090a5e..9f006b4a 100644 --- a/src/main/java/com/postgraduate/domain/senior/domain/entity/Senior.java +++ b/src/main/java/com/postgraduate/domain/senior/domain/entity/Senior.java @@ -1,6 +1,5 @@ package com.postgraduate.domain.senior.domain.entity; -import com.postgraduate.domain.senior.application.dto.req.SeniorMyPageProfileRequest; import com.postgraduate.domain.senior.domain.entity.constant.Status; import com.postgraduate.domain.user.domain.entity.User; import jakarta.persistence.*; @@ -58,8 +57,8 @@ public void updateProfile(Profile profile) { this.profile = profile; } - public void updateInfo(SeniorMyPageProfileRequest myPageProfileRequest) { - this.info.updateMyPage(this.user.getNickName(), myPageProfileRequest); + public void updateInfo(Info info) { + this.info = info; } public void updateCertification(String certification) { diff --git a/src/main/java/com/postgraduate/domain/senior/domain/repository/SeniorDslRepositoryImpl.java b/src/main/java/com/postgraduate/domain/senior/domain/repository/SeniorDslRepositoryImpl.java index 88191cc6..613e8866 100644 --- a/src/main/java/com/postgraduate/domain/senior/domain/repository/SeniorDslRepositoryImpl.java +++ b/src/main/java/com/postgraduate/domain/senior/domain/repository/SeniorDslRepositoryImpl.java @@ -44,7 +44,8 @@ public Page findAllBySearchSenior(String search, String sort, Pageable p .leftJoin(senior.user, user) .fetchJoin() .where( - senior.info.totalInfo.like("%" + search + "%"), + senior.info.totalInfo.like("%" + search + "%") + .or(senior.user.nickName.like("%" + search + "%")), senior.status.eq(APPROVE), senior.user.isDelete.eq(FALSE), senior.profile.isNotNull() @@ -60,7 +61,8 @@ public Page findAllBySearchSenior(String search, String sort, Pageable p .distinct() .leftJoin(senior.user, user) .where( - senior.info.totalInfo.like("%" + search + "%"), + senior.info.totalInfo.like("%" + search + "%") + .or(senior.user.nickName.like("%" + search + "%")), senior.status.eq(APPROVE), senior.user.isDelete.eq(FALSE) ) diff --git a/src/main/java/com/postgraduate/domain/senior/domain/service/SeniorUpdateService.java b/src/main/java/com/postgraduate/domain/senior/domain/service/SeniorUpdateService.java index f427015c..16877e9e 100644 --- a/src/main/java/com/postgraduate/domain/senior/domain/service/SeniorUpdateService.java +++ b/src/main/java/com/postgraduate/domain/senior/domain/service/SeniorUpdateService.java @@ -1,6 +1,6 @@ package com.postgraduate.domain.senior.domain.service; -import com.postgraduate.domain.senior.application.dto.req.SeniorMyPageProfileRequest; +import com.postgraduate.domain.senior.domain.entity.Info; import com.postgraduate.domain.senior.domain.entity.Profile; import com.postgraduate.domain.senior.domain.entity.Senior; import lombok.RequiredArgsConstructor; @@ -20,9 +20,9 @@ public void updateCertification(Senior senior, String imageUrl) { senior.updateStatus(WAITING); } - public void updateMyPageProfile(Senior senior, SeniorMyPageProfileRequest myPageProfileRequest, Profile profile) { + public void updateMyPageProfile(Senior senior, Info info, Profile profile) { senior.updateProfile(profile); - senior.updateInfo(myPageProfileRequest); + senior.updateInfo(info); } public void updateHit(Senior senior) { diff --git a/src/test/java/com/postgraduate/domain/senior/application/usecase/SeniorManageUseCaseTest.java b/src/test/java/com/postgraduate/domain/senior/application/usecase/SeniorManageUseCaseTest.java index 4a0ab3a1..b90f798d 100644 --- a/src/test/java/com/postgraduate/domain/senior/application/usecase/SeniorManageUseCaseTest.java +++ b/src/test/java/com/postgraduate/domain/senior/application/usecase/SeniorManageUseCaseTest.java @@ -181,13 +181,17 @@ void invalidKeyword() { void updateSeniorMyPage() { SeniorMyPageProfileRequest request = mock(SeniorMyPageProfileRequest.class); + given(request.field()) + .willReturn("a,b,c"); + given(request.keyword()) + .willReturn("a,b,c"); given(seniorGetService.byUser(user)) .willReturn(senior); SeniorProfileUpdateResponse response = seniorManageUseCase.updateSeniorMyPageProfile(user, request); verify(seniorUpdateService, times(1)) - .updateMyPageProfile(any(Senior.class), any(SeniorMyPageProfileRequest.class), any(Profile.class)); + .updateMyPageProfile(any(Senior.class), any(Info.class), any(Profile.class)); verify(availableDeleteService, times(1)) .delete(senior); assertThat(response.seniorId()) diff --git a/src/test/java/com/postgraduate/domain/senior/domain/service/SeniorUpdateServiceTest.java b/src/test/java/com/postgraduate/domain/senior/domain/service/SeniorUpdateServiceTest.java index 7a6be8ea..a64eaf7f 100644 --- a/src/test/java/com/postgraduate/domain/senior/domain/service/SeniorUpdateServiceTest.java +++ b/src/test/java/com/postgraduate/domain/senior/domain/service/SeniorUpdateServiceTest.java @@ -14,6 +14,7 @@ import org.mockito.InjectMocks; import org.mockito.junit.jupiter.MockitoExtension; +import static com.postgraduate.domain.senior.application.mapper.SeniorMapper.mapToInfo; import static com.postgraduate.domain.senior.application.mapper.SeniorMapper.mapToProfile; import static com.postgraduate.domain.senior.domain.entity.constant.Status.APPROVE; import static com.postgraduate.domain.user.domain.entity.constant.Role.SENIOR; @@ -76,15 +77,16 @@ void updateMyPageProfile() { of(availableCreateRequest1, availableCreateRequest2, availableCreateRequest3) ); Profile profile = mapToProfile(request); - seniorUpdateService.updateMyPageProfile(senior, request, profile); - Info info = senior.getInfo(); + Info info = mapToInfo(senior, request); + seniorUpdateService.updateMyPageProfile(senior, info, profile); + Info changeInfo = senior.getInfo(); Profile changeProfile = senior.getProfile(); - assertThat(info.getKeyword()) + assertThat(changeInfo.getKeyword()) .isEqualTo(request.keyword()); - assertThat(info.getLab()) + assertThat(changeInfo.getLab()) .isEqualTo(request.lab()); - assertThat(info.getField()) + assertThat(changeInfo.getField()) .isEqualTo(request.field()); assertThat(changeProfile.getTerm())