Skip to content

Commit

Permalink
Merge pull request #225 from WE-ARE-RACCOONS/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
ywj9811 authored Apr 12, 2024
2 parents 26f9464 + b6fdca9 commit 2a619e6
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> fieldNames = Field.fieldNames();
Set<String> 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<String> fieldNames = Field.fieldNames();
Set<String> postgraduNames = Postgradu.postgraduNames();
Expand All @@ -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)) {
Expand All @@ -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<String> 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())
Expand All @@ -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<String> fieldNames = Field.fieldNames();
Set<String> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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<AvailableCreateRequest> availableCreateRequests = myPageProfileRequest.times();
List<Available> sortedAvailable = sortAvailable(availableCreateRequests, senior);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
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;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.Set;

@Getter
@AllArgsConstructor
@NoArgsConstructor
Expand Down Expand Up @@ -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<String> 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;
}
}
Original file line number Diff line number Diff line change
@@ -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.*;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public Page<Senior> 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()
Expand All @@ -60,7 +61,8 @@ public Page<Senior> 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)
)
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit 2a619e6

Please sign in to comment.