diff --git a/src/main/java/com/postgraduate/domain/account/application/mapper/AccountMapper.java b/src/main/java/com/postgraduate/domain/account/application/mapper/AccountMapper.java index 056fb42e..c967fe41 100644 --- a/src/main/java/com/postgraduate/domain/account/application/mapper/AccountMapper.java +++ b/src/main/java/com/postgraduate/domain/account/application/mapper/AccountMapper.java @@ -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(); } } diff --git a/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringManageUseCase.java b/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringManageUseCase.java index 8ca84a16..4ed5c0ed 100644 --- a/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringManageUseCase.java +++ b/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringManageUseCase.java @@ -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 mentorings = mentoringGetService.byStatusAndCreatedAt(WAITING, now); for (Mentoring mentoring : mentorings) { diff --git a/src/main/java/com/postgraduate/domain/senior/application/dto/res/SeniorInfoResponse.java b/src/main/java/com/postgraduate/domain/senior/application/dto/res/SeniorInfoResponse.java index 699760fb..27bbc6cd 100644 --- a/src/main/java/com/postgraduate/domain/senior/application/dto/res/SeniorInfoResponse.java +++ b/src/main/java/com/postgraduate/domain/senior/application/dto/res/SeniorInfoResponse.java @@ -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; @@ -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; } diff --git a/src/main/java/com/postgraduate/domain/senior/application/dto/res/SeniorMyPageResponse.java b/src/main/java/com/postgraduate/domain/senior/application/dto/res/SeniorMyPageResponse.java new file mode 100644 index 00000000..2d199b75 --- /dev/null +++ b/src/main/java/com/postgraduate/domain/senior/application/dto/res/SeniorMyPageResponse.java @@ -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; +} 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 513194f3..3720132d 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 @@ -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; @@ -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) @@ -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() 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 24a9c82c..a7afa8f7 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 @@ -1,12 +1,12 @@ 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; @@ -14,6 +14,8 @@ 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; @@ -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); @@ -45,9 +49,17 @@ public void updateAccount(User user, SeniorAccountRequest accountRequest) { Senior senior = seniorGetService.byUser(user); Optional 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); + } } diff --git a/src/main/java/com/postgraduate/domain/senior/application/usecase/SeniorMyPageUseCase.java b/src/main/java/com/postgraduate/domain/senior/application/usecase/SeniorMyPageUseCase.java index cf958247..c61f6647 100644 --- a/src/main/java/com/postgraduate/domain/senior/application/usecase/SeniorMyPageUseCase.java +++ b/src/main/java/com/postgraduate/domain/senior/application/usecase/SeniorMyPageUseCase.java @@ -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; @@ -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 @@ -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 = 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); } } diff --git a/src/main/java/com/postgraduate/domain/senior/presentation/SeniorController.java b/src/main/java/com/postgraduate/domain/senior/presentation/SeniorController.java index 70ec46d4..d03c83f4 100644 --- a/src/main/java/com/postgraduate/domain/senior/presentation/SeniorController.java +++ b/src/main/java/com/postgraduate/domain/senior/presentation/SeniorController.java @@ -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; @@ -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.*; @@ -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 담아서 요청") @@ -57,23 +54,23 @@ public ResponseDto updateAccount(@AuthenticationPrincipal User user, @GetMapping("/me") @Operation(summary = "대학원생 마이페이지 기본 정보 조회", description = "닉네임, 프로필 사진, 인증 여부") - public ResponseDto getSeniorInfo(@AuthenticationPrincipal User user) { - SeniorInfoResponse seniorInfoResponse = seniorMyPageUseCase.seniorInfo(user); - return ResponseDto.create(SENIOR_FIND.getCode(), GET_SENIOR_INFO.getMessage(), seniorInfoResponse); + public ResponseDto 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 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 getSeniorDetails(@PathVariable Long seniorId) { - SeniorDetailResponse seniorDetail = seniorInfoUseCase.getSeniorDetail(seniorId); - return ResponseDto.create(SENIOR_FIND.getCode(), GET_SENIOR_INFO.getMessage(), seniorDetail); - } } diff --git a/src/main/java/com/postgraduate/domain/user/application/dto/req/UserInfoRequest.java b/src/main/java/com/postgraduate/domain/user/application/dto/req/UserInfoRequest.java new file mode 100644 index 00000000..29410a30 --- /dev/null +++ b/src/main/java/com/postgraduate/domain/user/application/dto/req/UserInfoRequest.java @@ -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; +} diff --git a/src/main/java/com/postgraduate/domain/user/application/dto/res/UserInfoResponse.java b/src/main/java/com/postgraduate/domain/user/application/dto/res/UserInfoResponse.java index 1ee91e66..68f65e5d 100644 --- a/src/main/java/com/postgraduate/domain/user/application/dto/res/UserInfoResponse.java +++ b/src/main/java/com/postgraduate/domain/user/application/dto/res/UserInfoResponse.java @@ -8,6 +8,7 @@ @Builder @AllArgsConstructor public class UserInfoResponse { - private String nickName; private String profile; -} \ No newline at end of file + private String nickName; + private String phoneNumber; +} diff --git a/src/main/java/com/postgraduate/domain/user/application/dto/res/UserMyPageResponse.java b/src/main/java/com/postgraduate/domain/user/application/dto/res/UserMyPageResponse.java new file mode 100644 index 00000000..c40a0a2c --- /dev/null +++ b/src/main/java/com/postgraduate/domain/user/application/dto/res/UserMyPageResponse.java @@ -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; +} \ No newline at end of file diff --git a/src/main/java/com/postgraduate/domain/user/application/mapper/UserMapper.java b/src/main/java/com/postgraduate/domain/user/application/mapper/UserMapper.java index 3caff08b..f3480f3b 100644 --- a/src/main/java/com/postgraduate/domain/user/application/mapper/UserMapper.java +++ b/src/main/java/com/postgraduate/domain/user/application/mapper/UserMapper.java @@ -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(); } diff --git a/src/main/java/com/postgraduate/domain/user/application/usecase/UserManageUseCase.java b/src/main/java/com/postgraduate/domain/user/application/usecase/UserManageUseCase.java index b9e62560..45c13be9 100644 --- a/src/main/java/com/postgraduate/domain/user/application/usecase/UserManageUseCase.java +++ b/src/main/java/com/postgraduate/domain/user/application/usecase/UserManageUseCase.java @@ -1,5 +1,8 @@ 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; @@ -7,6 +10,8 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import static com.postgraduate.domain.user.application.mapper.UserMapper.mapToInfo; + @Transactional @Service @RequiredArgsConstructor @@ -14,12 +19,8 @@ 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) { diff --git a/src/main/java/com/postgraduate/domain/user/application/usecase/UserMyPageUseCase.java b/src/main/java/com/postgraduate/domain/user/application/usecase/UserMyPageUseCase.java index 45c89608..83c7a3e0 100644 --- a/src/main/java/com/postgraduate/domain/user/application/usecase/UserMyPageUseCase.java +++ b/src/main/java/com/postgraduate/domain/user/application/usecase/UserMyPageUseCase.java @@ -1,19 +1,33 @@ package com.postgraduate.domain.user.application.usecase; import com.postgraduate.domain.user.application.dto.res.UserInfoResponse; +import com.postgraduate.domain.user.application.dto.res.UserMyPageResponse; 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 com.postgraduate.domain.user.domain.entity.constant.Role; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import static com.postgraduate.domain.user.application.mapper.UserMapper.mapToInfo; +import static com.postgraduate.domain.user.domain.entity.constant.Role.SENIOR; + @Service @Transactional @RequiredArgsConstructor public class UserMyPageUseCase { - public UserInfoResponse getUserInfo(User user) { - return UserMapper.mapToInfo(user); + public UserMyPageResponse getUserInfo(User user) { + return UserMapper.mapToMyPageInfo(user); + } + + public UserInfoResponse getUserOriginInfo(User user) { + return mapToInfo(user); + } + + public boolean checkSenior(User user) { + Role role = user.getRole(); + if (role.equals(SENIOR)) + return true; + return false; } } diff --git a/src/main/java/com/postgraduate/domain/user/domain/entity/User.java b/src/main/java/com/postgraduate/domain/user/domain/entity/User.java index 34c5406d..048b0c62 100644 --- a/src/main/java/com/postgraduate/domain/user/domain/entity/User.java +++ b/src/main/java/com/postgraduate/domain/user/domain/entity/User.java @@ -66,6 +66,12 @@ public void updateProfile(String profile) { this.profile = profile; } + public void updateInfo(String profile, String nickName, String phoneNumber) { + this.profile = profile; + this.nickName = nickName; + this.phoneNumber = phoneNumber; + } + public void updateSeniorMyPage(SeniorMyPageProfileRequest request) { this.profile = request.getProfile(); this.nickName = request.getNickName(); diff --git a/src/main/java/com/postgraduate/domain/user/domain/service/UserUpdateService.java b/src/main/java/com/postgraduate/domain/user/domain/service/UserUpdateService.java index 7524ae7c..c7ad208d 100644 --- a/src/main/java/com/postgraduate/domain/user/domain/service/UserUpdateService.java +++ b/src/main/java/com/postgraduate/domain/user/domain/service/UserUpdateService.java @@ -1,6 +1,7 @@ package com.postgraduate.domain.user.domain.service; import com.postgraduate.domain.senior.application.dto.req.SeniorMyPageProfileRequest; +import com.postgraduate.domain.user.application.dto.req.UserInfoRequest; import com.postgraduate.domain.user.domain.entity.User; import com.postgraduate.domain.user.domain.entity.constant.Role; import com.postgraduate.domain.user.domain.repository.UserRepository; @@ -12,19 +13,18 @@ public class UserUpdateService { private final UserRepository userRepository; - public void updateNickName(Long userId, String nickName) { - User user = userRepository.findById(userId).get(); - user.updateNickName(nickName); - } - public void updateRole(Long userId, Role role) { User user = userRepository.findById(userId).get(); user.updateRole(role); } - public void updateProfile(Long userId, String profile) { + public void updateInfo(Long userId, UserInfoRequest userInfoRequest) { User user = userRepository.findById(userId).get(); - user.updateProfile(profile); + user.updateInfo( + userInfoRequest.getProfile(), + userInfoRequest.getNickName(), + userInfoRequest.getPhoneNumber() + ); } public void updateSeniorMyPage(Long userId, SeniorMyPageProfileRequest myPageProfileRequest) { diff --git a/src/main/java/com/postgraduate/domain/user/presentation/UserController.java b/src/main/java/com/postgraduate/domain/user/presentation/UserController.java index 99dea856..b45f8e96 100644 --- a/src/main/java/com/postgraduate/domain/user/presentation/UserController.java +++ b/src/main/java/com/postgraduate/domain/user/presentation/UserController.java @@ -1,8 +1,8 @@ package com.postgraduate.domain.user.presentation; -import com.postgraduate.domain.user.application.dto.req.UserNickNameRequest; -import com.postgraduate.domain.user.application.dto.req.UserProfileRequest; +import com.postgraduate.domain.user.application.dto.req.UserInfoRequest; import com.postgraduate.domain.user.application.dto.res.UserInfoResponse; +import com.postgraduate.domain.user.application.dto.res.UserMyPageResponse; import com.postgraduate.domain.user.application.usecase.UserManageUseCase; import com.postgraduate.domain.user.application.usecase.UserMyPageUseCase; import com.postgraduate.domain.user.domain.entity.User; @@ -26,30 +26,37 @@ public class UserController { private final UserManageUseCase manageUseCase; @GetMapping("/me") - @Operation(description = "사용자 기본 정보 조회 - 닉네임, 프로필") - public ResponseDto getUserInfo(@AuthenticationPrincipal User user) { - UserInfoResponse userInfo = myPageUseCase.getUserInfo(user); + @Operation(description = "사용자 마이페이지 정보 조회 - 닉네임, 프로필") + public ResponseDto getUserInfo(@AuthenticationPrincipal User user) { + UserMyPageResponse userInfo = myPageUseCase.getUserInfo(user); return ResponseDto.create(USER_FIND.getCode(), GET_USER_INFO.getMessage(), userInfo); } - @PatchMapping("/nickname") - @Operation(description = "사용자 닉네임 변경 및 업데이트") - public ResponseDto updateNickName(@AuthenticationPrincipal User user, @RequestBody UserNickNameRequest userNickNameRequest) { - manageUseCase.updateNickName(user, userNickNameRequest.getNickName()); + @GetMapping("/me/info") + @Operation(description = "대학생 마이페이지 정보 수정시 기존 정보 조회") + public ResponseDto getOriginUserInfo(@AuthenticationPrincipal User user) { + UserInfoResponse originInfo = myPageUseCase.getUserOriginInfo(user); + return ResponseDto.create(USER_FIND.getCode(), GET_USER_INFO.getMessage(), originInfo); + } + + @PatchMapping("/me/info") + @Operation(description = "대학생 마이페이지 정보 수정 - 프로필사진, 닉네임, 번호") + public ResponseDto updateInfo(@AuthenticationPrincipal User user, @RequestBody UserInfoRequest userInfoRequest) { + manageUseCase.updateInfo(user, userInfoRequest); return ResponseDto.create(USER_UPDATE.getCode(), UPDATE_USER_INFO.getMessage()); } + @GetMapping("/me/role") + @Operation(description = "선배 전환시 가능 여부 확인 - true,false") + public ResponseDto checkRole(@AuthenticationPrincipal User user) { + boolean isOk = myPageUseCase.checkSenior(user); + return ResponseDto.create(USER_FIND.getCode(), GET_SENIOR_CHECK.getMessage(), isOk); + } + @GetMapping("/nickname") @Operation(description = "사용자 닉네임 중복체크") public ResponseDto duplicatedNickName(@RequestParam String nickName) { boolean checkDup = manageUseCase.duplicatedNickName(nickName); return ResponseDto.create(USER_FIND.getCode(), GET_NICKNAME_CHECK.getMessage(), checkDup); } - - @PatchMapping("/profile") - @Operation(description = "사용자 프로필 사진 업데이트 - url을 주세요") - public ResponseDto updateProfile(@AuthenticationPrincipal User user, @RequestBody UserProfileRequest userProfileRequest) { - manageUseCase.updateProfile(user, userProfileRequest.getProfile()); - return ResponseDto.create(USER_UPDATE.getCode(), UPDATE_USER_INFO.getMessage()); - } } diff --git a/src/main/java/com/postgraduate/domain/user/presentation/constant/UserResponseMessage.java b/src/main/java/com/postgraduate/domain/user/presentation/constant/UserResponseMessage.java index 283569cb..323a320a 100644 --- a/src/main/java/com/postgraduate/domain/user/presentation/constant/UserResponseMessage.java +++ b/src/main/java/com/postgraduate/domain/user/presentation/constant/UserResponseMessage.java @@ -9,6 +9,7 @@ public enum UserResponseMessage { GET_USER_INFO("사용자 기본 정보 조회에 성공하였습니다."), GET_USER_LIST_INFO("사용자 목록 조회에 성공하였습니다."), GET_NICKNAME_CHECK("닉네임 중복체크에 성공하였습니다."), + GET_SENIOR_CHECK("선배 변환 가능 여부 조회에 성공하였습니다."), UPDATE_USER_INFO("사용자 업데이트에 성공하였습니다."), NOT_FOUND_USER("등록된 사용자가 없습니다."); diff --git a/src/main/java/com/postgraduate/global/config/security/SecurityConfig.java b/src/main/java/com/postgraduate/global/config/security/SecurityConfig.java index e2ec972e..15895cc7 100644 --- a/src/main/java/com/postgraduate/global/config/security/SecurityConfig.java +++ b/src/main/java/com/postgraduate/global/config/security/SecurityConfig.java @@ -6,6 +6,7 @@ import com.postgraduate.global.config.security.jwt.JwtFilter; import com.postgraduate.global.config.security.jwt.JwtProvider; import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.web.builders.HttpSecurity; @@ -13,12 +14,17 @@ import org.springframework.security.config.annotation.web.configurers.HeadersConfigurer; import org.springframework.security.config.http.SessionCreationPolicy; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.security.crypto.encrypt.AesBytesEncryptor; import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.cors.CorsConfigurationSource; import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import java.util.UUID; + +import static java.util.UUID.randomUUID; + @Configuration @EnableWebSecurity @RequiredArgsConstructor @@ -27,9 +33,14 @@ public class SecurityConfig { private final JwtProvider jwtProvider; private final CustomAuthenticationEntryPoint customAuthenticationEntryPoint; private final CustomAccessDeniedHandler customAccessDeniedHandler; + @Value("${aesBytesEncryptor.secret}") + private String secretKey; + @Value("${aesBytesEncryptor.salt}") + private String salt; + @Bean - public BCryptPasswordEncoder encodePassword() { - return new BCryptPasswordEncoder(); + public AesBytesEncryptor aesBytesEncryptor() { + return new AesBytesEncryptor(secretKey, salt); } @Bean diff --git a/src/main/java/com/postgraduate/global/config/security/util/EncryptorUtils.java b/src/main/java/com/postgraduate/global/config/security/util/EncryptorUtils.java new file mode 100644 index 00000000..8566ecb0 --- /dev/null +++ b/src/main/java/com/postgraduate/global/config/security/util/EncryptorUtils.java @@ -0,0 +1,44 @@ +package com.postgraduate.global.config.security.util; + +import lombok.RequiredArgsConstructor; +import org.springframework.security.crypto.encrypt.AesBytesEncryptor; +import org.springframework.stereotype.Component; + +import java.nio.ByteBuffer; + +import static java.nio.charset.StandardCharsets.UTF_8; + +@Component +@RequiredArgsConstructor +public class EncryptorUtils { + private final AesBytesEncryptor encryptor; + + public String encryptData(String data) { + byte[] encrypt = encryptor.encrypt(data.getBytes(UTF_8)); + return byteArrayToString(encrypt); + } + + public String decryptData(String data) { + byte[] decryptBytes = stringToByteArray(data); + byte[] decrypt = encryptor.decrypt(decryptBytes); + return new String(decrypt, UTF_8); + } + + public String byteArrayToString(byte[] bytes) { + StringBuilder sb = new StringBuilder(); + for (byte abyte : bytes) { + sb.append(abyte); + sb.append(" "); + } + return sb.toString(); + } + + public byte[] stringToByteArray(String byteString) { + String[] split = byteString.split("\\s"); + ByteBuffer buffer = ByteBuffer.allocate(split.length); + for (String s : split) { + buffer.put((byte) Integer.parseInt(s)); + } + return buffer.array(); + } +} diff --git a/src/test/java/com/postgraduate/domain/user/application/usecase/UserMyPageUseCaseTest.java b/src/test/java/com/postgraduate/domain/user/application/usecase/UserMyPageUseCaseTest.java index b3cf1cba..36a0f54d 100644 --- a/src/test/java/com/postgraduate/domain/user/application/usecase/UserMyPageUseCaseTest.java +++ b/src/test/java/com/postgraduate/domain/user/application/usecase/UserMyPageUseCaseTest.java @@ -1,22 +1,9 @@ package com.postgraduate.domain.user.application.usecase; -import com.postgraduate.domain.user.application.dto.res.UserInfoResponse; -import com.postgraduate.domain.user.domain.entity.User; -import com.postgraduate.domain.user.domain.entity.constant.Role; -import com.postgraduate.domain.user.domain.service.UserGetService; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import java.time.LocalDate; -import java.util.Optional; - import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.BDDMockito.given; @ExtendWith(MockitoExtension.class) public class UserMyPageUseCaseTest { diff --git a/src/test/java/com/postgraduate/domain/user/presentation/UserControllerTest.java b/src/test/java/com/postgraduate/domain/user/presentation/UserControllerTest.java index 80aea55f..6aba047c 100644 --- a/src/test/java/com/postgraduate/domain/user/presentation/UserControllerTest.java +++ b/src/test/java/com/postgraduate/domain/user/presentation/UserControllerTest.java @@ -1,38 +1,9 @@ package com.postgraduate.domain.user.presentation; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.postgraduate.domain.user.application.dto.req.UserNickNameRequest; -import com.postgraduate.domain.user.application.dto.req.UserProfileRequest; -import com.postgraduate.domain.user.application.dto.res.UserInfoResponse; -import com.postgraduate.domain.user.application.usecase.UserMyPageUseCase; -import com.postgraduate.domain.user.domain.entity.User; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.http.MediaType; -import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.ResultActions; -import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; -import org.springframework.test.web.servlet.result.MockMvcResultHandlers; -import org.springframework.test.web.servlet.setup.MockMvcBuilders; -import org.springframework.web.context.WebApplicationContext; -import org.springframework.web.filter.CharacterEncodingFilter; -import java.time.LocalDate; - -import static com.postgraduate.domain.user.domain.entity.constant.Role.USER; -import static com.postgraduate.domain.user.presentation.constant.UserResponseCode.USER_FIND; -import static com.postgraduate.domain.user.presentation.constant.UserResponseCode.USER_UPDATE; -import static com.postgraduate.domain.user.presentation.constant.UserResponseMessage.GET_NICKNAME_CHECK; -import static com.postgraduate.domain.user.presentation.constant.UserResponseMessage.UPDATE_USER_INFO; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.BDDMockito.given; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @WebMvcTest(UserController.class) class UserControllerTest {