diff --git a/src/main/java/com/postgraduate/admin/application/dto/res/WishResponse.java b/src/main/java/com/postgraduate/admin/application/dto/res/MatchingWishResponse.java similarity index 51% rename from src/main/java/com/postgraduate/admin/application/dto/res/WishResponse.java rename to src/main/java/com/postgraduate/admin/application/dto/res/MatchingWishResponse.java index b37289063..1beecc474 100644 --- a/src/main/java/com/postgraduate/admin/application/dto/res/WishResponse.java +++ b/src/main/java/com/postgraduate/admin/application/dto/res/MatchingWishResponse.java @@ -1,15 +1,16 @@ package com.postgraduate.admin.application.dto.res; + import java.time.LocalDateTime; -public record WishResponse( +public record MatchingWishResponse( Long wishId, - String nickName, + String field, + String postgradu, + String professor, + String lab, String phoneNumber, LocalDateTime createAt, - Boolean marketingReceive, - Boolean matchingReceive, - String major, - String field + LocalDateTime updatedAt ) { } diff --git a/src/main/java/com/postgraduate/admin/application/dto/res/MatchingWishResponses.java b/src/main/java/com/postgraduate/admin/application/dto/res/MatchingWishResponses.java new file mode 100644 index 000000000..820cda771 --- /dev/null +++ b/src/main/java/com/postgraduate/admin/application/dto/res/MatchingWishResponses.java @@ -0,0 +1,6 @@ +package com.postgraduate.admin.application.dto.res; + +import java.util.List; + +public record MatchingWishResponses(List wishResponses) { +} diff --git a/src/main/java/com/postgraduate/admin/application/dto/res/MentoringManageResponse.java b/src/main/java/com/postgraduate/admin/application/dto/res/MentoringManageResponse.java index 5c85a7c09..089e064c5 100644 --- a/src/main/java/com/postgraduate/admin/application/dto/res/MentoringManageResponse.java +++ b/src/main/java/com/postgraduate/admin/application/dto/res/MentoringManageResponse.java @@ -3,7 +3,7 @@ import java.util.List; public record MentoringManageResponse( - List mentoringInfo, - UserMentoringInfo userMentoringInfo + UserInfoBasic userInfoBasic, + List mentoringInfo ) { } diff --git a/src/main/java/com/postgraduate/admin/application/dto/res/PaymentInfos.java b/src/main/java/com/postgraduate/admin/application/dto/res/PaymentInfos.java new file mode 100644 index 000000000..5fd13c854 --- /dev/null +++ b/src/main/java/com/postgraduate/admin/application/dto/res/PaymentInfos.java @@ -0,0 +1,6 @@ +package com.postgraduate.admin.application.dto.res; + +import java.util.List; + +public record PaymentInfos(List paymentInfos) { +} diff --git a/src/main/java/com/postgraduate/admin/application/dto/res/SalaryInfo.java b/src/main/java/com/postgraduate/admin/application/dto/res/SalaryInfo.java index d6d0bf5aa..b189deae7 100644 --- a/src/main/java/com/postgraduate/admin/application/dto/res/SalaryInfo.java +++ b/src/main/java/com/postgraduate/admin/application/dto/res/SalaryInfo.java @@ -3,7 +3,6 @@ import java.time.LocalDateTime; public record SalaryInfo( - Long salaryId, String nickName, String phoneNumber, Integer totalAmount, @@ -12,7 +11,7 @@ public record SalaryInfo( String accountNumber, LocalDateTime salaryDoneDate ) { - public SalaryInfo(Long salaryId, String nickName, String phoneNumber, int totalAmount, LocalDateTime salaryDoneDate) { - this(salaryId, nickName, phoneNumber, totalAmount, null, null, null, salaryDoneDate); + public SalaryInfo(String nickName, String phoneNumber, int totalAmount, LocalDateTime salaryDoneDate) { + this(nickName, phoneNumber, totalAmount, null, null, null, salaryDoneDate); } } diff --git a/src/main/java/com/postgraduate/admin/application/dto/res/SalaryInfoWithOutId.java b/src/main/java/com/postgraduate/admin/application/dto/res/SalaryInfoWithOutId.java deleted file mode 100644 index e4e67b02a..000000000 --- a/src/main/java/com/postgraduate/admin/application/dto/res/SalaryInfoWithOutId.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.postgraduate.admin.application.dto.res; - -import java.time.LocalDateTime; - -public record SalaryInfoWithOutId( - String nickName, - String phoneNumber, - Integer totalAmount, - String accountHolder, - String bank, - String accountNumber, - LocalDateTime salaryDoneDate -) { - public SalaryInfoWithOutId(String nickName, String phoneNumber, int totalAmount, LocalDateTime salaryDoneDate) { - this(nickName, phoneNumber, totalAmount, null, null, null, salaryDoneDate); - } -} diff --git a/src/main/java/com/postgraduate/admin/application/dto/res/SalaryInfos.java b/src/main/java/com/postgraduate/admin/application/dto/res/SalaryInfos.java new file mode 100644 index 000000000..40beaa295 --- /dev/null +++ b/src/main/java/com/postgraduate/admin/application/dto/res/SalaryInfos.java @@ -0,0 +1,6 @@ +package com.postgraduate.admin.application.dto.res; + +import java.util.List; + +public record SalaryInfos(List salaryInfos) { +} diff --git a/src/main/java/com/postgraduate/admin/application/dto/res/SeniorInfos.java b/src/main/java/com/postgraduate/admin/application/dto/res/SeniorInfos.java new file mode 100644 index 000000000..7f80ec057 --- /dev/null +++ b/src/main/java/com/postgraduate/admin/application/dto/res/SeniorInfos.java @@ -0,0 +1,6 @@ +package com.postgraduate.admin.application.dto.res; + +import java.util.List; + +public record SeniorInfos(List seniorInfos) { +} diff --git a/src/main/java/com/postgraduate/admin/application/dto/res/UnsettledSalaryInfos.java b/src/main/java/com/postgraduate/admin/application/dto/res/UnsettledSalaryInfos.java new file mode 100644 index 000000000..60b3701ed --- /dev/null +++ b/src/main/java/com/postgraduate/admin/application/dto/res/UnsettledSalaryInfos.java @@ -0,0 +1,6 @@ +package com.postgraduate.admin.application.dto.res; + +import java.util.List; + +public record UnsettledSalaryInfos(List unSettledSalaryInfos) { +} diff --git a/src/main/java/com/postgraduate/admin/application/dto/res/UserInfo.java b/src/main/java/com/postgraduate/admin/application/dto/res/UserInfo.java index 04fa43a8c..7d841b970 100644 --- a/src/main/java/com/postgraduate/admin/application/dto/res/UserInfo.java +++ b/src/main/java/com/postgraduate/admin/application/dto/res/UserInfo.java @@ -1,7 +1,5 @@ package com.postgraduate.admin.application.dto.res; -import com.postgraduate.domain.member.user.domain.entity.constant.Status; - import java.time.LocalDateTime; public record UserInfo( @@ -9,9 +7,6 @@ public record UserInfo( String nickName, String phoneNumber, LocalDateTime createdAt, - Boolean marketingReceive, - Boolean matchingReceive, - Long wishId, - Status matchingStatus, + Boolean marketinRgeceive, Boolean isSenior ) { } diff --git a/src/main/java/com/postgraduate/admin/application/dto/res/UserMentoringInfo.java b/src/main/java/com/postgraduate/admin/application/dto/res/UserInfoBasic.java similarity index 77% rename from src/main/java/com/postgraduate/admin/application/dto/res/UserMentoringInfo.java rename to src/main/java/com/postgraduate/admin/application/dto/res/UserInfoBasic.java index ec1464daa..118832606 100644 --- a/src/main/java/com/postgraduate/admin/application/dto/res/UserMentoringInfo.java +++ b/src/main/java/com/postgraduate/admin/application/dto/res/UserInfoBasic.java @@ -1,6 +1,6 @@ package com.postgraduate.admin.application.dto.res; -public record UserMentoringInfo( +public record UserInfoBasic( String nickName, String phoneNumber ) { } diff --git a/src/main/java/com/postgraduate/admin/application/dto/res/UserInfos.java b/src/main/java/com/postgraduate/admin/application/dto/res/UserInfos.java new file mode 100644 index 000000000..20d6176b1 --- /dev/null +++ b/src/main/java/com/postgraduate/admin/application/dto/res/UserInfos.java @@ -0,0 +1,6 @@ +package com.postgraduate.admin.application.dto.res; + +import java.util.List; + +public record UserInfos(List userInfos) { +} diff --git a/src/main/java/com/postgraduate/admin/application/dto/res/WaitingWishResponse.java b/src/main/java/com/postgraduate/admin/application/dto/res/WaitingWishResponse.java new file mode 100644 index 000000000..827c91e72 --- /dev/null +++ b/src/main/java/com/postgraduate/admin/application/dto/res/WaitingWishResponse.java @@ -0,0 +1,14 @@ +package com.postgraduate.admin.application.dto.res; + +import java.time.LocalDateTime; + +public record WaitingWishResponse( + Long wishId, + String field, + String postgradu, + String professor, + String lab, + String phoneNumber, + LocalDateTime createAt +) { +} diff --git a/src/main/java/com/postgraduate/admin/application/dto/res/WaitingWishResponses.java b/src/main/java/com/postgraduate/admin/application/dto/res/WaitingWishResponses.java new file mode 100644 index 000000000..4221d1a67 --- /dev/null +++ b/src/main/java/com/postgraduate/admin/application/dto/res/WaitingWishResponses.java @@ -0,0 +1,6 @@ +package com.postgraduate.admin.application.dto.res; + +import java.util.List; + +public record WaitingWishResponses(List wishResponses) { +} diff --git a/src/main/java/com/postgraduate/admin/application/mapper/AdminMapper.java b/src/main/java/com/postgraduate/admin/application/mapper/AdminMapper.java index a6e70ce7a..ecf1ef2ef 100644 --- a/src/main/java/com/postgraduate/admin/application/mapper/AdminMapper.java +++ b/src/main/java/com/postgraduate/admin/application/mapper/AdminMapper.java @@ -1,7 +1,7 @@ package com.postgraduate.admin.application.mapper; import com.postgraduate.admin.application.dto.res.*; -import com.postgraduate.domain.member.user.domain.entity.constant.Status; +import com.postgraduate.domain.member.user.domain.entity.MemberRole; import com.postgraduate.domain.mentoring.domain.entity.Mentoring; import com.postgraduate.domain.payment.domain.entity.Payment; import com.postgraduate.domain.salary.domain.entity.Salary; @@ -10,6 +10,7 @@ import com.postgraduate.domain.member.senior.domain.entity.Senior; import com.postgraduate.domain.member.user.application.utils.UserUtils; import com.postgraduate.domain.member.user.domain.entity.User; +import com.postgraduate.domain.wish.domain.entity.Wish; import jakarta.validation.constraints.NotNull; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -41,20 +42,18 @@ public CertificationDetailsResponse mapToCertificationInfo(Senior senior) { ); } - public UserInfo mapToUserInfo(User user) { + public UserInfo mapToUserInfo(MemberRole memberRole) { + User user = memberRole.getUser(); return new UserInfo( user.getUserId(), user.getNickName(), user.getPhoneNumber(), user.getCreatedAt(), user.getMarketingReceive(), - false, - 1L, // todo : wish 삭제에 따른 변경 필요 - Status.MATCHED, - false + user.isSenior() ); } - + public SeniorInfo mapToSeniorInfo(Salary salary) { Senior senior = salary.getSenior(); @@ -66,7 +65,7 @@ public SeniorInfo mapToSeniorInfo(Salary salary) { senior.getStatus(), salary.getTotalAmount(), user.getMarketingReceive(), - false //todo : wish 삭제에 따른 선배에서 후배 판단 조건 삭제 or 수정 필요 + user.isJunior() ); } @@ -99,16 +98,16 @@ private MentoringInfo getMentoringInfo(Mentoring mentoring, User user) { } - public UserMentoringInfo mapToUserMentoringInfo(User user) { - return new UserMentoringInfo( + public UserInfoBasic mapToUserMentoringInfo(User user) { + return new UserInfoBasic( user.getNickName(), user.getPhoneNumber() ); } - public UserMentoringInfo mapToUserMentoringInfo(Senior senior) { + public UserInfoBasic mapToUserMentoringInfo(Senior senior) { User user = senior.getUser(); - return new UserMentoringInfo( + return new UserInfoBasic( user.getNickName(), user.getPhoneNumber() ); @@ -140,10 +139,10 @@ public PaymentInfo mapToPaymentInfo(Payment payment) { return getPaymentInfo(payment, null, user); } - public SalaryInfoWithOutId mapToSalaryResponse(Senior senior, String accountNumber, Salary salary) { + public SalaryInfo mapToSalaryResponse(Senior senior, String accountNumber, Salary salary) { User user = senior.getUser(); SalaryAccount account = salary.getAccount(); - return new SalaryInfoWithOutId( + return new SalaryInfo( user.getNickName(), user.getPhoneNumber(), salary.getTotalAmount(), @@ -154,19 +153,9 @@ public SalaryInfoWithOutId mapToSalaryResponse(Senior senior, String accountNumb ); } - public SalaryInfoWithOutId mapToSalaryResponse(Senior senior, Salary salary) { - User user = senior.getUser(); - return new SalaryInfoWithOutId ( - user.getNickName(), - user.getPhoneNumber(), - salary.getTotalAmount(), - salary.getSalaryDoneDate() - ); - } - - public SalaryInfoWithOutId mapToSalaryResponse(Salary salary) { + public SalaryInfo mapToSalaryResponse(Salary salary) { User user = userUtils.getArchiveUser(); - return new SalaryInfoWithOutId ( + return new SalaryInfo( user.getNickName(), user.getPhoneNumber(), salary.getTotalAmount(), @@ -239,4 +228,29 @@ private static MentoringWithPaymentResponse getMentoringWithPaymentResponse(Ment SHORT.getCharge() ); } + + public WaitingWishResponse mapToWaitingWish(Wish wish) { + return new WaitingWishResponse( + wish.getWishId(), + wish.getField(), + wish.getPostgradu(), + wish.getProfessor(), + wish.getLab(), + wish.getPhoneNumber(), + wish.getCreatedAt() + ); + } + + public MatchingWishResponse mapToMatchedWish(Wish wish) { + return new MatchingWishResponse( + wish.getWishId(), + wish.getField(), + wish.getPostgradu(), + wish.getProfessor(), + wish.getLab(), + wish.getPhoneNumber(), + wish.getCreatedAt(), + wish.getUpdatedAt() + ); + } } diff --git a/src/main/java/com/postgraduate/admin/application/usecase/AdminMentoringUseCase.java b/src/main/java/com/postgraduate/admin/application/usecase/AdminMentoringUseCase.java index 7f79c9549..b45daece2 100644 --- a/src/main/java/com/postgraduate/admin/application/usecase/AdminMentoringUseCase.java +++ b/src/main/java/com/postgraduate/admin/application/usecase/AdminMentoringUseCase.java @@ -1,7 +1,7 @@ package com.postgraduate.admin.application.usecase; import com.postgraduate.admin.application.dto.res.MentoringManageResponse; -import com.postgraduate.admin.application.dto.res.UserMentoringInfo; +import com.postgraduate.admin.application.dto.res.UserInfoBasic; import com.postgraduate.admin.application.dto.res.MentoringInfo; import com.postgraduate.admin.application.mapper.AdminMapper; import com.postgraduate.admin.domain.service.*; @@ -36,8 +36,8 @@ public MentoringManageResponse seniorMentorings(Long seniorId) { List mentoringInfos = mentorings.stream() .map(adminMapper::mapToMentoringInfoWithSenior) .toList(); - UserMentoringInfo seniorInfo = adminMapper.mapToUserMentoringInfo(senior); - return new MentoringManageResponse(mentoringInfos, seniorInfo); + UserInfoBasic seniorInfo = adminMapper.mapToUserMentoringInfo(senior); + return new MentoringManageResponse(seniorInfo, mentoringInfos); } @Transactional(readOnly = true) @@ -47,8 +47,8 @@ public MentoringManageResponse userMentoringInfos(Long userId) { List mentoringInfos = mentorings.stream() .map(adminMapper::mapToMentoringInfoWithUser) .toList(); - UserMentoringInfo userInfo = adminMapper.mapToUserMentoringInfo(user); - return new MentoringManageResponse(mentoringInfos, userInfo); + UserInfoBasic userInfo = adminMapper.mapToUserMentoringInfo(user); + return new MentoringManageResponse(userInfo, mentoringInfos); } public void refundMentoring(User user, Long mentoringId) { diff --git a/src/main/java/com/postgraduate/admin/application/usecase/AdminPaymentUseCase.java b/src/main/java/com/postgraduate/admin/application/usecase/AdminPaymentUseCase.java index 4c61def70..d00cca2ec 100644 --- a/src/main/java/com/postgraduate/admin/application/usecase/AdminPaymentUseCase.java +++ b/src/main/java/com/postgraduate/admin/application/usecase/AdminPaymentUseCase.java @@ -1,7 +1,7 @@ package com.postgraduate.admin.application.usecase; import com.postgraduate.admin.application.dto.res.MentoringWithPaymentResponse; -import com.postgraduate.admin.application.dto.res.PaymentInfo; +import com.postgraduate.admin.application.dto.res.PaymentInfos; import com.postgraduate.admin.application.dto.res.PaymentWithMentoringQuery; import com.postgraduate.admin.application.mapper.AdminMapper; import com.postgraduate.admin.domain.service.AdminMentoringService; @@ -11,11 +11,10 @@ import com.postgraduate.domain.payment.application.usecase.PaymentManageUseCase; import com.postgraduate.domain.member.user.domain.entity.User; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.List; - import static com.postgraduate.domain.mentoring.domain.entity.constant.MentoringStatus.DONE; @Service @@ -29,15 +28,15 @@ public class AdminPaymentUseCase { private final AdminMapper adminMapper; @Transactional(readOnly = true) - public List paymentInfos() { - List all = adminPaymentService.allPayments(); - return all.stream() + public PaymentInfos paymentInfos(Integer page) { + Page all = adminPaymentService.allPayments(page); + return new PaymentInfos(all.stream() .map(pm -> { if (pm.mentoring().isEmpty()) return adminMapper.mapToPaymentInfo(pm.payment()); return adminMapper.mapToPaymentInfo(pm.payment(), pm.mentoring().get()); }) - .toList(); + .toList()); } @Transactional(readOnly = true) diff --git a/src/main/java/com/postgraduate/admin/application/usecase/AdminSalaryUseCase.java b/src/main/java/com/postgraduate/admin/application/usecase/AdminSalaryUseCase.java index f5fa6da95..113c67ef8 100644 --- a/src/main/java/com/postgraduate/admin/application/usecase/AdminSalaryUseCase.java +++ b/src/main/java/com/postgraduate/admin/application/usecase/AdminSalaryUseCase.java @@ -1,18 +1,17 @@ package com.postgraduate.admin.application.usecase; -import com.postgraduate.admin.application.dto.res.SalaryInfoWithOutId; -import com.postgraduate.admin.application.dto.res.UnSettledSalaryInfo; +import com.postgraduate.admin.application.dto.res.SalaryInfos; +import com.postgraduate.admin.application.dto.res.UnsettledSalaryInfos; import com.postgraduate.admin.application.mapper.AdminMapper; import com.postgraduate.admin.domain.service.AdminSalaryService; import com.postgraduate.domain.salary.domain.entity.Salary; import com.postgraduate.domain.salary.domain.entity.SalaryAccount; import com.postgraduate.global.config.security.util.EncryptorUtils; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.List; - @Service @Transactional @RequiredArgsConstructor @@ -22,9 +21,9 @@ public class AdminSalaryUseCase { private final AdminMapper adminMapper; @Transactional(readOnly = true) - public List salaryInfos() { - List all = adminSalaryService.findAllDoneSalary(); - return all.stream() + public SalaryInfos salaryInfos(Integer page) { + Page all = adminSalaryService.findAllDoneSalary(page); + return new SalaryInfos(all.stream() .map(salary -> { if (salary.getAccount() == null) return adminMapper.mapToSalaryResponse(salary); @@ -32,17 +31,7 @@ public List salaryInfos() { String accountNumber = encryptorUtils.decryptData(account.getAccountNumber()); return adminMapper.mapToSalaryResponse(salary.getSenior(), accountNumber, salary); }) - .toList(); - } - - @Transactional(readOnly = true) - public SalaryInfoWithOutId seniorSalary(Long seniorId) { - Salary salary = adminSalaryService.findBySeniorId(seniorId); - SalaryAccount account = salary.getAccount(); - if (account == null) - return adminMapper.mapToSalaryResponse(salary.getSenior(), salary); - String accountNumber = encryptorUtils.decryptData(account.getAccountNumber()); - return adminMapper.mapToSalaryResponse(salary.getSenior(), accountNumber, salary); + .toList()); } public void salaryDone(Long salaryId) { @@ -50,9 +39,9 @@ public void salaryDone(Long salaryId) { } @Transactional(readOnly = true) - public List unSettledSalaryInfo() { - List salaries = adminSalaryService.findAllByNotDone(); - return salaries.stream() + public UnsettledSalaryInfos unSettledSalaryInfo(Integer page) { + Page salaries = adminSalaryService.findAllByNotDone(page); + return new UnsettledSalaryInfos(salaries.stream() .map(salary -> { SalaryAccount account = salary.getAccount(); if (account == null) @@ -60,6 +49,6 @@ public List unSettledSalaryInfo() { String accountNumber = encryptorUtils.decryptData(account.getAccountNumber()); return adminMapper.mapToUnSettledSalaryResponse(salary, accountNumber); }) - .toList(); + .toList()); } } diff --git a/src/main/java/com/postgraduate/admin/application/usecase/AdminSeniorUseCase.java b/src/main/java/com/postgraduate/admin/application/usecase/AdminSeniorUseCase.java index f1cba4f39..d2c09dcd4 100644 --- a/src/main/java/com/postgraduate/admin/application/usecase/AdminSeniorUseCase.java +++ b/src/main/java/com/postgraduate/admin/application/usecase/AdminSeniorUseCase.java @@ -1,7 +1,7 @@ package com.postgraduate.admin.application.usecase; import com.postgraduate.admin.application.dto.res.CertificationDetailsResponse; -import com.postgraduate.admin.application.dto.res.SeniorInfo; +import com.postgraduate.admin.application.dto.res.SeniorInfos; import com.postgraduate.admin.application.mapper.AdminMapper; import com.postgraduate.admin.domain.service.AdminSeniorService; import com.postgraduate.domain.salary.domain.entity.Salary; @@ -9,10 +9,10 @@ import com.postgraduate.domain.member.senior.exception.SeniorCertificationException; import com.postgraduate.global.bizppurio.application.usecase.BizppurioSeniorMessage; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.List; import static com.postgraduate.domain.member.senior.domain.entity.constant.Status.WAITING; @@ -25,11 +25,11 @@ public class AdminSeniorUseCase { private final AdminMapper adminMapper; @Transactional(readOnly = true) - public List allSenior() { - List salaries = adminSeniorService.allSeniors(); - return salaries.stream() + public SeniorInfos allSenior(Integer page) { + Page salaries = adminSeniorService.allSeniors(page); + return new SeniorInfos(salaries.stream() .map(adminMapper::mapToSeniorInfo) - .toList(); + .toList()); } @Transactional(readOnly = true) diff --git a/src/main/java/com/postgraduate/admin/application/usecase/AdminUserUseCase.java b/src/main/java/com/postgraduate/admin/application/usecase/AdminUserUseCase.java index 7e59ebfd9..666ffc659 100644 --- a/src/main/java/com/postgraduate/admin/application/usecase/AdminUserUseCase.java +++ b/src/main/java/com/postgraduate/admin/application/usecase/AdminUserUseCase.java @@ -1,25 +1,20 @@ package com.postgraduate.admin.application.usecase; import com.postgraduate.admin.application.dto.req.Login; -import com.postgraduate.admin.application.dto.req.SendMessageRequest; -import com.postgraduate.admin.application.dto.res.UserInfo; -import com.postgraduate.admin.application.dto.res.WishResponse; +import com.postgraduate.admin.application.dto.res.UserInfos; import com.postgraduate.admin.application.mapper.AdminMapper; import com.postgraduate.admin.domain.service.AdminUserService; +import com.postgraduate.domain.member.user.domain.entity.MemberRole; import com.postgraduate.domain.member.user.domain.entity.User; -import com.postgraduate.global.bizppurio.application.dto.req.JuniorMatchingSuccessRequest; -import com.postgraduate.global.bizppurio.application.usecase.BizppurioJuniorMessage; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.List; - @Service @Transactional @RequiredArgsConstructor public class AdminUserUseCase { - private final BizppurioJuniorMessage bizppurioJuniorMessage; private final AdminUserService adminUserService; private final AdminMapper adminMapper; @@ -29,25 +24,10 @@ public User login(Login loginForm) { } @Transactional(readOnly = true) - public List userInfos() { - List all = adminUserService.allJunior(); - return all.stream() + public UserInfos userInfos(Integer page) { + Page all = adminUserService.allJunior(page); + return new UserInfos(all.stream() .map(adminMapper::mapToUserInfo) - .toList(); - } - - @Transactional(readOnly = true) - public WishResponse wishInfo(Long userId) { - return null; //todo : wish 변경에 따른 수정 필요 - } - - public void wishDone(Long wishId) { - adminUserService.updateWishDone(wishId); - } - - public void sendMatchingMessage(SendMessageRequest request) { - bizppurioJuniorMessage.matchingSuccess(new JuniorMatchingSuccessRequest( - request.phoneNumber(), request.nickName(), request.postgraduate(), request.major()) - ); + .toList()); } } diff --git a/src/main/java/com/postgraduate/admin/application/usecase/AdminWishUseCase.java b/src/main/java/com/postgraduate/admin/application/usecase/AdminWishUseCase.java new file mode 100644 index 000000000..3755cea93 --- /dev/null +++ b/src/main/java/com/postgraduate/admin/application/usecase/AdminWishUseCase.java @@ -0,0 +1,47 @@ +package com.postgraduate.admin.application.usecase; + +import com.postgraduate.admin.application.dto.res.MatchingWishResponses; +import com.postgraduate.admin.application.dto.res.WaitingWishResponses; +import com.postgraduate.admin.application.mapper.AdminMapper; +import com.postgraduate.admin.domain.service.AdminWishService; +import com.postgraduate.domain.wish.domain.entity.Wish; +import com.postgraduate.global.bizppurio.application.dto.req.JuniorMatchingSuccessRequest; +import com.postgraduate.global.bizppurio.application.usecase.BizppurioJuniorMessage; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@RequiredArgsConstructor +@Service +@Transactional +public class AdminWishUseCase { + private final AdminWishService adminWishService; + private final AdminMapper adminMapper; + private final BizppurioJuniorMessage bizppurioJuniorMessage; + + @Transactional(readOnly = true) + public WaitingWishResponses waitingWish(Integer page) { + return new WaitingWishResponses(adminWishService.findAllWaiting(page) + .stream() + .map(adminMapper::mapToWaitingWish) + .toList()); + } + + @Transactional(readOnly = true) + public MatchingWishResponses matchingWish(Integer page) { + return new MatchingWishResponses(adminWishService.findAllMatching(page) + .stream() + .map(adminMapper::mapToMatchedWish) + .toList()); + } + + public void matchFin(Long wishId) { + Wish wish = adminWishService.matchFin(wishId); + bizppurioJuniorMessage.matchingSuccess(new JuniorMatchingSuccessRequest( + wish.getPhoneNumber(), + "고객님", + wish.getPostgradu(), + wish.getLab()) + ); //todo : 신청서 폼에서 postgradu, lab은 필수로 받아야 함 혹은 알림톡 형식을 변경해야 함 + } +} diff --git a/src/main/java/com/postgraduate/admin/domain/repository/AdminPaymentRepository.java b/src/main/java/com/postgraduate/admin/domain/repository/AdminPaymentRepository.java index 3851dc10d..f6a7cb01e 100644 --- a/src/main/java/com/postgraduate/admin/domain/repository/AdminPaymentRepository.java +++ b/src/main/java/com/postgraduate/admin/domain/repository/AdminPaymentRepository.java @@ -4,8 +4,13 @@ import com.querydsl.core.Tuple; import com.querydsl.jpa.impl.JPAQueryFactory; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Repository; +import org.springframework.util.CollectionUtils; +import java.util.ArrayList; import java.util.List; import static com.postgraduate.domain.member.user.domain.entity.QUser.user; @@ -18,19 +23,36 @@ public class AdminPaymentRepository { private final JPAQueryFactory queryFactory; - public List findAllPayment() { + public Page findAllPayment(Pageable pageable) { List fetch = queryFactory.select(payment, mentoring) .from(payment) .distinct() - .leftJoin(payment.user, user) + .leftJoin(payment.user, user) .fetchJoin() .leftJoin(mentoring) .on(mentoring.payment.eq(payment)) .fetchJoin() + .orderBy(payment.paidAt.desc()) + .offset(pageable.getOffset()) + .limit(pageable.getPageSize()) .fetch(); - return fetch.stream() + List results = fetch.stream() .map(tuple -> new PaymentWithMentoringQuery(tuple.get(payment), ofNullable(tuple.get(mentoring)))) .toList(); + + if (CollectionUtils.isEmpty(results)) { + return new PageImpl<>(new ArrayList<>(), pageable, 0); + } + + Long total = queryFactory.select(payment.count()) + .from(payment) + .distinct() + .leftJoin(payment.user, user) + .leftJoin(mentoring) + .on(mentoring.payment.eq(payment)) + .fetchOne(); + + return new PageImpl<>(results, pageable, total); } } diff --git a/src/main/java/com/postgraduate/admin/domain/repository/AdminSalaryRepository.java b/src/main/java/com/postgraduate/admin/domain/repository/AdminSalaryRepository.java index fd18ad3cb..963a69b8a 100644 --- a/src/main/java/com/postgraduate/admin/domain/repository/AdminSalaryRepository.java +++ b/src/main/java/com/postgraduate/admin/domain/repository/AdminSalaryRepository.java @@ -3,9 +3,14 @@ import com.postgraduate.domain.salary.domain.entity.Salary; import com.querydsl.jpa.impl.JPAQueryFactory; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Repository; +import org.springframework.util.CollectionUtils; import java.time.LocalDate; +import java.util.ArrayList; import java.util.List; import java.util.Optional; @@ -18,8 +23,8 @@ public class AdminSalaryRepository { private final JPAQueryFactory queryFactory; - public List findAllByDone() { - return queryFactory.selectFrom(salary) + public Page findAllByDone(Pageable pageable) { + List salaries = queryFactory.selectFrom(salary) .distinct() .where( salary.status.isTrue(), @@ -30,7 +35,26 @@ public List findAllByDone() { .leftJoin(senior.user, user) .fetchJoin() .orderBy(salary.salaryDoneDate.desc()) + .offset(pageable.getOffset()) + .limit(pageable.getPageSize()) .fetch(); + + if (CollectionUtils.isEmpty(salaries)) { + return new PageImpl<>(new ArrayList<>(), pageable, 0); + } + + Long total = queryFactory.select(salary.count()) + .from(salary) + .distinct() + .where( + salary.status.isTrue(), + salary.totalAmount.gt(0) + ) + .leftJoin(salary.senior, senior) + .leftJoin(senior.user, user) + .fetchOne(); + + return new PageImpl<>(salaries, pageable, total); } public Optional findBySeniorId(Long seniorId, LocalDate salaryDate) { @@ -54,8 +78,8 @@ public Optional findBySalaryId(Long salaryId) { .fetchOne()); } - public List findAllByNotDoneFromLast(LocalDate salaryDate) { - return queryFactory.selectFrom(salary) + public Page findAllByNotDoneFromLast(LocalDate salaryDate, Pageable pageable) { + List salaries = queryFactory.selectFrom(salary) .distinct() .where( salary.status.isFalse(), @@ -68,6 +92,27 @@ public List findAllByNotDoneFromLast(LocalDate salaryDate) { .leftJoin(senior.user, user) .fetchJoin() .orderBy(salary.salaryDate.asc()) + .offset(pageable.getOffset()) + .limit(pageable.getPageSize()) .fetch(); + + if (CollectionUtils.isEmpty(salaries)) { + return new PageImpl<>(new ArrayList<>(), pageable, 0); + } + + Long total = queryFactory.select(salary.count()) + .from(salary) + .distinct() + .where( + salary.status.isFalse(), + salary.salaryDate.lt(salaryDate), + salary.totalAmount.gt(0), + salary.senior.user.isDelete.isFalse() + ) + .leftJoin(salary.senior, senior) + .leftJoin(senior.user, user) + .fetchOne(); + + return new PageImpl<>(salaries, pageable, total); } } diff --git a/src/main/java/com/postgraduate/admin/domain/repository/AdminSeniorRepository.java b/src/main/java/com/postgraduate/admin/domain/repository/AdminSeniorRepository.java index 09a65fe59..dcffe5533 100644 --- a/src/main/java/com/postgraduate/admin/domain/repository/AdminSeniorRepository.java +++ b/src/main/java/com/postgraduate/admin/domain/repository/AdminSeniorRepository.java @@ -4,9 +4,14 @@ import com.postgraduate.domain.member.senior.domain.entity.Senior; import com.querydsl.jpa.impl.JPAQueryFactory; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Repository; +import org.springframework.util.CollectionUtils; import java.time.LocalDate; +import java.util.ArrayList; import java.util.List; import java.util.Optional; @@ -20,8 +25,8 @@ public class AdminSeniorRepository { private final JPAQueryFactory queryFactory; - public List allSeniorInfo(LocalDate salaryDate) { - return queryFactory.selectFrom(salary) + public Page allSeniorInfo(LocalDate salaryDate, Pageable pageable) { + List salaries = queryFactory.selectFrom(salary) .distinct() .join(salary.senior, senior) .fetchJoin() @@ -29,7 +34,23 @@ public List allSeniorInfo(LocalDate salaryDate) { .fetchJoin() .where(salary.senior.user.isDelete.isFalse(), salary.salaryDate.eq(salaryDate)) .orderBy(salary.senior.createdAt.desc()) + .offset(pageable.getOffset()) + .limit(pageable.getPageSize()) .fetch(); + + if (CollectionUtils.isEmpty(salaries)) { + return new PageImpl<>(new ArrayList<>(), pageable, 0); + } + + Long total = queryFactory.select(salary.count()) + .distinct() + .join(salary.senior, senior) + .join(salary.senior.user, user) + .where(salary.senior.user.isDelete.isFalse(), salary.salaryDate.eq(salaryDate)) + .orderBy(salary.senior.createdAt.desc()) + .fetchOne(); + + return new PageImpl<>(salaries, pageable, total); } public Optional findBySeniorId(Long seniorId) { diff --git a/src/main/java/com/postgraduate/admin/domain/repository/AdminUserRepository.java b/src/main/java/com/postgraduate/admin/domain/repository/AdminUserRepository.java index e982c8a46..d53216a78 100644 --- a/src/main/java/com/postgraduate/admin/domain/repository/AdminUserRepository.java +++ b/src/main/java/com/postgraduate/admin/domain/repository/AdminUserRepository.java @@ -1,13 +1,21 @@ package com.postgraduate.admin.domain.repository; +import com.postgraduate.domain.member.user.domain.entity.MemberRole; import com.postgraduate.domain.member.user.domain.entity.User; +import com.postgraduate.domain.member.user.domain.entity.constant.Role; import com.querydsl.jpa.impl.JPAQueryFactory; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Repository; +import org.springframework.util.CollectionUtils; +import java.util.ArrayList; import java.util.List; import java.util.Optional; +import static com.postgraduate.domain.member.user.domain.entity.QMemberRole.memberRole; import static com.postgraduate.domain.member.user.domain.entity.QUser.user; @RequiredArgsConstructor @@ -15,10 +23,29 @@ public class AdminUserRepository { private final JPAQueryFactory queryFactory; - public List findAllJunior() { - return queryFactory.selectFrom(user) -// .where(user.role.eq(Role.USER)) + public Page findAllJunior(Pageable pageable) { + List memberRoles = queryFactory.selectFrom(memberRole) + .distinct() + .where(memberRole.role.eq(Role.USER)) + .join(memberRole.user, user) + .fetchJoin() + .orderBy(user.createdAt.desc()) + .offset(pageable.getOffset()) + .limit(pageable.getPageSize()) .fetch(); + + if (CollectionUtils.isEmpty(memberRoles)) { + return new PageImpl<>(new ArrayList<>(), pageable, 0); + } + + Long total = queryFactory.select(memberRole.count()) + .from(memberRole) + .distinct() + .where(memberRole.role.eq(Role.USER)) + .join(memberRole.user, user) + .fetchOne(); + + return new PageImpl<>(memberRoles, pageable, total); } public Optional findUserByUserId(Long userId) { diff --git a/src/main/java/com/postgraduate/admin/domain/repository/AdminWishRepository.java b/src/main/java/com/postgraduate/admin/domain/repository/AdminWishRepository.java new file mode 100644 index 000000000..43cdef4fa --- /dev/null +++ b/src/main/java/com/postgraduate/admin/domain/repository/AdminWishRepository.java @@ -0,0 +1,69 @@ +package com.postgraduate.admin.domain.repository; + +import com.postgraduate.domain.wish.domain.entity.constant.Status; +import com.postgraduate.domain.wish.domain.entity.Wish; +import com.querydsl.jpa.impl.JPAQueryFactory; +import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Repository; +import org.springframework.util.CollectionUtils; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +import static com.postgraduate.domain.wish.domain.entity.QWish.wish; + +@RequiredArgsConstructor +@Repository +public class AdminWishRepository { + private final JPAQueryFactory queryFactory; + + public Page findAllWaitingWish(Pageable pageable) { + List wishes = queryFactory.selectFrom(wish) + .where(wish.status.eq(Status.WAITING)) + .orderBy(wish.createdAt.desc()) + .offset(pageable.getOffset()) + .limit(pageable.getPageSize()) + .fetch(); + + if (CollectionUtils.isEmpty(wishes)) { + return new PageImpl<>(new ArrayList<>(), pageable, 0); + } + + Long total = queryFactory.select(wish.count()) + .from(wish) + .where(wish.status.eq(Status.WAITING)) + .fetchOne(); + + return new PageImpl<>(wishes, pageable, total); + } + + public Page findAllMatchingWish(Pageable pageable) { + List wishes = queryFactory.selectFrom(wish) + .where(wish.status.eq(Status.MATCHED)) + .orderBy(wish.updatedAt.desc()) + .offset(pageable.getOffset()) + .limit(pageable.getPageSize()) + .fetch(); + + if (CollectionUtils.isEmpty(wishes)) { + return new PageImpl<>(new ArrayList<>(), pageable, 0); + } + + Long total = queryFactory.select(wish.count()) + .from(wish) + .where(wish.status.eq(Status.MATCHED)) + .fetchOne(); + + return new PageImpl<>(wishes, pageable, total); + } + + public Optional findByWishId(Long wishId) { + return Optional.ofNullable(queryFactory.selectFrom(wish) + .where(wish.wishId.eq(wishId)) + .fetchOne()); + } +} diff --git a/src/main/java/com/postgraduate/admin/domain/service/AdminPaymentService.java b/src/main/java/com/postgraduate/admin/domain/service/AdminPaymentService.java index ed8ad9871..d748c73d0 100644 --- a/src/main/java/com/postgraduate/admin/domain/service/AdminPaymentService.java +++ b/src/main/java/com/postgraduate/admin/domain/service/AdminPaymentService.java @@ -3,16 +3,21 @@ import com.postgraduate.admin.application.dto.res.PaymentWithMentoringQuery; import com.postgraduate.admin.domain.repository.AdminPaymentRepository; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; -import java.util.List; - @Service @RequiredArgsConstructor public class AdminPaymentService { private final AdminPaymentRepository adminPaymentRepository; + private static final int PAYMENT_PAGE_SIZE = 20; - public List allPayments() { - return adminPaymentRepository.findAllPayment(); + public Page allPayments(Integer page) { + if (page == null) + page = 1; + Pageable pageable = PageRequest.of(page-1, PAYMENT_PAGE_SIZE); + return adminPaymentRepository.findAllPayment(pageable); } } diff --git a/src/main/java/com/postgraduate/admin/domain/service/AdminSalaryService.java b/src/main/java/com/postgraduate/admin/domain/service/AdminSalaryService.java index 763e4abf5..4745678a7 100644 --- a/src/main/java/com/postgraduate/admin/domain/service/AdminSalaryService.java +++ b/src/main/java/com/postgraduate/admin/domain/service/AdminSalaryService.java @@ -7,18 +7,25 @@ import com.postgraduate.domain.salary.util.SalaryUtil; import com.postgraduate.domain.member.senior.domain.entity.Senior; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import java.time.LocalDate; -import java.util.List; @Service @RequiredArgsConstructor +@Slf4j public class AdminSalaryService { private final AdminSalaryRepository adminSalaryRepository; - - public List findAllDoneSalary() { - return adminSalaryRepository.findAllByDone(); + private static final int SALARY_PAGE_SIZE = 20; + public Page findAllDoneSalary(Integer page) { + if (page == null) + page = 1; + Pageable pageable = PageRequest.of(page-1, SALARY_PAGE_SIZE); + return adminSalaryRepository.findAllByDone(pageable); } public Salary findBySeniorId(Long seniorId) { @@ -33,9 +40,13 @@ public void updateDone(Long salaryId) { salary.updateStatus(true); } - public List findAllByNotDone() { + public Page findAllByNotDone(Integer page) { + if (page == null) + page = 1; + Pageable pageable = PageRequest.of(page-1, SALARY_PAGE_SIZE); LocalDate salaryDate = SalaryUtil.getSalaryDate(); - return adminSalaryRepository.findAllByNotDoneFromLast(salaryDate); + log.info("salaryDate : {} 확인", salaryDate); + return adminSalaryRepository.findAllByNotDoneFromLast(salaryDate, pageable); } public void minusTotalAmount(Mentoring mentoring) { diff --git a/src/main/java/com/postgraduate/admin/domain/service/AdminSeniorService.java b/src/main/java/com/postgraduate/admin/domain/service/AdminSeniorService.java index 5bbc5f459..e9cab5eb8 100644 --- a/src/main/java/com/postgraduate/admin/domain/service/AdminSeniorService.java +++ b/src/main/java/com/postgraduate/admin/domain/service/AdminSeniorService.java @@ -6,10 +6,12 @@ import com.postgraduate.domain.member.senior.domain.entity.Senior; import com.postgraduate.domain.member.senior.exception.NoneSeniorException; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import java.time.LocalDate; -import java.util.List; import static com.postgraduate.domain.member.senior.domain.entity.constant.Status.*; @@ -17,10 +19,14 @@ @RequiredArgsConstructor public class AdminSeniorService { private final AdminSeniorRepository adminSeniorRepository; + private static final int SENIOR_PAGE_SIZE = 20; - public List allSeniors() { + public Page allSeniors(Integer page) { + if (page == null) + page = 1; LocalDate salaryDate = SalaryUtil.getSalaryDate(); - return adminSeniorRepository.allSeniorInfo(salaryDate); + Pageable pageable = PageRequest.of(page-1, SENIOR_PAGE_SIZE); + return adminSeniorRepository.allSeniorInfo(salaryDate, pageable); } public Senior bySeniorId(Long seniorId) { diff --git a/src/main/java/com/postgraduate/admin/domain/service/AdminUserService.java b/src/main/java/com/postgraduate/admin/domain/service/AdminUserService.java index 2076e9adb..03c999002 100644 --- a/src/main/java/com/postgraduate/admin/domain/service/AdminUserService.java +++ b/src/main/java/com/postgraduate/admin/domain/service/AdminUserService.java @@ -1,24 +1,25 @@ package com.postgraduate.admin.domain.service; import com.postgraduate.admin.domain.repository.AdminUserRepository; +import com.postgraduate.domain.member.user.domain.entity.MemberRole; import com.postgraduate.domain.member.user.domain.entity.User; import com.postgraduate.domain.member.user.exception.UserNotFoundException; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; -import java.util.List; - @Service @RequiredArgsConstructor public class AdminUserService { private final AdminUserRepository adminUserRepository; - - public List allJunior() { - return adminUserRepository.findAllJunior(); - } - - public void updateWishDone(Long wishId) { - //todo : wish삭제에 따른 수정 필요 + private static final int JUNIOR_PAGE_SIZE = 20; + public Page allJunior(Integer page) { + if (page == null) + page = 1; + Pageable pageable = PageRequest.of(page-1, JUNIOR_PAGE_SIZE); + return adminUserRepository.findAllJunior(pageable); } public User userByUserId(Long userId) { diff --git a/src/main/java/com/postgraduate/admin/domain/service/AdminWishService.java b/src/main/java/com/postgraduate/admin/domain/service/AdminWishService.java new file mode 100644 index 000000000..c23716a36 --- /dev/null +++ b/src/main/java/com/postgraduate/admin/domain/service/AdminWishService.java @@ -0,0 +1,37 @@ +package com.postgraduate.admin.domain.service; + +import com.postgraduate.admin.domain.repository.AdminWishRepository; +import com.postgraduate.domain.member.user.exception.WishNotFoundException; +import com.postgraduate.domain.wish.domain.entity.Wish; +import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class AdminWishService { + private final AdminWishRepository adminWishRepository; + private static final int WISH_PAGE_SIZE = 20; + public Page findAllWaiting(Integer page) { + if (page == null) + page = 1; + Pageable pageable = PageRequest.of(page-1, WISH_PAGE_SIZE); + return adminWishRepository.findAllWaitingWish(pageable); + } + + public Page findAllMatching(Integer page) { + if (page == null) + page = 1; + Pageable pageable = PageRequest.of(page-1, WISH_PAGE_SIZE); + return adminWishRepository.findAllMatchingWish(pageable); + } + + public Wish matchFin(Long wishId) { + Wish wish = adminWishRepository.findByWishId(wishId) + .orElseThrow(WishNotFoundException::new); + wish.updateDone(); + return wish; + } +} diff --git a/src/main/java/com/postgraduate/admin/presentation/AdminController.java b/src/main/java/com/postgraduate/admin/presentation/AdminController.java new file mode 100644 index 000000000..380c2d2b2 --- /dev/null +++ b/src/main/java/com/postgraduate/admin/presentation/AdminController.java @@ -0,0 +1,178 @@ +package com.postgraduate.admin.presentation; + +import com.postgraduate.admin.application.dto.res.*; +import com.postgraduate.admin.application.usecase.*; +import com.postgraduate.domain.member.user.domain.entity.User; +import com.postgraduate.global.dto.ResponseDto; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.security.core.annotation.AuthenticationPrincipal; +import org.springframework.web.bind.annotation.*; + +@RequiredArgsConstructor +@RestController +@RequestMapping("/admin") +@Tag(name = "ADMIN Controller", description = "관리자의 모든 API는 관리자 권한의 토큰이 필요합니다.") +public class AdminController { + private final AdminSeniorUseCase adminSeniorUseCase; + private final AdminUserUseCase adminUserUseCase; + private final AdminMentoringUseCase adminMentoringUseCase; + private final AdminSalaryUseCase adminSalaryUseCase; + private final AdminPaymentUseCase adminPaymentUseCase; + private final AdminWishUseCase adminWishUseCase; + private final AdminBatchUseCase adminBatchUseCase; + + @GetMapping("/senior") + @Operation(summary = "대학원생에 대한 정보 노출", description = "닉네임, 전화번호, 인증여부, 총 정산금액, 마케팅동의 여부, 후배 여부") + public ResponseEntity> seniorInfo(@RequestParam(required = false) Integer page) { + SeniorInfos seniorInfos = adminSeniorUseCase.allSenior(page); + return ResponseEntity.ok(ResponseDto.create("","", seniorInfos)); + } + + @GetMapping("/senior/certification/{seniorId}") + @Operation(summary = "대학원생 인증 상세정보", description = "이미지, 닉네임, 핸드폰번호, 가입일시, 대학원, 전공, 분야, 연구실, 교수님, 키워드") + public ResponseEntity> certification(@PathVariable Long seniorId) { + CertificationDetailsResponse certification = adminSeniorUseCase.getCertification(seniorId); + return ResponseEntity.ok(ResponseDto.create("", "", certification)); + } + + @PostMapping("/senior/certification/{seniorId}/refuse") + @Operation(summary = "대학원생 인증 반려", description = "인증 반려") + public ResponseEntity> certificationRefuse(@PathVariable Long seniorId) { + adminSeniorUseCase.updateNotApprove(seniorId); + return ResponseEntity.ok(ResponseDto.create("", "")); + } + + @PostMapping("/senior/certification/{seniorId}/approve") + @Operation(summary = "대학원생 인증 승인", description = "인증 승인") + public ResponseEntity> certificationApprove(@PathVariable Long seniorId) { + adminSeniorUseCase.updateApprove(seniorId); + return ResponseEntity.ok(ResponseDto.create("", "")); + } + + @GetMapping("/senior/mentoring/{seniorId}") + @Operation(summary = "대학원생 멘토링 정보", description = "닉네임, 핸드폰번호 (기본정보), 신청받은 멘토링 리스트(멘토링 진행 상태, 후배 닉네임, 후배 핸드폰번호, 신청일시, 멘토링 진행 일시") + public ResponseEntity> seniorMentoringInfo(@PathVariable Long seniorId) { + MentoringManageResponse mentoringInfos = adminMentoringUseCase.seniorMentorings(seniorId); + return ResponseEntity.ok(ResponseDto.create("", "", mentoringInfos)); + } + + // senior 정보 처리 완료 + + @PostMapping("/mentoring/refund/{mentoringId}") + @Operation(summary = "멘토링 환불", description = "멘토링 환불") + public ResponseEntity> refundMentoring(@AuthenticationPrincipal User user, @PathVariable Long mentoringId) { + adminMentoringUseCase.refundMentoring(user, mentoringId); + return ResponseEntity.ok(ResponseDto.create("","")); + } + + // mentoring 전용 + + @GetMapping("/salary") //정산 관리 + @Operation(summary = "정산완료 확인", description = "정산별 닉네임, 핸드폰번호, 총금액, 예금주, 은행, 계좌번호, 완료일") + public ResponseEntity> salaryInfo(@RequestParam(required = false) Integer page) { + SalaryInfos salaryInfos = adminSalaryUseCase.salaryInfos(page); + return ResponseEntity.ok(ResponseDto.create("","",salaryInfos)); + } + + @GetMapping("/salary/unsettled") //미정산건 관리 + @Operation(summary = "정산미완료 확인", description = "정산별 닉네임, 핸드폰번호, 총금액, 예금주, 은행, 계좌번호, 정산예정일") + public ResponseEntity> unsettledSalaryInfo(@RequestParam(required = false) Integer page) { + UnsettledSalaryInfos unSettledSalaryInfos = adminSalaryUseCase.unSettledSalaryInfo(page); + return ResponseEntity.ok(ResponseDto.create("","", unSettledSalaryInfos)); + } + + @PostMapping("/salary/done/{salaryId}") //미정산건 완료 처리 + @Operation(summary = "정산 완료 처리", description = "정산 완료 처리") + public ResponseEntity> salaryDone(@PathVariable Long salaryId) { + adminSalaryUseCase.salaryDone(salaryId); + return ResponseEntity.ok(ResponseDto.create("","")); + } + + // 정산/미정산 관련 + + @GetMapping("/junior") + @Operation(summary = "후배 정보 확인", description = "후배별 닉네임, 핸드폰번호, 가입일, 마케팅 동의 여부, 선배 여부") + public ResponseEntity> userInfo(@RequestParam(required = false) Integer page) { + UserInfos userInfos = adminUserUseCase.userInfos(page); + return ResponseEntity.ok(ResponseDto.create("","", userInfos)); + } + + @GetMapping("/junior/mentoring/{userId}") + @Operation(summary = "후배 멘토링 정보 확인", description = "닉네임, 핸드폰번호 (기본정보), 신청한 멘토링 리스트(멘토링 진행 상태, 선배 닉네임, 선배 핸드폰번호, 신청일시, 멘토링 진행 일시") + public ResponseEntity> userMentoring(@PathVariable Long userId) { + MentoringManageResponse mentoringInfos = adminMentoringUseCase.userMentoringInfos(userId); + return ResponseEntity.ok(ResponseDto.create("","", mentoringInfos)); + } + + // 후배 관련 + + @GetMapping("/payment") + @Operation(summary = "결제 정보 확인", description = "멘토링ID, 후배 닉네임, 핸드폰번호, 결제일, 금액, 결제상태") + public ResponseEntity> paymentInfo(@RequestParam(required = false) Integer page) { + PaymentInfos paymentInfos = adminPaymentUseCase.paymentInfos(page); + return ResponseEntity.ok(ResponseDto.create("","",paymentInfos)); + } + + @GetMapping("/payment/mentoring/{paymentId}") + @Operation(summary = "결제 멘토링 확인", description = "결제ID, 후배닉네임, 후배핸드폰, 선배닉네임, 선배핸드폰, 멘토링날짜, 몇분짜리, 금액, 수수료") + public ResponseEntity> paymentWithMentoring(@PathVariable Long paymentId) { + MentoringWithPaymentResponse mentoringWithPaymentResponse = adminPaymentUseCase.paymentMentoringInfo(paymentId); + return ResponseEntity.ok(ResponseDto.create("","",mentoringWithPaymentResponse)); + } + + @PostMapping("/payment/mentoring/refund/{paymentId}") + @Operation(summary = "결제 환불", description = "결제 기록을 기반으로 환불") + public ResponseEntity> refundPayment(@AuthenticationPrincipal User user, @PathVariable Long paymentId) { + adminPaymentUseCase.refundPayment(user, paymentId); + return ResponseEntity.ok(ResponseDto.create("","")); + } + + // 결제 관련 + + @GetMapping("/wish/waiting") + @Operation(summary = "대기중 신청서 확인", description = "분야, 대학원, 교수, 랩실, 핸드폰번호, 신청일") + public ResponseEntity> waitingWish(@RequestParam(required = false) Integer page) { + WaitingWishResponses waitingWishResponses = adminWishUseCase.waitingWish(page); + return ResponseEntity.ok(ResponseDto.create("","", waitingWishResponses)); + } + + @GetMapping("/wish/matching") + @Operation(summary = "완료된 신청서 확인", description = "분야, 대학원, 교수, 랩실, 핸드폰번호, 신청일, 완료일") + public ResponseEntity> matching(@RequestParam(required = false) Integer page) { + MatchingWishResponses matchingWishResponses = adminWishUseCase.matchingWish(page); + return ResponseEntity.ok(ResponseDto.create("","", matchingWishResponses)); + } + + @PostMapping("/wish/done/{wishId}") + @Operation(summary = "신청서 완료 확인 및 알림톡 전송", description = "신청서 완료 상태 변경 및 후배 알림톡 전송") + public ResponseEntity> wishDone(@PathVariable Long wishId) { + adminWishUseCase.matchFin(wishId); + return ResponseEntity.ok(ResponseDto.create("","")); + } + + // 신청서 관련 처리 + + @PostMapping("/batch/salary") + @Operation(summary = "개발팀 전용 API", description = "정산 관련 배치 재시도") + public ResponseEntity> startSalaryBatch() { + adminBatchUseCase.startSalaryBatch(); + return ResponseEntity.ok(ResponseDto.create("","")); + } + + @PostMapping("/batch/mentoring/done") + @Operation(summary = "개발팀 전용 API", description = "멘토링 완료 관련 배치 재시도") + public ResponseEntity> startMentoringDone() { + adminBatchUseCase.startMentoringDoneBatch(); + return ResponseEntity.ok(ResponseDto.create("","")); + } + + @PostMapping("/batch/mentoring/cancel") + @Operation(summary = "개발팀 전용 API", description = "멘토링 취소 관련 배치 재시도") + public ResponseEntity> startMentoringCancel() { + adminBatchUseCase.startMentoringCancelBatch(); + return ResponseEntity.ok(ResponseDto.create("","")); + } +} diff --git a/src/main/java/com/postgraduate/admin/presentation/AdminWithThymeLeafController.java b/src/main/java/com/postgraduate/admin/presentation/AdminWithThymeLeafController.java deleted file mode 100644 index 13546b1b3..000000000 --- a/src/main/java/com/postgraduate/admin/presentation/AdminWithThymeLeafController.java +++ /dev/null @@ -1,190 +0,0 @@ -package com.postgraduate.admin.presentation; - -import com.postgraduate.admin.application.dto.req.Login; -import com.postgraduate.admin.application.dto.req.SendMessageRequest; -import com.postgraduate.admin.application.dto.res.*; -import com.postgraduate.admin.application.usecase.*; -import com.postgraduate.global.auth.login.application.dto.res.JwtTokenResponse; -import com.postgraduate.global.auth.login.application.usecase.jwt.JwtUseCase; -import com.postgraduate.domain.member.user.domain.entity.User; -import lombok.RequiredArgsConstructor; -import org.springframework.security.core.annotation.AuthenticationPrincipal; -import org.springframework.stereotype.Controller; -import org.springframework.ui.Model; -import org.springframework.web.bind.annotation.*; - -import java.util.List; - -@RequiredArgsConstructor -@Controller -@RequestMapping("/adminServer") -public class AdminWithThymeLeafController { - private final AdminSeniorUseCase adminSeniorUseCase; - private final AdminUserUseCase adminUserUseCase; - private final AdminMentoringUseCase adminMentoringUseCase; - private final AdminSalaryUseCase adminSalaryUseCase; - private final AdminPaymentUseCase adminPaymentUseCase; - private final AdminBatchUseCase adminBatchUseCase; - private final JwtUseCase jwtUseCase; - - @GetMapping("/loginForm") - public String loginForm(Model model, Login loginForm) { - model.addAttribute("loginForm", loginForm); - return "adminLogin"; - } - - @PostMapping("/login") - public String login(@ModelAttribute Login loginForm, Model model) { - User user = adminUserUseCase.login(loginForm); - JwtTokenResponse jwtTokenResponse = jwtUseCase.signIn(user); - model.addAttribute("tokenResponse", jwtTokenResponse); - return "adminMain"; - } - - @GetMapping("/seniorInfo") - public String seniorInfo(Model model) { - List seniorInfos = adminSeniorUseCase.allSenior(); - model.addAttribute("seniorInfos", seniorInfos); - return "adminSenior"; - } - - @GetMapping("/certification/{seniorId}") - public String certification(@PathVariable Long seniorId, Model model) { - CertificationDetailsResponse certification = adminSeniorUseCase.getCertification(seniorId); - model.addAttribute("certificationInfo", certification); - return "seniorCertification"; - } - - @PostMapping("/certification/{seniorId}/refuse") - public String certificationRefuse(@PathVariable Long seniorId) { - adminSeniorUseCase.updateNotApprove(seniorId); - return "adminEmpty"; - } - - @PostMapping("/certification/{seniorId}/approve") - public String certificationApprove(@PathVariable Long seniorId) { - adminSeniorUseCase.updateApprove(seniorId); - return "adminEmpty"; - } - - @GetMapping("/mentoring/{seniorId}") - public String seniorMentoringInfo(@PathVariable Long seniorId, Model model) { - MentoringManageResponse mentoringInfos = adminMentoringUseCase.seniorMentorings(seniorId); - model.addAttribute("mentoringInfos", mentoringInfos); - return "seniorMentoring"; - } - - @PostMapping("/mentoring/refund/{mentoringId}") - public String refundMentoring(@AuthenticationPrincipal User user, @PathVariable Long mentoringId) { - adminMentoringUseCase.refundMentoring(user, mentoringId); - return "adminEmpty"; - } - - @GetMapping("/salaryInfo") - public String salaryInfo(Model model) { - List salaryInfos = adminSalaryUseCase.salaryInfos(); - model.addAttribute("salaryInfo", salaryInfos); - return "adminSalary"; - } - - @GetMapping("/salary/{seniorId}") - public String seniorSalaryInfo(@PathVariable Long seniorId, Model model) { - SalaryInfoWithOutId salaryInfo = adminSalaryUseCase.seniorSalary(seniorId); - model.addAttribute("salaryInfo", salaryInfo); - return "seniorSalary"; - } - - @PostMapping("/salary/done/{salaryId}") - public String salaryDone(@PathVariable Long salaryId) { - adminSalaryUseCase.salaryDone(salaryId); - return "adminEmpty"; - } - - @GetMapping("/salary/unsettled") - public String unsettledSalaryInfo(Model model) { - List unSettledSalaryInfos = adminSalaryUseCase.unSettledSalaryInfo(); - model.addAttribute("salaryInfos", unSettledSalaryInfos); - return "unSettledSalary"; - } - - @PostMapping("/wish/done/{wishId}") - public String wishDone(@PathVariable Long wishId) { - adminUserUseCase.wishDone(wishId); - return "adminEmpty"; - } - - @GetMapping("/user/matching/{userId}") - public String userMatching(@PathVariable Long userId, Model model) { - WishResponse wishResponse = adminUserUseCase.wishInfo(userId); - model.addAttribute("wishInfo", wishResponse); - return "userWish"; - } - - @GetMapping("/user/mentoring/{userId}") - public String userMentoring(@PathVariable Long userId, Model model) { - MentoringManageResponse mentoringInfos = adminMentoringUseCase.userMentoringInfos(userId); - model.addAttribute("mentoringInfos", mentoringInfos); - return "userMentoring"; - } - - @GetMapping("/userInfo") - public String userInfo(Model model) { - List userInfos = adminUserUseCase.userInfos(); - model.addAttribute("userInfos", userInfos); - return "adminUser"; - } - - @GetMapping("/paymentInfo") - public String paymentInfo(Model model) { - List paymentInfos = adminPaymentUseCase.paymentInfos(); - model.addAttribute("paymentInfos", paymentInfos); - return "adminPayment"; - } - - @GetMapping("/payment/mentoring/{paymentId}") - public String paymentWithMentoring(@PathVariable Long paymentId, Model model) { - MentoringWithPaymentResponse mentoringWithPaymentResponse = adminPaymentUseCase.paymentMentoringInfo(paymentId); - model.addAttribute("mentoringInfo", mentoringWithPaymentResponse); - return "paymentMentoring"; - } - - @PostMapping("/payment/refund/{paymentId}") - public String refundPayment(@AuthenticationPrincipal User user, @PathVariable Long paymentId) { - adminPaymentUseCase.refundPayment(user, paymentId); - return "adminEmpty"; - } - - @GetMapping("/message") - public String messageManage() { - return "adminMessage"; - } - - @PostMapping("/message") - public String sendMessage(@RequestBody SendMessageRequest messageRequest) { - adminUserUseCase.sendMatchingMessage(messageRequest); - return "adminEmpty"; - } - - @GetMapping("/batch") - public String batchManage() { - return "adminBatch"; - } - - @PostMapping("/batch/salary") - public String startSalaryBatch() { - adminBatchUseCase.startSalaryBatch(); - return "adminEmpty"; - } - - @PostMapping("/batch/mentoring/done") - public String startMentoringDone() { - adminBatchUseCase.startMentoringDoneBatch(); - return "adminEmpty"; - } - - @PostMapping("/batch/mentoring/cancel") - public String startMentoringCancel() { - adminBatchUseCase.startMentoringCancelBatch(); - return "adminEmpty"; - } -} diff --git a/src/main/java/com/postgraduate/domain/member/senior/domain/entity/Senior.java b/src/main/java/com/postgraduate/domain/member/senior/domain/entity/Senior.java index 563bc1019..7181a3512 100644 --- a/src/main/java/com/postgraduate/domain/member/senior/domain/entity/Senior.java +++ b/src/main/java/com/postgraduate/domain/member/senior/domain/entity/Senior.java @@ -69,7 +69,7 @@ public class Senior { @OneToMany(mappedBy = "senior") private List availables = new ArrayList<>(); - @OneToOne(mappedBy = "senior") + @OneToOne(mappedBy = "senior") //todo : OneToOne 을 ManyToOne, OneToMany 로 변경하기 (양방향을 사용해야 하는 환경이라면?) private Account account; public void updateAccount(SeniorMyPageUserAccountRequest myPageUserAccountRequest, String accountNumber) { diff --git a/src/main/java/com/postgraduate/domain/member/user/domain/entity/constant/Status.java b/src/main/java/com/postgraduate/domain/member/user/domain/entity/constant/Status.java deleted file mode 100644 index 95bf6938c..000000000 --- a/src/main/java/com/postgraduate/domain/member/user/domain/entity/constant/Status.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.postgraduate.domain.member.user.domain.entity.constant; - -public enum Status { - WAITING, MATCHED, REJECTED -} diff --git a/src/main/java/com/postgraduate/domain/wish/domain/entity/Wish.java b/src/main/java/com/postgraduate/domain/wish/domain/entity/Wish.java index 2a4d438ee..4a60bbd74 100644 --- a/src/main/java/com/postgraduate/domain/wish/domain/entity/Wish.java +++ b/src/main/java/com/postgraduate/domain/wish/domain/entity/Wish.java @@ -1,6 +1,6 @@ package com.postgraduate.domain.wish.domain.entity; -import com.postgraduate.domain.member.user.domain.entity.constant.Status; +import com.postgraduate.domain.wish.domain.entity.constant.Status; import jakarta.persistence.*; import lombok.AllArgsConstructor; import lombok.Builder; @@ -48,7 +48,7 @@ public class Wish { @UpdateTimestamp private LocalDateTime updatedAt; - protected void updateDone() { + public void updateDone() { this.status = Status.MATCHED; } } diff --git a/src/main/java/com/postgraduate/domain/wish/domain/entity/constant/Status.java b/src/main/java/com/postgraduate/domain/wish/domain/entity/constant/Status.java new file mode 100644 index 000000000..3e853af32 --- /dev/null +++ b/src/main/java/com/postgraduate/domain/wish/domain/entity/constant/Status.java @@ -0,0 +1,5 @@ +package com.postgraduate.domain.wish.domain.entity.constant; + +public enum Status { + WAITING, MATCHED, REJECTED +} diff --git a/src/main/java/com/postgraduate/global/auth/login/application/usecase/jwt/JwtUseCase.java b/src/main/java/com/postgraduate/global/auth/login/application/usecase/jwt/JwtUseCase.java index b5b2dc250..087dc55cb 100644 --- a/src/main/java/com/postgraduate/global/auth/login/application/usecase/jwt/JwtUseCase.java +++ b/src/main/java/com/postgraduate/global/auth/login/application/usecase/jwt/JwtUseCase.java @@ -7,7 +7,9 @@ import com.postgraduate.domain.member.user.exception.UserNotFoundException; import com.postgraduate.global.auth.login.application.dto.res.JwtTokenResponse; import com.postgraduate.global.config.security.jwt.util.JwtUtils; +import jakarta.servlet.http.Cookie; import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; @@ -22,60 +24,63 @@ @Transactional(readOnly = true) public class JwtUseCase { private final JwtUtils jwtUtils; + private static final String COOKIE = "role"; @Value("${jwt.refreshExpiration}") private int refreshExpiration; @Value("${jwt.accessExpiration}") private int accessExpiration; - public JwtTokenResponse signIn(User user) { - if (user.isSenior()) - return seniorToken(user); + public JwtTokenResponse signIn(User user, HttpServletResponse response) { if (user.isAdmin()) - return adminToken(user); - return userToken(user); + return adminToken(user, response); + if (user.isSenior()) + return seniorToken(user, response); + return userToken(user, response); } - public void logout(User user) { + public void logout(User user, HttpServletResponse response) { + deleteRoleCookie(response); jwtUtils.makeExpired(user.getUserId()); } - public JwtTokenResponse regenerateToken(User user, HttpServletRequest request) { + public JwtTokenResponse regenerateToken(User user, HttpServletRequest request, HttpServletResponse response) { String role = jwtUtils.checkRedis(user.getUserId(), request); if (role.equals(SENIOR.toString())) - return seniorToken(user); + return seniorToken(user, response); if (role.equals(ADMIN.toString())) - return adminToken(user); - return userToken(user); + return adminToken(user, response); + return userToken(user, response); } - public JwtTokenResponse changeUser(User user) { + public JwtTokenResponse changeUser(User user, HttpServletResponse response) { if (!user.isJunior()) throw new UserNotFoundException(); - return userToken(user); + return userToken(user, response); } - public JwtTokenResponse changeSenior(User user) { + public JwtTokenResponse changeSenior(User user, HttpServletResponse response) { if (!user.isSenior()) throw new NoneSeniorException(); - return seniorToken(user); + return seniorToken(user, response); } - private JwtTokenResponse userToken(User user) { - return generateToken(user, USER); + private JwtTokenResponse userToken(User user, HttpServletResponse response) { + return generateToken(user, USER, response); } - private JwtTokenResponse seniorToken(User user) { - return generateToken(user, SENIOR); + private JwtTokenResponse seniorToken(User user, HttpServletResponse response) { + return generateToken(user, SENIOR, response); } - private JwtTokenResponse adminToken(User user) { - return generateToken(user, ADMIN); + private JwtTokenResponse adminToken(User user, HttpServletResponse response) { + return generateToken(user, ADMIN, response); } - private JwtTokenResponse generateToken(User user, Role role) { + private JwtTokenResponse generateToken(User user, Role role, HttpServletResponse response) { checkDelete(user); String accessToken = jwtUtils.generateAccessToken(user.getUserId(), role); String refreshToken = jwtUtils.generateRefreshToken(user.getUserId(), role); + addRoleCookie(response, role); return new JwtTokenResponse(accessToken, accessExpiration, refreshToken, refreshExpiration, role, user.isTutorial()); } @@ -83,4 +88,20 @@ private void checkDelete(User user) { if (user.isDelete()) throw new DeletedUserException(); } + + private void addRoleCookie(HttpServletResponse response, Role role) { + Cookie roleCookie = new Cookie(COOKIE, role.toString()); + roleCookie.setHttpOnly(true); + roleCookie.setPath("/"); + roleCookie.setMaxAge(accessExpiration); + response.addCookie(roleCookie); + } + + private void deleteRoleCookie(HttpServletResponse response) { + Cookie roleCookie = new Cookie(COOKIE, null); + roleCookie.setHttpOnly(true); + roleCookie.setPath("/"); + roleCookie.setMaxAge(0); + response.addCookie(roleCookie); + } } \ No newline at end of file diff --git a/src/main/java/com/postgraduate/global/auth/login/presentation/AuthController.java b/src/main/java/com/postgraduate/global/auth/login/presentation/AuthController.java index a9a733212..411b5a6a4 100644 --- a/src/main/java/com/postgraduate/global/auth/login/presentation/AuthController.java +++ b/src/main/java/com/postgraduate/global/auth/login/presentation/AuthController.java @@ -18,6 +18,7 @@ import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; @@ -40,96 +41,97 @@ public class AuthController { @PostMapping("/login/token/{provider}") @Operation(summary = "소셜 로그인", description = "회원인 경우 JWT를, 회원이 아닌 경우 socialId를 반환합니다(회원가입은 진행하지 않습니다). 탈퇴 회원인 경우 isDelete = true 가 응답됩니다") - public ResponseEntity> authLoginWithToken(@RequestBody @Valid TokenRequest request, @PathVariable Provider provider) { + public ResponseEntity> authLoginWithToken(@RequestBody @Valid TokenRequest request, @PathVariable Provider provider, HttpServletResponse response) { SignInUseCase signInUseCase = selectOauth.selectSignIn(provider); AuthUserResponse authUser = signInUseCase.getUserWithToken(request); if (authUser.user() == null) return ResponseEntity.ok(create(AuthResponseCode.AUTH_NONE.getCode(), AuthResponseMessage.NOT_REGISTERED_USER.getMessage(), authUser)); - JwtTokenResponse jwtToken = jwtUseCase.signIn(authUser.user()); + JwtTokenResponse jwtToken = jwtUseCase.signIn(authUser.user(), response); return ResponseEntity.ok(create(AuthResponseCode.AUTH_ALREADY.getCode(), AuthResponseMessage.SUCCESS_AUTH.getMessage(), jwtToken)); } @PostMapping("/login/{provider}") @Operation(summary = "소셜 로그인", description = "회원인 경우 JWT를, 회원이 아닌 경우 socialId를 반환합니다(회원가입은 진행하지 않습니다). 탈퇴 회원인 경우 isDelete = true 가 응답됩니다") - public ResponseEntity> authLogin(@RequestBody @Valid CodeRequest request, @PathVariable Provider provider) { + public ResponseEntity> authLogin(@RequestBody @Valid CodeRequest request, @PathVariable Provider provider, HttpServletResponse response) { SignInUseCase signInUseCase = selectOauth.selectSignIn(provider); AuthUserResponse authUser = signInUseCase.getUser(request); if (authUser.user() == null) return ResponseEntity.ok(create(AuthResponseCode.AUTH_NONE.getCode(), AuthResponseMessage.NOT_REGISTERED_USER.getMessage(), authUser)); - JwtTokenResponse jwtToken = jwtUseCase.signIn(authUser.user()); + JwtTokenResponse jwtToken = jwtUseCase.signIn(authUser.user(), response); return ResponseEntity.ok(create(AuthResponseCode.AUTH_ALREADY.getCode(), AuthResponseMessage.SUCCESS_AUTH.getMessage(), jwtToken)); } @PostMapping("/dev/login/{provider}") @Operation(summary = "개발용 소셜 로그인", description = "회원인 경우 JWT를, 회원이 아닌 경우 socialId를 반환합니다(회원가입은 진행하지 않습니다). 탈퇴 회원인 경우 isDelete = true 가 응답됩니다") - public ResponseEntity> authDevLogin(@RequestBody @Valid CodeRequest request, @PathVariable Provider provider) { + public ResponseEntity> authDevLogin(@RequestBody @Valid CodeRequest request, @PathVariable Provider provider, HttpServletResponse response) { SignInUseCase signInUseCase = selectOauth.selectSignIn(provider); AuthUserResponse authUser = signInUseCase.getDevUser(request); if (authUser.user() == null) return ResponseEntity.ok(create(AuthResponseCode.AUTH_NONE.getCode(), AuthResponseMessage.NOT_REGISTERED_USER.getMessage(), authUser)); - JwtTokenResponse jwtToken = jwtUseCase.signIn(authUser.user()); + JwtTokenResponse jwtToken = jwtUseCase.signIn(authUser.user(), response); return ResponseEntity.ok(create(AuthResponseCode.AUTH_ALREADY.getCode(), AuthResponseMessage.SUCCESS_AUTH.getMessage(), jwtToken)); } @PatchMapping("/rejoin/{provider}") @Operation(summary = "탈퇴 사용자 재가입", description = "복구를 희망하는 경우 rejoin = true 희망하지 않는 경우 false 를 넣어주세요. 복구시 기존 로그인과 동일한 응답") - public ResponseEntity> reJoin(@PathVariable Provider provider, @RequestBody RejoinRequest request) { + public ResponseEntity> reJoin(@PathVariable Provider provider, @RequestBody RejoinRequest request, HttpServletResponse response) { User user = userManageUseCase.updateRejoin(provider, request); - JwtTokenResponse jwtToken = jwtUseCase.signIn(user); + JwtTokenResponse jwtToken = jwtUseCase.signIn(user, response); return ResponseEntity.ok(create(AuthResponseCode.AUTH_ALREADY.getCode(), AuthResponseMessage.SUCCESS_AUTH.getMessage(), jwtToken)); } @PostMapping("/logout") @Operation(summary = "로그아웃", description = "토큰 같이 보내주세요") - public ResponseEntity> logout(@AuthenticationPrincipal User user) { - jwtUseCase.logout(user); + public ResponseEntity> logout(@AuthenticationPrincipal User user, HttpServletResponse response) { + jwtUseCase.logout(user, response); return ResponseEntity.ok(create(AuthResponseCode.AUTH_DELETE.getCode(), AuthResponseMessage.LOGOUT_USER.getMessage())); } @PostMapping("/user/signup") @Operation(summary = "대학생 회원가입", description = "로그인 API에서 반환한 socialId, 닉네임, 번호, 마케팅 수신여부, 희망 학과, 희망 분야, 매칭 희망 여부") - public ResponseEntity> signUpUser(@RequestBody @Valid SignUpRequest request) { + public ResponseEntity> signUpUser(@RequestBody @Valid SignUpRequest request, HttpServletResponse response) { User user = signUpUseCase.userSignUp(request); - JwtTokenResponse jwtToken = jwtUseCase.signIn(user); + JwtTokenResponse jwtToken = jwtUseCase.signIn(user, response); return ResponseEntity.ok(create(AuthResponseCode.AUTH_CREATE.getCode(), AuthResponseMessage.SUCCESS_AUTH.getMessage(), jwtToken)); } @PostMapping("/user/token") @Operation(summary = "후배로 변경 | 토큰 필요", description = "후배로 변경 가능한 경우 후배 토큰 발급") - public ResponseEntity> changeUserToken(@AuthenticationPrincipal User user) { + public ResponseEntity> changeUserToken(@AuthenticationPrincipal User user, HttpServletResponse response) { signUpUseCase.changeUser(user); - JwtTokenResponse jwtToken = jwtUseCase.changeUser(user); + JwtTokenResponse jwtToken = jwtUseCase.changeUser(user, response); return ResponseEntity.ok(create(AuthResponseCode.AUTH_CREATE.getCode(), AuthResponseMessage.SUCCESS_AUTH.getMessage(), jwtToken)); } @PostMapping("/senior/signup") @Operation(summary = "대학원생 가입 - 필수 과정만", description = "대학원생 회원가입 - 필수 과정만") - public ResponseEntity> singUpSenior(@RequestBody @Valid SeniorSignUpRequest request) { + public ResponseEntity> singUpSenior(@RequestBody @Valid SeniorSignUpRequest request, HttpServletResponse response) { User user = signUpUseCase.seniorSignUp(request); - JwtTokenResponse jwtToken = jwtUseCase.signIn(user); + JwtTokenResponse jwtToken = jwtUseCase.signIn(user, response); return ResponseEntity.ok(create(SENIOR_CREATE.getCode(), CREATE_SENIOR.getMessage(), jwtToken)); } @PostMapping("/senior/change") @Operation(summary = "선배로 추가 가입 | 토큰 필요", description = "대학생 대학원생으로 변경 추가 가입") public ResponseEntity> changeSenior(@AuthenticationPrincipal User user, - @RequestBody @Valid SeniorChangeRequest changeRequest) { + @RequestBody @Valid SeniorChangeRequest changeRequest, + HttpServletResponse response) { User changeUser = signUpUseCase.changeSenior(user, changeRequest); - JwtTokenResponse jwtToken = jwtUseCase.changeSenior(changeUser); + JwtTokenResponse jwtToken = jwtUseCase.changeSenior(changeUser, response); return ResponseEntity.ok(create(SENIOR_CREATE.getCode(), CREATE_SENIOR.getMessage(), jwtToken)); } @PostMapping("/senior/token") @Operation(summary = "선배로 변경 | 토큰 필요", description = "선배로 변경 가능한 경우 선배 토큰 발급") - public ResponseEntity> changeSeniorToken(@AuthenticationPrincipal User user) { - JwtTokenResponse jwtToken = jwtUseCase.changeSenior(user); + public ResponseEntity> changeSeniorToken(@AuthenticationPrincipal User user, HttpServletResponse response) { + JwtTokenResponse jwtToken = jwtUseCase.changeSenior(user, response); return ResponseEntity.ok(create(AuthResponseCode.AUTH_CREATE.getCode(), AuthResponseMessage.SUCCESS_AUTH.getMessage(), jwtToken)); } @PostMapping("/refresh") @Operation(summary = "토큰 재발급 | 토큰 필요", description = "refreshToken 으로 토큰 재발급") - public ResponseEntity> refresh(@AuthenticationPrincipal User user, HttpServletRequest request) { - JwtTokenResponse jwtToken = jwtUseCase.regenerateToken(user, request); + public ResponseEntity> refresh(@AuthenticationPrincipal User user, HttpServletRequest request, HttpServletResponse response) { + JwtTokenResponse jwtToken = jwtUseCase.regenerateToken(user, request, response); return ResponseEntity.ok(create(AuthResponseCode.AUTH_UPDATE.getCode(), AuthResponseMessage.SUCCESS_REGENERATE_TOKEN.getMessage(), jwtToken)); } diff --git a/src/test/java/com/postgraduate/domain/auth/application/usecase/oauth/SignUpUseTypeTest.java b/src/test/java/com/postgraduate/domain/auth/application/usecase/oauth/SignUpUseTypeTest.java index b5b2f24b8..24b7a86e8 100644 --- a/src/test/java/com/postgraduate/domain/auth/application/usecase/oauth/SignUpUseTypeTest.java +++ b/src/test/java/com/postgraduate/domain/auth/application/usecase/oauth/SignUpUseTypeTest.java @@ -21,7 +21,7 @@ //import com.postgraduate.domain.member.user.domain.service.UserUpdateService; //import com.postgraduate.domain.member.user.exception.PhoneNumberException; //import com.postgraduate.domain.wish.domain.entity.Wish; -//import com.postgraduate.domain.member.user.domain.entity.constant.Status; +//import com.postgraduate.domain.wish.domain.entity.constant.Status; //import com.postgraduate.global.bizppurio.application.usecase.BizppurioJuniorMessage; //import com.postgraduate.global.bizppurio.application.usecase.BizppurioSeniorMessage; //import com.postgraduate.global.slack.SlackSignUpMessage; diff --git a/src/test/java/com/postgraduate/domain/auth/presentation/AuthControllerTest.java b/src/test/java/com/postgraduate/domain/auth/presentation/AuthControllerTest.java index 6f95c4f87..c07895ef8 100644 --- a/src/test/java/com/postgraduate/domain/auth/presentation/AuthControllerTest.java +++ b/src/test/java/com/postgraduate/domain/auth/presentation/AuthControllerTest.java @@ -43,7 +43,7 @@ void authLoginByUser() throws Exception { .willReturn(kakaoSignInUseCase); given(kakaoSignInUseCase.getUser(codeRequest)) .willReturn(response); - given(jwtUseCase.signIn(any())) + given(jwtUseCase.signIn(any(), any())) .willReturn(tokenResponse); mvc.perform(post("/auth/login/KAKAO") @@ -96,7 +96,7 @@ void signUpUser() throws Exception { given(signUpUseCase.userSignUp(signUpRequest)) .willReturn(user); - given(jwtUseCase.signIn(user)) + given(jwtUseCase.signIn(any(), any())) .willReturn(tokenResponse); mvc.perform(post("/auth/user/signup") @@ -120,7 +120,7 @@ void signUpUser() throws Exception { void changeUserToken() throws Exception { JwtTokenResponse tokenResponse = new JwtTokenResponse("access", 10, "refresh", 10, USER, TRUE); - given(jwtUseCase.changeUser(any())) + given(jwtUseCase.changeUser(any(), any())) .willReturn(tokenResponse); mvc.perform(post("/auth/user/token") @@ -149,7 +149,7 @@ void singUpSenior() throws Exception { given(signUpUseCase.seniorSignUp(any())) .willReturn(user); - given(jwtUseCase.signIn(user)) + given(jwtUseCase.signIn(any(), any())) .willReturn(tokenResponse); mvc.perform(post("/auth/senior/signup") @@ -179,7 +179,7 @@ void changeSenior() throws Exception { given(signUpUseCase.changeSenior(any(), any())) .willReturn(user); - given(jwtUseCase.changeSenior(user)) + given(jwtUseCase.changeSenior(any(), any())) .willReturn(tokenResponse); mvc.perform(post("/auth/senior/change") @@ -203,7 +203,7 @@ void changeSenior() throws Exception { void changeSeniorToken() throws Exception { JwtTokenResponse tokenResponse = new JwtTokenResponse("access", 10, "refresh", 10, USER, TRUE); - given(jwtUseCase.changeSenior(any())) + given(jwtUseCase.changeSenior(any(), any())) .willReturn(tokenResponse); mvc.perform(post("/auth/senior/token") @@ -225,7 +225,7 @@ void changeSeniorToken() throws Exception { void refresh() throws Exception { JwtTokenResponse tokenResponse = new JwtTokenResponse("access", 10, "refresh", 10, USER, TRUE); - given(jwtUseCase.regenerateToken(any(), any())) + given(jwtUseCase.regenerateToken(any(), any(), any())) .willReturn(tokenResponse); mvc.perform(post("/auth/refresh") @@ -246,7 +246,7 @@ void refresh() throws Exception { @DisplayName("로그아웃한다.") void logout() throws Exception { willDoNothing().given(jwtUseCase) - .logout(any()); + .logout(any(), any()); mvc.perform(post("/auth/logout") .header(HttpHeaders.AUTHORIZATION, BEARER) diff --git a/src/test/java/com/postgraduate/support/Resource.java b/src/test/java/com/postgraduate/support/Resource.java index 4464e2cff..ab6a15e1a 100644 --- a/src/test/java/com/postgraduate/support/Resource.java +++ b/src/test/java/com/postgraduate/support/Resource.java @@ -22,13 +22,11 @@ import static com.postgraduate.domain.mentoring.domain.entity.constant.MentoringStatus.WAITING; import static com.postgraduate.domain.payment.domain.entity.constant.Status.DONE; import static com.postgraduate.domain.salary.util.SalaryUtil.getSalaryDate; -import static com.postgraduate.domain.member.user.domain.entity.constant.Role.SENIOR; -import static com.postgraduate.domain.member.user.domain.entity.constant.Role.USER; import static java.time.LocalDateTime.now; public class Resource { private User user = new User(-1L, -1L, "mail", "후배", "011", "profile", 0, new ArrayList<>(), true, now(), now(), false, false); - private Wish wish = new Wish(-1L, "major", "field", "professor", "lab", "123", com.postgraduate.domain.member.user.domain.entity.constant.Status.WAITING, now(), now()); + private Wish wish = new Wish(-1L, "major", "field", "professor", "lab", "123", com.postgraduate.domain.wish.domain.entity.constant.Status.WAITING, now(), now()); private User otherUser = new User(-3L, -3L, "mail", "다른후배", "011", "profile", 0, new ArrayList<>(), true, now(), now(), false, false); private User userOfSenior = new User(-2L, -2L, "mail", "선배", "012", "profile", 0, new ArrayList<>(), true, now(), now(), false, false); private Info info = new Info("major", "서울대학교", "교수님", "키워드1,키워드2", "랩실", "인공지능", false, false, "인공지능,키워드1,키워드2", "chatLink", 30);