Skip to content

Commit

Permalink
Merge pull request #40 from WE-ARE-RACCOONS/RAC-146
Browse files Browse the repository at this point in the history
RAC-146 refactor : λ³€κ²½λœ μš”κ΅¬μ‚¬ν•­ 적용
  • Loading branch information
ywj9811 authored Nov 12, 2023
2 parents 25b6809 + 5ddf418 commit ff5a776
Show file tree
Hide file tree
Showing 23 changed files with 218 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ public class SignUpRequest {
@NotNull
private Long socialId;
@NotNull
private String phoneNumber;
@NotNull
private String nickName;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.Optional;

@Builder
@Getter
@NoArgsConstructor
@AllArgsConstructor
public class AuthUserResponse {
private Optional<User> user;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.postgraduate.domain.mentoring.application.dto;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;


@Getter
@Builder
@AllArgsConstructor
public class DoneMentoringInfo {
Long mentoringId;
Long seniorId;
String nickName;
String postgradu;
String field;
String professor;
String date;
int term;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.postgraduate.domain.mentoring.application.dto;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -8,14 +9,14 @@
@Getter
@Builder
@AllArgsConstructor
public class AppliedMentoringInfo {
public class ExpectedMentoringInfo {
Long mentoringId;
Long seniorId;
String nickName;
String postgradu;
String field;
String professor;
String[] dates;
String date;
int term;
String chatLink;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.postgraduate.domain.mentoring.application.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;


@Getter
@Builder
@AllArgsConstructor
public class WaitingMentoringInfo {
Long mentoringId;
Long seniorId;
String nickName;
String postgradu;
String field;
String major;
int term;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.postgraduate.domain.mentoring.application.dto.res;

import com.postgraduate.domain.mentoring.application.dto.AppliedMentoringInfo;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -11,5 +10,5 @@
@Builder
@AllArgsConstructor
public class AppliedMentoringResponse {
List<AppliedMentoringInfo> appliedMentoringInfos;
List<?> appliedMentoringInfos;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.postgraduate.domain.mentoring.application.mapper;

import com.postgraduate.domain.mentoring.application.dto.AppliedMentoringInfo;
import com.postgraduate.domain.mentoring.application.dto.DoneMentoringInfo;
import com.postgraduate.domain.mentoring.application.dto.ExpectedMentoringInfo;
import com.postgraduate.domain.mentoring.application.dto.WaitingMentoringInfo;
import com.postgraduate.domain.mentoring.application.dto.req.MentoringApplyRequest;
import com.postgraduate.domain.mentoring.application.dto.res.AppliedMentoringDetailResponse;
import com.postgraduate.domain.mentoring.application.dto.res.SeniorMentoringDetailResponse;
Expand All @@ -13,32 +15,45 @@
import java.util.stream.Stream;

public class MentoringMapper {
public static AppliedMentoringInfo mapToExpectedAppliedInfo(Mentoring mentoring) {
public static ExpectedMentoringInfo mapToExpectedInfo(Mentoring mentoring) {
Senior senior = mentoring.getSenior();
String[] dates = mentoring.getDate().split(",");
return AppliedMentoringInfo.builder()
return ExpectedMentoringInfo.builder()
.mentoringId(mentoring.getMentoringId())
.dates(dates)
.seniorId(senior.getSeniorId())
.nickName(senior.getUser().getNickName())
.postgradu(senior.getInfo().getPostgradu())
.professor(senior.getInfo().getProfessor())
.field(senior.getInfo().getField())
.term(senior.getProfile().getTerm())
.date(mentoring.getDate())
.chatLink(senior.getProfile().getChatLink())
.build();
}
public static AppliedMentoringInfo mapToWaitingOrDoneAppliedInfo(Mentoring mentoring) {

public static DoneMentoringInfo mapToDoneInfo(Mentoring mentoring) {
Senior senior = mentoring.getSenior();
String[] dates = mentoring.getDate().split(",");
return AppliedMentoringInfo.builder()
return DoneMentoringInfo.builder()
.mentoringId(mentoring.getMentoringId())
.dates(dates)
.term(senior.getProfile().getTerm())
.seniorId(senior.getSeniorId())
.nickName(senior.getUser().getNickName())
.postgradu(senior.getInfo().getPostgradu())
.professor(senior.getInfo().getProfessor())
.field(senior.getInfo().getField())
.term(senior.getProfile().getTerm())
.date(mentoring.getDate())
.build();
}

public static WaitingMentoringInfo mapToWaitingInfo(Mentoring mentoring) {
Senior senior = mentoring.getSenior();
return WaitingMentoringInfo.builder()
.mentoringId(mentoring.getMentoringId())
.term(senior.getProfile().getTerm())
.seniorId(senior.getSeniorId())
.nickName(senior.getUser().getNickName())
.postgradu(senior.getInfo().getPostgradu())
.major(senior.getInfo().getMajor())
.field(senior.getInfo().getField())
.build();
}
public static AppliedMentoringDetailResponse mapToAppliedDetailInfo(Mentoring mentoring) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.postgraduate.domain.mentoring.application.usecase;

import com.postgraduate.domain.mentoring.application.dto.AppliedMentoringInfo;
import com.postgraduate.domain.mentoring.application.dto.DoneMentoringInfo;
import com.postgraduate.domain.mentoring.application.dto.ExpectedMentoringInfo;
import com.postgraduate.domain.mentoring.application.dto.WaitingMentoringInfo;
import com.postgraduate.domain.mentoring.application.dto.res.AppliedMentoringDetailResponse;
import com.postgraduate.domain.mentoring.application.dto.res.AppliedMentoringResponse;
import com.postgraduate.domain.mentoring.application.dto.res.SeniorMentoringDetailResponse;
Expand All @@ -22,8 +24,7 @@
import java.util.List;
import java.util.stream.Collectors;

import static com.postgraduate.domain.mentoring.domain.entity.constant.Status.DONE;
import static com.postgraduate.domain.mentoring.domain.entity.constant.Status.WAITING;
import static com.postgraduate.domain.mentoring.domain.entity.constant.Status.*;

@Service
@Transactional
Expand All @@ -33,9 +34,21 @@ public class MentoringInfoUseCase {
private final CheckIsMyMentoringUseCase checkIsMyMentoringUseCase;
private final SeniorGetService seniorGetService;

public AppliedMentoringResponse getMentorings(Status status, User user) {
List<Mentoring> mentorings = mentoringGetService.mentoringByUser(user, status);
return getCategories(status, mentorings);

public AppliedMentoringDetailResponse getMentoringDetail(User user, Long mentoringId) {
Mentoring mentoring = checkIsMyMentoringUseCase.byUser(user, mentoringId);
if (mentoring.getStatus() != WAITING) {
throw new MentoringNotWaitingException();
}
return MentoringMapper.mapToAppliedDetailInfo(mentoring);
}

public SeniorMentoringDetailResponse getSeniorMentoringDetail(User user, Long mentoringId) {
Mentoring mentoring = checkIsMyMentoringUseCase.bySenior(user, mentoringId);
if (mentoring.getStatus() == DONE) {
throw new MentoringDoneException();
}
return MentoringMapper.mapToSeniorMentoringDetail(mentoring);
}

public List<SeniorMentoringResponse> getSeniorMentorings(Status status, User user) {
Expand All @@ -45,39 +58,42 @@ public List<SeniorMentoringResponse> getSeniorMentorings(Status status, User use
return mentorings.stream().map(MentoringMapper::mapToSeniorMentoring).collect(Collectors.toList());
}

private AppliedMentoringResponse getCategories(Status status, List<Mentoring> mentorings) {
List<AppliedMentoringInfo> appliedMentoringInfos = new ArrayList<>();
public AppliedMentoringResponse getMentorings(Status status, User user) {
List<Mentoring> mentorings = mentoringGetService.mentoringByUser(user, status);
return getCategories(status, mentorings);
}

switch (status) {
case WAITING, DONE -> {
for (Mentoring mentoring : mentorings) {
appliedMentoringInfos.add(MentoringMapper.mapToWaitingOrDoneAppliedInfo(mentoring));
}
return new AppliedMentoringResponse(appliedMentoringInfos);
}
private AppliedMentoringResponse getCategories(Status status, List<Mentoring> mentorings) {
if (status == WAITING) {
return getWaiting(mentorings);
}
if (status == EXPECTED) {
return getExpected(mentorings);
}
return getDone(mentorings);
}

default -> {
for (Mentoring mentoring : mentorings) {
appliedMentoringInfos.add(MentoringMapper.mapToExpectedAppliedInfo(mentoring));
}
return new AppliedMentoringResponse(appliedMentoringInfos);
}
private AppliedMentoringResponse getWaiting(List<Mentoring> mentorings) {
List<WaitingMentoringInfo> waitingMentoringInfos = new ArrayList<>();
for (Mentoring mentoring : mentorings) {
waitingMentoringInfos.add(MentoringMapper.mapToWaitingInfo(mentoring));
}
return new AppliedMentoringResponse(waitingMentoringInfos);
}

public AppliedMentoringDetailResponse getMentoringDetail(User user, Long mentoringId) {
Mentoring mentoring = checkIsMyMentoringUseCase.byUser(user, mentoringId);
if (mentoring.getStatus() != WAITING) {
throw new MentoringNotWaitingException();
private AppliedMentoringResponse getExpected(List<Mentoring> mentorings) {
List<ExpectedMentoringInfo> expectedMentoringInfos = new ArrayList<>();
for (Mentoring mentoring : mentorings) {
expectedMentoringInfos.add(MentoringMapper.mapToExpectedInfo(mentoring));
}
return MentoringMapper.mapToAppliedDetailInfo(mentoring);
return new AppliedMentoringResponse(expectedMentoringInfos);
}

public SeniorMentoringDetailResponse getSeniorMentoringDetail(User user, Long mentoringId) {
Mentoring mentoring = checkIsMyMentoringUseCase.bySenior(user, mentoringId);
if (mentoring.getStatus() == DONE) {
throw new MentoringDoneException();
private AppliedMentoringResponse getDone(List<Mentoring> mentorings) {
List<DoneMentoringInfo> doneMentoringInfos = new ArrayList<>();
for (Mentoring mentoring : mentorings) {
doneMentoringInfos.add(MentoringMapper.mapToDoneInfo(mentoring));
}
return MentoringMapper.mapToSeniorMentoringDetail(mentoring);
return new AppliedMentoringResponse(doneMentoringInfos);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ public class SeniorProfileAndAccountRequest {
@NotNull
private String time;
@NotNull
private String oneLiner;
@NotNull
private String keyword;
@NotNull
private String account;
@NotNull
private String bank;
@NotNull
private String rrn;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@ public class SeniorProfileRequest {
private String chatLink;
@NotNull
private String time;
@NotNull
private String oneLiner;
@NotNull
private String keyword;
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public static Account mapToAccount(SeniorProfileAndAccountRequest profileAndAcco
return Account.builder()
.bank(profileAndAccountPageRequest.getBank())
.account(profileAndAccountPageRequest.getAccount())
.rrn(profileAndAccountPageRequest.getRrn())
.build();
}

Expand All @@ -56,13 +55,17 @@ public static Profile mapToProfile(SeniorProfileAndAccountRequest profileAndAcco
.chatLink(profileAndAccountPageRequest.getChatLink())
.target(profileAndAccountPageRequest.getTarget())
.time(profileAndAccountPageRequest.getTime())
.oneLiner(profileAndAccountPageRequest.getOneLiner())
.keyword(profileAndAccountPageRequest.getKeyword())
.build();
}

public static Profile mapToProfile(SeniorProfileRequest profileRequest) {
return Profile.builder()
.info(profileRequest.getInfo())
.chatLink(profileRequest.getChatLink())
.oneLiner(profileRequest.getOneLiner())
.keyword(profileRequest.getKeyword())
.target(profileRequest.getTarget())
.time(profileRequest.getTime())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import com.postgraduate.domain.user.domain.entity.User;
import com.postgraduate.domain.user.domain.entity.constant.Role;
import com.postgraduate.domain.user.domain.service.UserUpdateService;
import com.postgraduate.global.config.security.util.SecurityUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,9 @@ public class Account {

@Column(nullable = false)
private String rrn;

public void updateAccount(Account account) {
this.account = account.getAccount();
this.bank = account.getBank();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@
public class Profile {
private String info;

private String oneLiner;

private String keyword;

private String target;

private String chatLink;

private String time;

private Integer term;
@Builder.Default
private Integer term = 40;
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void updateProfile(Profile profile) {

public void updateProfileAndAccount(Profile profile, Account account) {
this.profile = profile;
this.account = account;
account.updateAccount(account);
}

public void updateCertification(String certification) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
@RequiredArgsConstructor
public enum SeniorResponseMessage {
CREATE_SENIOR("λŒ€ν•™μ›μƒ κ°€μž…μ— μ„±κ³΅ν•˜μ˜€μŠ΅λ‹ˆλ‹€."),
UPDATE_PROFILE("λŒ€ν•™μ›μƒ ν”„λ‘œν•„ 등둝에 μ„±κ³΅ν•˜μ˜€μŠ΅λ‹ˆλ‹€"),
UPDATE_PROFILE("λŒ€ν•™μ›μƒ ν”„λ‘œν•„ μˆ˜μ •μ— μ„±κ³΅ν•˜μ˜€μŠ΅λ‹ˆλ‹€"),
GET_SENIOR_INFO("λŒ€ν•™μ›μƒ 정보 μ‘°νšŒμ— μ„±κ³΅ν•˜μ˜€μŠ΅λ‹ˆλ‹€"),
GET_SENIOR_PROFILE("λŒ€ν•™μ›μƒ ν”„λ‘œν•„ μ‘°νšŒμ— μ„±κ³΅ν•˜μ˜€μŠ΅λ‹ˆλ‹€"),
UPDATE_CERTIFICATION("λŒ€ν•™μ›μƒ 인증사진 μ—…λ‘œλ“œμ— μ„±κ³΅ν•˜μ˜€μŠ΅λ‹ˆλ‹€"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.postgraduate.domain.user.application.dto.req;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public class UserHopeRequest {
private String major;
private String field;
private boolean receive;
}
Loading

0 comments on commit ff5a776

Please sign in to comment.