diff --git a/build.gradle b/build.gradle index 2d3d2031..c00adad1 100644 --- a/build.gradle +++ b/build.gradle @@ -63,6 +63,10 @@ dependencies { annotationProcessor "jakarta.annotation:jakarta.annotation-api" annotationProcessor "jakarta.persistence:jakarta.persistence-api" + // prometheus metric + implementation 'org.springframework.boot:spring-boot-starter-actuator' + runtimeOnly 'io.micrometer:micrometer-registry-prometheus' + // aws s3 implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE' diff --git a/src/main/java/com/postgraduate/domain/mentoring/application/dto/ExpectedSeniorMentoringInfo.java b/src/main/java/com/postgraduate/domain/mentoring/application/dto/ExpectedSeniorMentoringInfo.java index 9895cafc..060d838f 100644 --- a/src/main/java/com/postgraduate/domain/mentoring/application/dto/ExpectedSeniorMentoringInfo.java +++ b/src/main/java/com/postgraduate/domain/mentoring/application/dto/ExpectedSeniorMentoringInfo.java @@ -1,4 +1,4 @@ package com.postgraduate.domain.mentoring.application.dto; -public record ExpectedSeniorMentoringInfo(Long mentoringId, String profile, String nickName, int term, String date) { +public record ExpectedSeniorMentoringInfo(Long mentoringId, String profile, String nickName, int term, String date, long dDay) { } diff --git a/src/main/java/com/postgraduate/domain/mentoring/application/dto/WaitingSeniorMentoringInfo.java b/src/main/java/com/postgraduate/domain/mentoring/application/dto/WaitingSeniorMentoringInfo.java index 3ce4d4a2..309046fc 100644 --- a/src/main/java/com/postgraduate/domain/mentoring/application/dto/WaitingSeniorMentoringInfo.java +++ b/src/main/java/com/postgraduate/domain/mentoring/application/dto/WaitingSeniorMentoringInfo.java @@ -1,4 +1,4 @@ package com.postgraduate.domain.mentoring.application.dto; -public record WaitingSeniorMentoringInfo(Long mentoringId, String profile, String nickName, int term, long remainTime) { +public record WaitingSeniorMentoringInfo(Long mentoringId, String profile, String nickName, int term, String remainTime) { } diff --git a/src/main/java/com/postgraduate/domain/mentoring/application/mapper/MentoringMapper.java b/src/main/java/com/postgraduate/domain/mentoring/application/mapper/MentoringMapper.java index a8cff85e..2666605f 100644 --- a/src/main/java/com/postgraduate/domain/mentoring/application/mapper/MentoringMapper.java +++ b/src/main/java/com/postgraduate/domain/mentoring/application/mapper/MentoringMapper.java @@ -86,7 +86,7 @@ public static Mentoring mapToMentoring(User user, Senior senior, MentoringApplyR .build(); } - public static WaitingSeniorMentoringInfo mapToSeniorWaitingInfo(Mentoring mentoring, long remainTime) { + public static WaitingSeniorMentoringInfo mapToSeniorWaitingInfo(Mentoring mentoring, String remainTime) { User user = mentoring.getUser(); return new WaitingSeniorMentoringInfo( mentoring.getMentoringId(), @@ -95,12 +95,13 @@ public static WaitingSeniorMentoringInfo mapToSeniorWaitingInfo(Mentoring mentor remainTime); } - public static ExpectedSeniorMentoringInfo mapToSeniorExpectedInfo(Mentoring mentoring) { + public static ExpectedSeniorMentoringInfo mapToSeniorExpectedInfo(Mentoring mentoring, long dDay) { User user = mentoring.getUser(); return new ExpectedSeniorMentoringInfo(mentoring.getMentoringId(), user.getProfile(), user.getNickName(), mentoring.getTerm(), - mentoring.getDate()); + mentoring.getDate(), + dDay); } public static DoneSeniorMentoringInfo mapToSeniorDoneInfo(Mentoring mentoring, Payment payment) { diff --git a/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringSeniorInfoUseCase.java b/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringSeniorInfoUseCase.java index 72b30c7c..510a217a 100644 --- a/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringSeniorInfoUseCase.java +++ b/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringSeniorInfoUseCase.java @@ -10,6 +10,7 @@ import com.postgraduate.domain.mentoring.domain.entity.constant.Status; import com.postgraduate.domain.mentoring.domain.service.MentoringGetService; import com.postgraduate.domain.mentoring.exception.MentoringDetailNotFoundException; +import com.postgraduate.domain.mentoring.util.DateUtils; import com.postgraduate.domain.senior.domain.entity.Senior; import com.postgraduate.domain.senior.domain.service.SeniorGetService; import com.postgraduate.domain.user.domain.entity.User; @@ -19,11 +20,12 @@ import java.time.Duration; import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; import java.util.List; -import static com.postgraduate.domain.mentoring.application.mapper.MentoringMapper.mapToSeniorMentoringDetail; -import static com.postgraduate.domain.mentoring.application.mapper.MentoringMapper.mapToSeniorWaitingInfo; +import static com.postgraduate.domain.mentoring.application.mapper.MentoringMapper.*; import static com.postgraduate.domain.mentoring.domain.entity.constant.Status.*; +import static java.time.Duration.between; @Service @Transactional @@ -51,7 +53,7 @@ public SeniorMentoringResponse getSeniorWaiting(User user) { .toLocalDate() .atStartOfDay(); LocalDateTime now = LocalDateTime.now(); - long remain = Duration.between(now, expiredAt).toMinutes(); + String remain = DateUtils.remainTime(between(now, expiredAt)); return mapToSeniorWaitingInfo(mentoring, remain); }) .toList(); @@ -61,7 +63,12 @@ public SeniorMentoringResponse getSeniorWaiting(User user) { public SeniorMentoringResponse getSeniorExpected(User user) { List mentorings = getMentorings(user, EXPECTED); List expectedMentoringInfos = mentorings.stream() - .map(MentoringMapper::mapToSeniorExpectedInfo) + .map(mentoring -> { + LocalDateTime date = DateUtils.stringToLocalDateTime(mentoring.getDate()); + LocalDateTime now = LocalDateTime.now(); + long dDay = between(now, date).toDays(); + return mapToSeniorExpectedInfo(mentoring, dDay); + }) .toList(); return new SeniorMentoringResponse(expectedMentoringInfos); } diff --git a/src/main/java/com/postgraduate/domain/mentoring/util/DateUtils.java b/src/main/java/com/postgraduate/domain/mentoring/util/DateUtils.java new file mode 100644 index 00000000..29e2b2db --- /dev/null +++ b/src/main/java/com/postgraduate/domain/mentoring/util/DateUtils.java @@ -0,0 +1,21 @@ +package com.postgraduate.domain.mentoring.util; + +import java.time.Duration; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; + +import static java.time.format.DateTimeFormatter.ofPattern; + +public class DateUtils { + public static LocalDateTime stringToLocalDateTime(String date) { + DateTimeFormatter formatter = ofPattern("yyyy-MM-dd-HH-mm"); + return LocalDateTime.parse(date, formatter); + } + + public static String remainTime(Duration duration) { + long minutes = duration.toMinutes(); + long hours = minutes / 60; + minutes -= 60*hours; + return (hours + "-" + minutes); + } +} diff --git a/src/main/java/com/postgraduate/domain/senior/application/dto/res/AllSeniorIdResponse.java b/src/main/java/com/postgraduate/domain/senior/application/dto/res/AllSeniorIdResponse.java new file mode 100644 index 00000000..e623ffcc --- /dev/null +++ b/src/main/java/com/postgraduate/domain/senior/application/dto/res/AllSeniorIdResponse.java @@ -0,0 +1,6 @@ +package com.postgraduate.domain.senior.application.dto.res; + +import java.util.List; + +public record AllSeniorIdResponse(List seniorIds) { +} diff --git a/src/main/java/com/postgraduate/domain/senior/application/dto/res/SeniorMyPageResponse.java b/src/main/java/com/postgraduate/domain/senior/application/dto/res/SeniorMyPageResponse.java index fe8c3da8..1f20e6b4 100644 --- a/src/main/java/com/postgraduate/domain/senior/application/dto/res/SeniorMyPageResponse.java +++ b/src/main/java/com/postgraduate/domain/senior/application/dto/res/SeniorMyPageResponse.java @@ -2,7 +2,7 @@ import com.postgraduate.domain.senior.domain.entity.constant.Status; -public record SeniorMyPageResponse(Long seniorId, Long socialId, String nickName, String profile, +public record SeniorMyPageResponse(Long socialId, Long seniorId, String nickName, String profile, Status certificationRegister, Boolean profileRegister) { } diff --git a/src/main/java/com/postgraduate/domain/senior/application/dto/res/SeniorPossibleResponse.java b/src/main/java/com/postgraduate/domain/senior/application/dto/res/SeniorPossibleResponse.java index 7b137429..b6acda73 100644 --- a/src/main/java/com/postgraduate/domain/senior/application/dto/res/SeniorPossibleResponse.java +++ b/src/main/java/com/postgraduate/domain/senior/application/dto/res/SeniorPossibleResponse.java @@ -1,3 +1,3 @@ package com.postgraduate.domain.senior.application.dto.res; -public record SeniorPossibleResponse(Boolean possible) {} +public record SeniorPossibleResponse(Boolean possible, Long socialId) {} 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 3f48182b..146be502 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 @@ -114,7 +114,7 @@ public static Info mapToInfo(SeniorChangeRequest request) { public static SeniorMyPageResponse mapToSeniorMyPageInfo(Senior senior, Status certificationRegister, boolean profileRegister) { User user = senior.getUser(); - return new SeniorMyPageResponse(senior.getSeniorId(), user.getSocialId(), user.getNickName(), user.getProfile(), certificationRegister, profileRegister); + return new SeniorMyPageResponse(user.getSocialId(), senior.getSeniorId(), user.getNickName(), user.getProfile(), certificationRegister, profileRegister); } public static SeniorMyPageProfileResponse mapToMyPageProfile(Senior senior, List times) { 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 3579a068..a21e6b04 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 @@ -5,10 +5,7 @@ import com.postgraduate.domain.available.application.mapper.AvailableMapper; import com.postgraduate.domain.available.domain.entity.Available; import com.postgraduate.domain.available.domain.service.AvailableGetService; -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.SeniorProfileResponse; -import com.postgraduate.domain.senior.application.dto.res.SeniorSearchResponse; +import com.postgraduate.domain.senior.application.dto.res.*; import com.postgraduate.domain.senior.application.mapper.SeniorMapper; import com.postgraduate.domain.senior.domain.entity.Senior; import com.postgraduate.domain.senior.domain.service.SeniorGetService; @@ -73,4 +70,12 @@ public AvailableTimesResponse getSeniorTimes(Long seniorId) { .toList(); return new AvailableTimesResponse(senior.getUser().getNickName(), times); } + + public AllSeniorIdResponse getAllSeniorId() { + List seniors = seniorGetService.allSeniorId(); + List seniorIds = seniors.stream() + .map(senior -> senior.getSeniorId()) + .toList(); + return new AllSeniorIdResponse(seniorIds); + } } 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 5a8067f7..d9e27483 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 @@ -73,7 +73,7 @@ public SeniorMyPageUserAccountResponse getSeniorMyPageUserAccount(User user) { public SeniorPossibleResponse checkUser(User user) { Optional wish = wishGetService.byUser(user); if (wish.isEmpty()) - return new SeniorPossibleResponse(FALSE); - return new SeniorPossibleResponse(TRUE); + return new SeniorPossibleResponse(FALSE, user.getSocialId()); + return new SeniorPossibleResponse(TRUE, user.getSocialId()); } } 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 71bbe607..d04f4b94 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 @@ -4,9 +4,11 @@ import com.postgraduate.domain.user.domain.entity.User; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; import java.util.Optional; public interface SeniorRepository extends JpaRepository, SeniorDslRepository { Optional findByUser(User user); Optional findBySeniorIdAndUser_IsDelete(Long seniorId, Boolean isDelete); + List findAllByUser_IsDelete(Boolean isDelete); } 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 0c7a9257..48ced89c 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 @@ -60,4 +60,8 @@ public Page byField(String field, String postgradu, Integer page) { Page allByFieldSenior = seniorRepository.findAllByFieldSenior(field, postgradu, pageable); return allByFieldSenior; } + + public List allSeniorId() { + return seniorRepository.findAllByUser_IsDelete(FALSE); + } } 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 027f61a1..4f4c469c 100644 --- a/src/main/java/com/postgraduate/domain/senior/presentation/SeniorController.java +++ b/src/main/java/com/postgraduate/domain/senior/presentation/SeniorController.java @@ -28,6 +28,13 @@ public class SeniorController { private final SeniorManageUseCase seniorManageUseCase; private final SeniorInfoUseCase seniorInfoUseCase; + @GetMapping("/all") + @Operation(summary = "모든 SeniorID 조회") + public ResponseDto getAllSeniorId() { + AllSeniorIdResponse seniorIds = seniorInfoUseCase.getAllSeniorId(); + return ResponseDto.create(SENIOR_FIND.getCode(), GET_SENIOR_ID_LIST.getMessage(), seniorIds); + } + @PatchMapping("/certification") @Operation(summary = "대학원생 인증 | 토큰 필요", description = "이미지 업로드 이후 url 담아서 요청") public ResponseDto updateCertification(@AuthenticationPrincipal User user, diff --git a/src/main/java/com/postgraduate/domain/senior/presentation/constant/SeniorResponseMessage.java b/src/main/java/com/postgraduate/domain/senior/presentation/constant/SeniorResponseMessage.java index 12cd7265..3299138f 100644 --- a/src/main/java/com/postgraduate/domain/senior/presentation/constant/SeniorResponseMessage.java +++ b/src/main/java/com/postgraduate/domain/senior/presentation/constant/SeniorResponseMessage.java @@ -18,6 +18,7 @@ public enum SeniorResponseMessage { GET_SENIOR_MYPAGE_ACCOUNT("대학원생 마이페이지 계정 조회에 성공하였습니다"), GET_SENIOR_PROFILE("대학원생 프로필 조회에 성공하였습니다"), GET_SENIOR_LIST_INFO("대학원생 리스트 조회에 성공하였습니다."), + GET_SENIOR_ID_LIST("SeniorId 리스트 조회에 성공하였습니다."), UPDATE_CERTIFICATION("대학원생 인증사진 업로드에 성공하였습니다"), UPDATE_STATUS("대학원생 승인 요청 응답에 성공하였습니다"), GET_USER_CHECK("후배 변경 가능 여부 확인에 성공하였습니다"), diff --git a/src/test/java/com/postgraduate/domain/mentoring/application/usecase/MentoringSeniorInfoUseCaseTest.java b/src/test/java/com/postgraduate/domain/mentoring/application/usecase/MentoringSeniorInfoUseCaseTest.java index 0a467b53..25d90901 100644 --- a/src/test/java/com/postgraduate/domain/mentoring/application/usecase/MentoringSeniorInfoUseCaseTest.java +++ b/src/test/java/com/postgraduate/domain/mentoring/application/usecase/MentoringSeniorInfoUseCaseTest.java @@ -158,9 +158,9 @@ void getSeniorExpected() { User user = mock(User.class); Senior senior = mock(Senior.class); - Mentoring mentoring1 = new Mentoring(1L, user, senior, "A", "b", "a", 40, WAITING, LocalDateTime.now(), LocalDateTime.now()); - Mentoring mentoring2 = new Mentoring(2L, user, senior, "A", "b", "a", 40, WAITING, LocalDateTime.now(), LocalDateTime.now()); - Mentoring mentoring3 = new Mentoring(3L, user, senior, "A", "b", "a", 40, WAITING, LocalDateTime.now(), LocalDateTime.now()); + Mentoring mentoring1 = new Mentoring(1L, user, senior, "A", "b", "2024-01-20-17-00", 40, WAITING, LocalDateTime.now(), LocalDateTime.now()); + Mentoring mentoring2 = new Mentoring(2L, user, senior, "A", "b", "2024-01-20-17-00", 40, WAITING, LocalDateTime.now(), LocalDateTime.now()); + Mentoring mentoring3 = new Mentoring(3L, user, senior, "A", "b", "2024-01-20-17-00", 40, WAITING, LocalDateTime.now(), LocalDateTime.now()); List mentorings = List.of(mentoring1, mentoring2, mentoring3); given(seniorGetService.byUser(user)) diff --git a/src/test/java/com/postgraduate/domain/mentoring/presentation/MentoringControllerTest.java b/src/test/java/com/postgraduate/domain/mentoring/presentation/MentoringControllerTest.java index 09d73b2c..21e62cb8 100644 --- a/src/test/java/com/postgraduate/domain/mentoring/presentation/MentoringControllerTest.java +++ b/src/test/java/com/postgraduate/domain/mentoring/presentation/MentoringControllerTest.java @@ -286,7 +286,7 @@ void updateMentoringCancelWithoutWaiting(Status status) throws Exception { @EnumSource(value = Status.class, names = {"WAITING", "EXPECTED", "DONE"}) @DisplayName("대학원생이 멘토링 목록을 조회한다.") void getSeniorMentorings(Status status) throws Exception { - Mentoring mentoring = new Mentoring(0L, user, senior, "topic", "question", "date", 40, status, now(), now()); + Mentoring mentoring = new Mentoring(0L, user, senior, "topic", "question", "2024-01-20-18-00", 40, status, now(), now()); mentoringRepository.save(mentoring); Salary salary = new Salary(0L, false, senior, null, 10000, LocalDate.now(), now(), null, null, null);