Skip to content

Commit

Permalink
Merge pull request #52 from WE-ARE-RACCOONS/RAC-160
Browse files Browse the repository at this point in the history
RAC-160 refactor : ์š”๊ตฌ์‚ฌํ•ญ ๋ฐ˜์˜ ๋ฆฌํŒฉํ† ๋ง
  • Loading branch information
ywj9811 authored Nov 21, 2023
2 parents 65f07cc + f63b041 commit 4b8b1d7
Show file tree
Hide file tree
Showing 22 changed files with 249 additions and 123 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
import com.postgraduate.domain.senior.domain.entity.Senior;

public class AccountMapper {
public static Account mapToAccount(Senior senior, SeniorAccountRequest accountRequest) {
public static Account mapToAccount(Senior senior, SeniorAccountRequest accountRequest, String accountNumber, String rrn) {
return Account.builder()
.senior(senior)
.accountNumber(accountRequest.getAccountNumber())
.accountNumber(accountNumber)
.accountHolder(accountRequest.getAccountHolder())
.bank(accountRequest.getBank())
.name(accountRequest.getName())
.rrn(accountRequest.getRrn())
.rrn(rrn)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void updateExpected(User user, Long mentoringId, MentoringDateRequest dat
}

@Scheduled(cron = "0 0 0 * * *", zone = "Asia/Seoul")
private void updateCancel() {
public void updateCancel() {
LocalDate now = LocalDate.now();
List<Mentoring> mentorings = mentoringGetService.byStatusAndCreatedAt(WAITING, now);
for (Mentoring mentoring : mentorings) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.postgraduate.domain.senior.application.dto.res;

import com.postgraduate.domain.senior.domain.entity.constant.Status;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -9,10 +9,13 @@
@Getter
@AllArgsConstructor
public class SeniorInfoResponse {
private String nickName;
private String profile;
private int amount;
private String month;
private Status certificationRegister;
private boolean profileRegister;
private String nickName;
private String lab;
private String keyword;
private String info;
private String target;
private String chatLink;
private String field;
private String oneLiner;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.postgraduate.domain.senior.application.dto.res;

import com.postgraduate.domain.senior.domain.entity.constant.Status;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;

@Builder
@Getter
@AllArgsConstructor
public class SeniorMyPageResponse {
private String nickName;
private String profile;
private int amount;
private String month;
private Status certificationRegister;
private boolean profileRegister;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.postgraduate.domain.auth.application.dto.req.SeniorSignUpRequest;
import com.postgraduate.domain.senior.application.dto.res.SeniorDetailResponse;
import com.postgraduate.domain.senior.application.dto.res.SeniorInfoResponse;
import com.postgraduate.domain.senior.application.dto.res.SeniorMyPageResponse;
import com.postgraduate.domain.senior.domain.entity.Info;
import com.postgraduate.domain.senior.domain.entity.Profile;
import com.postgraduate.domain.senior.domain.entity.Senior;
Expand Down Expand Up @@ -62,8 +63,8 @@ public static Info mapToInfo(SeniorChangeRequest request) {
.build();
}

public static SeniorInfoResponse mapToSeniorInfo(Senior senior, Salary salary, String month, Status certificationRegister, boolean profileRegister) {
return SeniorInfoResponse.builder()
public static SeniorMyPageResponse mapToSeniorMyPageInfo(Senior senior, Salary salary, String month, Status certificationRegister, boolean profileRegister) {
return SeniorMyPageResponse.builder()
.nickName(senior.getUser().getNickName())
.profile(senior.getUser().getProfile())
.month(month)
Expand All @@ -73,6 +74,23 @@ public static SeniorInfoResponse mapToSeniorInfo(Senior senior, Salary salary, S
.build();
}

public static SeniorInfoResponse mapToOriginInfo(Senior senior) {
User user = senior.getUser();
Info info = senior.getInfo();
Profile profile = senior.getProfile();
return SeniorInfoResponse.builder()
.profile(user.getProfile())
.nickName(user.getNickName())
.lab(info.getLab())
.keyword(info.getKeyword())
.field(info.getField())
.info(profile.getInfo())
.target(profile.getTarget())
.chatLink(profile.getChatLink())
.oneLiner(profile.getOneLiner())
.build();
}

public static SeniorDetailResponse mapToSeniorDetail(Senior senior) {
String[] keyword = senior.getInfo().getKeyword().split(",");
return SeniorDetailResponse.builder()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
package com.postgraduate.domain.senior.application.usecase;

import com.postgraduate.domain.account.application.mapper.AccountMapper;
import com.postgraduate.domain.account.domain.entity.Account;
import com.postgraduate.domain.account.domain.service.AccountGetService;
import com.postgraduate.domain.account.domain.service.AccountSaveService;
import com.postgraduate.domain.account.domain.service.AccountUpdateService;
import com.postgraduate.domain.senior.application.dto.req.SeniorAccountRequest;
import com.postgraduate.domain.senior.application.dto.req.SeniorCertificationRequest;
import com.postgraduate.domain.senior.application.dto.req.SeniorMyPageProfileRequest;
import com.postgraduate.domain.senior.application.dto.req.SeniorProfileRequest;
import com.postgraduate.domain.senior.application.mapper.SeniorMapper;
import com.postgraduate.domain.senior.domain.entity.Profile;
import com.postgraduate.domain.senior.domain.entity.Senior;
import com.postgraduate.domain.senior.domain.service.SeniorGetService;
import com.postgraduate.domain.senior.domain.service.SeniorUpdateService;
import com.postgraduate.domain.user.domain.entity.User;
import com.postgraduate.domain.user.domain.service.UserUpdateService;
import com.postgraduate.global.config.security.util.EncryptorUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

Expand All @@ -24,11 +26,13 @@
@Service
@RequiredArgsConstructor
public class SeniorManageUseCase {
private final UserUpdateService userUpdateService;
private final SeniorUpdateService seniorUpdateService;
private final SeniorGetService seniorGetService;
private final AccountGetService accountGetService;
private final AccountSaveService accountSaveService;
private final AccountUpdateService accountUpdateService;
private final EncryptorUtils encryptorUtils;

public void updateCertification(User user, SeniorCertificationRequest certificationRequest) {
Senior senior = seniorGetService.byUser(user);
Expand All @@ -45,9 +49,17 @@ public void updateAccount(User user, SeniorAccountRequest accountRequest) {
Senior senior = seniorGetService.byUser(user);
Optional<Account> account = accountGetService.bySenior(senior);
if (account.isEmpty()) {
accountSaveService.saveAccount(mapToAccount(senior, accountRequest));
String accountNumber = encryptorUtils.encryptData(accountRequest.getAccountNumber());
String rrn = encryptorUtils.encryptData(accountRequest.getRrn());
accountSaveService.saveAccount(mapToAccount(senior, accountRequest, accountNumber, rrn));
return;
}
accountUpdateService.updateAccount(account.get(), accountRequest);
}

public void updateSeniorMyPageProfile(User user, SeniorMyPageProfileRequest myPageProfileRequest) {
userUpdateService.updateSeniorMyPage(user.getUserId(), myPageProfileRequest);
Senior senior = seniorGetService.byUser(user);
seniorUpdateService.updateMyPageProfile(senior, myPageProfileRequest);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@

import com.postgraduate.domain.salary.domain.entity.Salary;
import com.postgraduate.domain.salary.domain.service.SalaryGetService;
import com.postgraduate.domain.senior.application.dto.req.SeniorMyPageProfileRequest;
import com.postgraduate.domain.senior.application.dto.res.SeniorInfoResponse;
import com.postgraduate.domain.senior.application.mapper.SeniorMapper;
import com.postgraduate.domain.senior.application.dto.res.SeniorMyPageResponse;
import com.postgraduate.domain.senior.domain.entity.Profile;
import com.postgraduate.domain.senior.domain.entity.Senior;
import com.postgraduate.domain.senior.domain.entity.constant.Status;
import com.postgraduate.domain.senior.domain.service.SeniorGetService;
import com.postgraduate.domain.senior.domain.service.SeniorUpdateService;
import com.postgraduate.domain.user.domain.entity.User;
import com.postgraduate.domain.user.domain.service.UserUpdateService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -20,6 +17,8 @@
import java.util.Optional;

import static com.postgraduate.domain.salary.util.MonthFormat.getMonthFormat;
import static com.postgraduate.domain.senior.application.mapper.SeniorMapper.mapToOriginInfo;
import static com.postgraduate.domain.senior.application.mapper.SeniorMapper.mapToSeniorMyPageInfo;
import static java.util.Optional.ofNullable;

@Service
Expand All @@ -28,22 +27,19 @@
public class SeniorMyPageUseCase {
private final SeniorGetService seniorGetService;
private final SalaryGetService salaryGetService;
private final SeniorUpdateService seniorUpdateService;
private final UserUpdateService userUpdateService;

public SeniorInfoResponse seniorInfo(User user) {
public SeniorMyPageResponse getSeniorInfo(User user) {
Senior senior = seniorGetService.byUser(user);
String month = LocalDate.now().format(getMonthFormat());
Salary salary = salaryGetService.bySeniorAndMonth(senior, month)
.orElse(new Salary());
Status status = senior.getStatus();
Optional<Profile> profile = ofNullable(senior.getProfile());
return SeniorMapper.mapToSeniorInfo(senior, salary, month, status, profile.isPresent());
return mapToSeniorMyPageInfo(senior, salary, month, status, profile.isPresent());
}

public void updateSeniorMyPageProfile(User user, SeniorMyPageProfileRequest myPageProfileRequest) {
userUpdateService.updateSeniorMyPage(user.getUserId(), myPageProfileRequest);
public SeniorInfoResponse getSeniorOriginInfo(User user) {
Senior senior = seniorGetService.byUser(user);
seniorUpdateService.updateMyPageProfile(senior, myPageProfileRequest);
return mapToOriginInfo(senior);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
import com.postgraduate.domain.senior.application.dto.req.SeniorCertificationRequest;
import com.postgraduate.domain.senior.application.dto.req.SeniorMyPageProfileRequest;
import com.postgraduate.domain.senior.application.dto.req.SeniorProfileRequest;
import com.postgraduate.domain.senior.application.dto.res.SeniorDetailResponse;
import com.postgraduate.domain.senior.application.dto.res.SeniorInfoResponse;
import com.postgraduate.domain.senior.application.usecase.SeniorInfoUseCase;
import com.postgraduate.domain.senior.application.dto.res.SeniorMyPageResponse;
import com.postgraduate.domain.senior.application.usecase.SeniorManageUseCase;
import com.postgraduate.domain.senior.application.usecase.SeniorMyPageUseCase;
import com.postgraduate.domain.user.domain.entity.User;
Expand All @@ -17,8 +16,7 @@
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

import static com.postgraduate.domain.senior.presentation.constant.SeniorResponseCode.SENIOR_FIND;
import static com.postgraduate.domain.senior.presentation.constant.SeniorResponseCode.SENIOR_UPDATE;
import static com.postgraduate.domain.senior.presentation.constant.SeniorResponseCode.*;
import static com.postgraduate.domain.senior.presentation.constant.SeniorResponseMessage.*;


Expand All @@ -29,7 +27,6 @@
public class SeniorController {
private final SeniorMyPageUseCase seniorMyPageUseCase;
private final SeniorManageUseCase seniorManageUseCase;
private final SeniorInfoUseCase seniorInfoUseCase;

@PatchMapping("/certification")
@Operation(summary = "๋Œ€ํ•™์›์ƒ ์ธ์ฆ", description = "์ด๋ฏธ์ง€ ์—…๋กœ๋“œ ์ดํ›„ url ๋‹ด์•„์„œ ์š”์ฒญ")
Expand Down Expand Up @@ -57,23 +54,23 @@ public ResponseDto updateAccount(@AuthenticationPrincipal User user,

@GetMapping("/me")
@Operation(summary = "๋Œ€ํ•™์›์ƒ ๋งˆ์ดํŽ˜์ด์ง€ ๊ธฐ๋ณธ ์ •๋ณด ์กฐํšŒ", description = "๋‹‰๋„ค์ž„, ํ”„๋กœํ•„ ์‚ฌ์ง„, ์ธ์ฆ ์—ฌ๋ถ€")
public ResponseDto<SeniorInfoResponse> getSeniorInfo(@AuthenticationPrincipal User user) {
SeniorInfoResponse seniorInfoResponse = seniorMyPageUseCase.seniorInfo(user);
return ResponseDto.create(SENIOR_FIND.getCode(), GET_SENIOR_INFO.getMessage(), seniorInfoResponse);
public ResponseDto<SeniorMyPageResponse> getSeniorInfo(@AuthenticationPrincipal User user) {
SeniorMyPageResponse seniorMyPageResponse = seniorMyPageUseCase.getSeniorInfo(user);
return ResponseDto.create(SENIOR_FIND.getCode(), GET_SENIOR_INFO.getMessage(), seniorMyPageResponse);
}

@GetMapping("/me/profile")
@Operation(summary = "๋Œ€ํ•™์ƒ ๋งˆ์ดํŽ˜์ด์ง€ ํ”„๋กœํ•„ ์ˆ˜์ •์‹œ ๊ธฐ์กด ์ •๋ณด ์กฐํšŒ")
public ResponseDto<SeniorInfoResponse> getSeniorProfile(@AuthenticationPrincipal User user) {
SeniorInfoResponse seniorOriginInfo = seniorMyPageUseCase.getSeniorOriginInfo(user);
return ResponseDto.create(SENIOR_FIND.getCode(), GET_SENIOR_INFO.getMessage(), seniorOriginInfo);
}

@PatchMapping("/me/profile")
@Operation(summary = "๋Œ€ํ•™์›์ƒ ๋งˆ์ดํŽ˜์ด์ง€ ํ”„๋กœํ•„ ์ˆ˜์ •")
public ResponseDto getSeniorProfile(@AuthenticationPrincipal User user,
public ResponseDto updateSeniorProfile(@AuthenticationPrincipal User user,
@RequestBody SeniorMyPageProfileRequest myPageProfileRequest) {
seniorMyPageUseCase.updateSeniorMyPageProfile(user, myPageProfileRequest);
seniorManageUseCase.updateSeniorMyPageProfile(user, myPageProfileRequest);
return ResponseDto.create(SENIOR_UPDATE.getCode(), UPDATE_MYPAGE_PROFILE.getMessage());
}

@GetMapping("/{seniorId}")
@Operation(summary = "๋Œ€ํ•™์›์ƒ ์ƒ์„ธ ์กฐํšŒ")
public ResponseDto<SeniorDetailResponse> getSeniorDetails(@PathVariable Long seniorId) {
SeniorDetailResponse seniorDetail = seniorInfoUseCase.getSeniorDetail(seniorId);
return ResponseDto.create(SENIOR_FIND.getCode(), GET_SENIOR_INFO.getMessage(), seniorDetail);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.postgraduate.domain.user.application.dto.req;

import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@AllArgsConstructor
@NoArgsConstructor
public class UserInfoRequest {
@NotNull
private String profile;
@NotNull
private String nickName;
@NotNull
private String phoneNumber;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
@Builder
@AllArgsConstructor
public class UserInfoResponse {
private String nickName;
private String profile;
}
private String nickName;
private String phoneNumber;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.postgraduate.domain.user.application.dto.res;

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

@Getter
@Builder
@AllArgsConstructor
public class UserMyPageResponse {
private String nickName;
private String profile;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,24 @@
import com.postgraduate.domain.auth.application.dto.req.SeniorSignUpRequest;
import com.postgraduate.domain.auth.application.dto.req.SignUpRequest;
import com.postgraduate.domain.user.application.dto.res.UserInfoResponse;
import com.postgraduate.domain.user.application.dto.res.UserMyPageResponse;
import com.postgraduate.domain.user.domain.entity.User;
import com.postgraduate.domain.user.domain.entity.constant.Role;

import static com.postgraduate.domain.user.domain.entity.constant.Role.SENIOR;

public class UserMapper {
public static UserMyPageResponse mapToMyPageInfo(User user) {
return UserMyPageResponse.builder()
.nickName(user.getNickName())
.profile(user.getProfile())
.build();
}

public static UserInfoResponse mapToInfo(User user) {
return UserInfoResponse.builder()
.nickName(user.getNickName())
.profile(user.getProfile())
.nickName(user.getNickName())
.phoneNumber(user.getPhoneNumber())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
package com.postgraduate.domain.user.application.usecase;

import com.postgraduate.domain.user.application.dto.req.UserInfoRequest;
import com.postgraduate.domain.user.application.dto.res.UserInfoResponse;
import com.postgraduate.domain.user.application.mapper.UserMapper;
import com.postgraduate.domain.user.domain.entity.User;
import com.postgraduate.domain.user.domain.service.UserGetService;
import com.postgraduate.domain.user.domain.service.UserUpdateService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import static com.postgraduate.domain.user.application.mapper.UserMapper.mapToInfo;

@Transactional
@Service
@RequiredArgsConstructor
public class UserManageUseCase {
private final UserUpdateService userUpdateService;
private final UserGetService userGetService;

public void updateNickName(User user, String nickName) {
userUpdateService.updateNickName(user.getUserId(), nickName);
}

public void updateProfile(User user, String profile) {
userUpdateService.updateProfile(user.getUserId(), profile);
public void updateInfo(User user, UserInfoRequest userInfoRequest) {
userUpdateService.updateInfo(user.getUserId(), userInfoRequest);
}

public boolean duplicatedNickName(String nickName) {
Expand Down
Loading

0 comments on commit 4b8b1d7

Please sign in to comment.