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 c967fe41..89ad352f 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 @@ -2,17 +2,25 @@ import com.postgraduate.domain.account.domain.entity.Account; import com.postgraduate.domain.senior.application.dto.req.SeniorAccountRequest; +import com.postgraduate.domain.senior.application.dto.req.SeniorMyPageUserAccountRequest; import com.postgraduate.domain.senior.domain.entity.Senior; public class AccountMapper { - public static Account mapToAccount(Senior senior, SeniorAccountRequest accountRequest, String accountNumber, String rrn) { + public static Account mapToAccount(Senior senior, SeniorAccountRequest accountRequest, String accountNumber) { return Account.builder() .senior(senior) .accountNumber(accountNumber) .accountHolder(accountRequest.getAccountHolder()) .bank(accountRequest.getBank()) - .name(accountRequest.getName()) - .rrn(rrn) + .build(); + } + + public static Account mapToAccount(Senior senior, SeniorMyPageUserAccountRequest myPageUserAccountRequest, String accountNumber) { + return Account.builder() + .senior(senior) + .accountNumber(accountNumber) + .accountHolder(myPageUserAccountRequest.accountHolder()) + .bank(myPageUserAccountRequest.bank()) .build(); } } diff --git a/src/main/java/com/postgraduate/domain/account/domain/entity/Account.java b/src/main/java/com/postgraduate/domain/account/domain/entity/Account.java index 10b7a9e1..2ed3a1ac 100644 --- a/src/main/java/com/postgraduate/domain/account/domain/entity/Account.java +++ b/src/main/java/com/postgraduate/domain/account/domain/entity/Account.java @@ -28,12 +28,6 @@ public class Account { @Column(nullable = false) private String accountHolder; - @Column(nullable = false) - private String name; - - @Column(nullable = false) - private String rrn; - @OneToOne private Senior senior; diff --git a/src/main/java/com/postgraduate/domain/auth/presentation/AuthController.java b/src/main/java/com/postgraduate/domain/auth/presentation/AuthController.java index 62a4799e..8ce34053 100644 --- a/src/main/java/com/postgraduate/domain/auth/presentation/AuthController.java +++ b/src/main/java/com/postgraduate/domain/auth/presentation/AuthController.java @@ -59,7 +59,7 @@ public ResponseDto singUpSenior(@RequestBody SeniorSignUpReque } @PostMapping("/senior/change") - @Operation(summary = "선배로 변경", description = "대학생 대학원생으로 변경") + @Operation(summary = "선배로 업데이트", description = "대학생 대학원생으로 변경") public ResponseDto changeSenior(@AuthenticationPrincipal User user, @RequestBody SeniorChangeRequest changeRequest) { User changeUser = signUpUseCase.changeSenior(user, changeRequest); diff --git a/src/main/java/com/postgraduate/domain/senior/application/dto/res/AllSeniorSearchResponse.java b/src/main/java/com/postgraduate/domain/senior/application/dto/res/AllSeniorSearchResponse.java new file mode 100644 index 00000000..1123c303 --- /dev/null +++ b/src/main/java/com/postgraduate/domain/senior/application/dto/res/AllSeniorSearchResponse.java @@ -0,0 +1,7 @@ +package com.postgraduate.domain.senior.application.dto.res; + +import jakarta.validation.constraints.NotNull; + +import java.util.List; + +public record AllSeniorSearchResponse(@NotNull List seniorSearchResponses) {} diff --git a/src/main/java/com/postgraduate/domain/senior/application/dto/res/SeniorSearchResponse.java b/src/main/java/com/postgraduate/domain/senior/application/dto/res/SeniorSearchResponse.java new file mode 100644 index 00000000..0a7976aa --- /dev/null +++ b/src/main/java/com/postgraduate/domain/senior/application/dto/res/SeniorSearchResponse.java @@ -0,0 +1,20 @@ +package com.postgraduate.domain.senior.application.dto.res; + +import jakarta.validation.constraints.NotNull; + +public record SeniorSearchResponse( + @NotNull + String profile, + @NotNull + String nickName, + @NotNull + String postgradu, + @NotNull + String major, + @NotNull + String lab, + @NotNull + String oneLiner, + @NotNull + String[] keyword +) {} 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 3f5103f8..5a75a896 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 @@ -4,11 +4,8 @@ import com.postgraduate.domain.auth.application.dto.req.SeniorChangeRequest; import com.postgraduate.domain.auth.application.dto.req.SeniorSignUpRequest; import com.postgraduate.domain.senior.application.dto.req.SeniorMyPageProfileRequest; -import com.postgraduate.domain.senior.application.dto.res.SeniorDetailResponse; +import com.postgraduate.domain.senior.application.dto.res.*; import com.postgraduate.domain.senior.application.dto.req.SeniorProfileRequest; -import com.postgraduate.domain.senior.application.dto.res.SeniorMyPageProfileResponse; -import com.postgraduate.domain.senior.application.dto.res.SeniorMyPageResponse; -import com.postgraduate.domain.senior.application.dto.res.SeniorMyPageUserAccountResponse; import com.postgraduate.domain.senior.domain.entity.Info; import com.postgraduate.domain.senior.domain.entity.Profile; import com.postgraduate.domain.senior.domain.entity.Senior; @@ -33,6 +30,8 @@ public static Info mapToInfo(SeniorSignUpRequest request) { .lab(request.getLab()) .keyword(request.getKeyword()) .field(request.getField()) + .totalInfo(request.getMajor() + request.getLab() + request.getField() + + request.getProfessor() + request.getPostgradu()) .build(); } @@ -72,6 +71,8 @@ public static Info mapToInfo(SeniorChangeRequest request) { .lab(request.getLab()) .keyword(request.getKeyword()) .field(request.getField()) + .totalInfo(request.getMajor() + request.getLab() + request.getField() + + request.getProfessor() + request.getPostgradu()) .build(); } @@ -112,6 +113,14 @@ public static SeniorMyPageUserAccountResponse mapToMyPageUserAccount(Senior seni .build(); } + public static SeniorMyPageUserAccountResponse mapToMyPageUserAccount(Senior senior) { + User user = senior.getUser(); + return SeniorMyPageUserAccountResponse.builder() + .profile(user.getProfile()) + .nickName(user.getNickName()) + .build(); + } + public static SeniorDetailResponse mapToSeniorDetail(Senior senior) { String[] keyword = senior.getInfo().getKeyword().split(","); return SeniorDetailResponse.builder() @@ -128,4 +137,15 @@ public static SeniorDetailResponse mapToSeniorDetail(Senior senior) { .time(senior.getProfile().getTime()) .build(); } + + public static SeniorSearchResponse mapToSeniorSearch(Senior senior) { + User user = senior.getUser(); + Info info = senior.getInfo(); + Profile profile = senior.getProfile(); + String[] keyword = info.getKeyword().split(","); + + return new SeniorSearchResponse(user.getProfile(), user.getNickName(), + info.getPostgradu(), info.getMajor(), info.getLab(), + profile.getOneLiner(), keyword); + } } diff --git a/src/main/java/com/postgraduate/domain/senior/application/usecase/SeniorInfoUseCase.java b/src/main/java/com/postgraduate/domain/senior/application/usecase/SeniorInfoUseCase.java index a2679410..f9ffec5a 100644 --- a/src/main/java/com/postgraduate/domain/senior/application/usecase/SeniorInfoUseCase.java +++ b/src/main/java/com/postgraduate/domain/senior/application/usecase/SeniorInfoUseCase.java @@ -1,14 +1,21 @@ package com.postgraduate.domain.senior.application.usecase; +import com.postgraduate.domain.senior.application.dto.res.AllSeniorSearchResponse; import com.postgraduate.domain.senior.application.dto.res.SeniorDetailResponse; +import com.postgraduate.domain.senior.application.dto.res.SeniorSearchResponse; import com.postgraduate.domain.senior.domain.entity.Senior; import com.postgraduate.domain.senior.domain.service.SeniorGetService; import com.postgraduate.domain.senior.domain.service.SeniorUpdateService; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.ArrayList; +import java.util.List; + import static com.postgraduate.domain.senior.application.mapper.SeniorMapper.mapToSeniorDetail; +import static com.postgraduate.domain.senior.application.mapper.SeniorMapper.mapToSeniorSearch; @Service @Transactional @@ -22,4 +29,13 @@ public SeniorDetailResponse getSeniorDetail(Long seniorId) { seniorUpdateService.updateHit(senior); return mapToSeniorDetail(senior); } + + public AllSeniorSearchResponse getSearchSenior(String search, Integer page, String sort) { + Page allSeniors = seniorGetService.bySearch(search, page, sort); + List selectSeniors = new ArrayList<>(); + for (Senior senior : allSeniors.getContent()) { + selectSeniors.add(mapToSeniorSearch(senior)); + } + return new AllSeniorSearchResponse(selectSeniors); + } } 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 4a03bd10..93e45923 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 @@ -5,12 +5,10 @@ import com.postgraduate.domain.account.domain.service.AccountSaveService; import com.postgraduate.domain.account.domain.service.AccountUpdateService; import com.postgraduate.domain.senior.application.dto.req.*; -import com.postgraduate.domain.senior.application.mapper.SeniorMapper; import com.postgraduate.domain.senior.domain.entity.Profile; import com.postgraduate.domain.senior.domain.entity.Senior; import com.postgraduate.domain.senior.domain.service.SeniorGetService; import com.postgraduate.domain.senior.domain.service.SeniorUpdateService; -import com.postgraduate.domain.senior.exception.NoneAccountException; import com.postgraduate.domain.user.domain.entity.User; import com.postgraduate.domain.user.domain.service.UserUpdateService; import com.postgraduate.global.config.security.util.EncryptorUtils; @@ -18,6 +16,8 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.Optional; + import static com.postgraduate.domain.account.application.mapper.AccountMapper.mapToAccount; import static com.postgraduate.domain.senior.application.mapper.SeniorMapper.mapToProfile; @@ -47,8 +47,7 @@ public void signUpProfile(User user, SeniorProfileRequest profileRequest) { public void saveAccount(User user, SeniorAccountRequest accountRequest) { Senior senior = seniorGetService.byUser(user); String accountNumber = encryptorUtils.encryptData(accountRequest.getAccountNumber()); - String rrn = encryptorUtils.encryptData(accountRequest.getRrn()); - accountSaveService.saveAccount(mapToAccount(senior, accountRequest, accountNumber, rrn)); + accountSaveService.saveAccount(mapToAccount(senior, accountRequest, accountNumber)); } public void updateSeniorMyPageProfile(User user, SeniorMyPageProfileRequest myPageProfileRequest) { @@ -59,9 +58,21 @@ public void updateSeniorMyPageProfile(User user, SeniorMyPageProfileRequest myPa public void updateSeniorMyPageUserAccount(User user, SeniorMyPageUserAccountRequest myPageUserAccountRequest) { Senior senior = seniorGetService.byUser(user); - Account account = accountGetService.bySenior(senior).orElseThrow(NoneAccountException::new); + Optional optionalAccount = accountGetService.bySenior(senior); + if (optionalAccount.isEmpty()) { + updateSeniorMyPageUserAccountNoneAccount(senior, user, myPageUserAccountRequest); + return; + } + Account account = optionalAccount.get(); String accountNumber = encryptorUtils.encryptData(myPageUserAccountRequest.accountNumber()); userUpdateService.updateSeniorUserAccount(user.getUserId(), myPageUserAccountRequest); accountUpdateService.updateAccount(account, myPageUserAccountRequest, accountNumber); } + + private void updateSeniorMyPageUserAccountNoneAccount(Senior senior, User user, SeniorMyPageUserAccountRequest myPageUserAccountRequest) { + String accountNumber = encryptorUtils.encryptData(myPageUserAccountRequest.accountNumber()); + Account account = mapToAccount(senior, myPageUserAccountRequest, accountNumber); + userUpdateService.updateSeniorUserAccount(user.getUserId(), myPageUserAccountRequest); + accountSaveService.saveAccount(account); + } } 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 9606206e..59422be6 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 @@ -44,7 +44,10 @@ public SeniorMyPageProfileResponse getSeniorMyPageProfile(User user) { public SeniorMyPageUserAccountResponse getSeniorMyPageUserAccount(User user) { Senior senior = seniorGetService.byUser(user); - Account account = accountGetService.bySenior(senior).orElseThrow(NoneAccountException::new); + Optional optionalAccount = accountGetService.bySenior(senior); + if (optionalAccount.isEmpty()) + return mapToMyPageUserAccount(senior); + Account account = optionalAccount.get(); String accountNumber = encryptorUtils.decryptData(account.getAccountNumber()); return mapToMyPageUserAccount(senior, account, accountNumber); } diff --git a/src/main/java/com/postgraduate/domain/senior/domain/entity/Info.java b/src/main/java/com/postgraduate/domain/senior/domain/entity/Info.java index 314f3e28..3e7509d3 100644 --- a/src/main/java/com/postgraduate/domain/senior/domain/entity/Info.java +++ b/src/main/java/com/postgraduate/domain/senior/domain/entity/Info.java @@ -32,9 +32,17 @@ public class Info { @Column(nullable = false) private String field; + @Column(nullable = false) + private String totalInfo; // 모든 Info정보 String으로 가지는 컬럼 - 검색시 사용 + public void updateMyPage(SeniorMyPageProfileRequest request) { this.keyword = request.getKeyword(); this.lab = request.getLab(); this.field = request.getField(); + combineTotalInfo(); + } + + private void combineTotalInfo() { + this.totalInfo = major + lab + field + professor + postgradu + keyword; } } diff --git a/src/main/java/com/postgraduate/domain/senior/domain/repository/SeniorDslRepository.java b/src/main/java/com/postgraduate/domain/senior/domain/repository/SeniorDslRepository.java new file mode 100644 index 00000000..53cb030c --- /dev/null +++ b/src/main/java/com/postgraduate/domain/senior/domain/repository/SeniorDslRepository.java @@ -0,0 +1,9 @@ +package com.postgraduate.domain.senior.domain.repository; + +import com.postgraduate.domain.senior.domain.entity.Senior; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; + +public interface SeniorDslRepository { + Page findAllSenior(String search, String sort, Pageable pageable); +} diff --git a/src/main/java/com/postgraduate/domain/senior/domain/repository/SeniorDslRepositoryImpl.java b/src/main/java/com/postgraduate/domain/senior/domain/repository/SeniorDslRepositoryImpl.java new file mode 100644 index 00000000..40c4558e --- /dev/null +++ b/src/main/java/com/postgraduate/domain/senior/domain/repository/SeniorDslRepositoryImpl.java @@ -0,0 +1,51 @@ +package com.postgraduate.domain.senior.domain.repository; + +import com.postgraduate.domain.senior.domain.entity.Senior; +import com.querydsl.core.types.Order; +import com.querydsl.core.types.OrderSpecifier; +import com.querydsl.jpa.impl.JPAQuery; +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 java.util.List; + +import static com.postgraduate.domain.senior.domain.entity.QSenior.senior; +import static com.postgraduate.domain.senior.domain.entity.constant.Status.APPROVE; + +@RequiredArgsConstructor +@Repository +public class SeniorDslRepositoryImpl implements SeniorDslRepository{ + private final JPAQueryFactory queryFactory; + + @Override + public Page findAllSenior(String search, String sort, Pageable pageable) { + JPAQuery query = queryFactory.selectFrom(senior) + .where( + senior.info.totalInfo.like("%" + search + "%"), + senior.status.eq(APPROVE) + ) + .orderBy(orderSpecifier(sort)); + + List seniors = query.offset(pageable.getOffset()) + .limit(pageable.getPageSize()) + .fetch(); + + long total = query.fetchCount(); + + return new PageImpl<>(seniors, pageable, total); + } + + private OrderSpecifier orderSpecifier(String sort) { + if (sort == null) + return new OrderSpecifier<>(Order.DESC, senior.hit); + return switch (sort) { + case "low" -> new OrderSpecifier<>(Order.ASC, senior.hit); + default -> new OrderSpecifier<>(Order.DESC, senior.hit); + }; + } + +} diff --git a/src/main/java/com/postgraduate/domain/senior/domain/repository/SeniorRepository.java b/src/main/java/com/postgraduate/domain/senior/domain/repository/SeniorRepository.java index 5a4e9802..4e430514 100644 --- a/src/main/java/com/postgraduate/domain/senior/domain/repository/SeniorRepository.java +++ b/src/main/java/com/postgraduate/domain/senior/domain/repository/SeniorRepository.java @@ -8,7 +8,7 @@ import java.util.List; import java.util.Optional; -public interface SeniorRepository extends JpaRepository { +public interface SeniorRepository extends JpaRepository, SeniorDslRepository { Optional findByUser(User user); Optional findBySeniorIdAndProfileNotNullAndStatus(Long seniorId, Status status); List findAllByStatus(Status status); diff --git a/src/main/java/com/postgraduate/domain/senior/domain/service/SeniorGetService.java b/src/main/java/com/postgraduate/domain/senior/domain/service/SeniorGetService.java index cee820b5..7c8adfa0 100644 --- a/src/main/java/com/postgraduate/domain/senior/domain/service/SeniorGetService.java +++ b/src/main/java/com/postgraduate/domain/senior/domain/service/SeniorGetService.java @@ -6,6 +6,9 @@ import com.postgraduate.domain.senior.exception.NoneSeniorException; import com.postgraduate.domain.user.domain.entity.User; 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; @@ -16,6 +19,7 @@ @RequiredArgsConstructor public class SeniorGetService { private final SeniorRepository seniorRepository; + private static final int SENIOR_PAGE_SIZE = 10; public Senior byUser(User user) { return seniorRepository.findByUser(user).orElseThrow(NoneSeniorException::new); @@ -32,4 +36,11 @@ public Senior bySeniorIdWithCertification(Long seniorId) { public List byStatus(Status status) { return seniorRepository.findAllByStatus(status); } + + public Page bySearch(String search, Integer page, String sort) { + if (page == null) + page = 1; + Pageable pageable = PageRequest.of(page-1, SENIOR_PAGE_SIZE); + return seniorRepository.findAllSenior(search, sort, pageable); + } } 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 aa730c49..4cfd4fe2 100644 --- a/src/main/java/com/postgraduate/domain/senior/presentation/SeniorController.java +++ b/src/main/java/com/postgraduate/domain/senior/presentation/SeniorController.java @@ -1,10 +1,7 @@ package com.postgraduate.domain.senior.presentation; import com.postgraduate.domain.senior.application.dto.req.*; -import com.postgraduate.domain.senior.application.dto.res.SeniorDetailResponse; -import com.postgraduate.domain.senior.application.dto.res.SeniorMyPageProfileResponse; -import com.postgraduate.domain.senior.application.dto.res.SeniorMyPageResponse; -import com.postgraduate.domain.senior.application.dto.res.SeniorMyPageUserAccountResponse; +import com.postgraduate.domain.senior.application.dto.res.*; import com.postgraduate.domain.senior.application.usecase.SeniorInfoUseCase; import com.postgraduate.domain.senior.application.usecase.SeniorManageUseCase; import com.postgraduate.domain.senior.application.usecase.SeniorMyPageUseCase; @@ -96,4 +93,13 @@ public ResponseDto getSeniorDetails(@PathVariable Long sen SeniorDetailResponse seniorDetail = seniorInfoUseCase.getSeniorDetail(seniorId); return ResponseDto.create(SENIOR_FIND.getCode(), GET_SENIOR_INFO.getMessage(), seniorDetail); } + + @GetMapping("/search") + @Operation(summary = "대학원생 검색어 검색") + public ResponseDto getSearchSenior(@RequestParam String find, + @RequestParam(required = false) String sort, + @RequestParam(required = false) Integer page) { + AllSeniorSearchResponse searchSenior = seniorInfoUseCase.getSearchSenior(find, page, sort); + return ResponseDto.create(SENIOR_FIND.getCode(), GET_SENIOR_LIST_INFO.getMessage(), searchSenior); + } }