Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…uate-back into RAC-254
  • Loading branch information
ay-eonii committed Jan 21, 2024
2 parents 2bb91e4 + 112632e commit 5a5017f
Show file tree
Hide file tree
Showing 18 changed files with 80 additions and 22 deletions.
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
Original file line number Diff line number Diff line change
@@ -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) {
}
Original file line number Diff line number Diff line change
@@ -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) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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();
Expand All @@ -61,7 +63,12 @@ public SeniorMentoringResponse getSeniorWaiting(User user) {
public SeniorMentoringResponse getSeniorExpected(User user) {
List<Mentoring> mentorings = getMentorings(user, EXPECTED);
List<ExpectedSeniorMentoringInfo> 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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.postgraduate.domain.senior.application.dto.res;

import java.util.List;

public record AllSeniorIdResponse(List<Long> seniorIds) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package com.postgraduate.domain.senior.application.dto.res;

public record SeniorPossibleResponse(Boolean possible) {}
public record SeniorPossibleResponse(Boolean possible, Long socialId) {}
Original file line number Diff line number Diff line change
Expand Up @@ -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<AvailableTimeResponse> times) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -73,4 +70,12 @@ public AvailableTimesResponse getSeniorTimes(Long seniorId) {
.toList();
return new AvailableTimesResponse(senior.getUser().getNickName(), times);
}

public AllSeniorIdResponse getAllSeniorId() {
List<Senior> seniors = seniorGetService.allSeniorId();
List<Long> seniorIds = seniors.stream()
.map(senior -> senior.getSeniorId())
.toList();
return new AllSeniorIdResponse(seniorIds);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public SeniorMyPageUserAccountResponse getSeniorMyPageUserAccount(User user) {
public SeniorPossibleResponse checkUser(User user) {
Optional<Wish> 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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Senior, Long>, SeniorDslRepository {
Optional<Senior> findByUser(User user);
Optional<Senior> findBySeniorIdAndUser_IsDelete(Long seniorId, Boolean isDelete);
List<Senior> findAllByUser_IsDelete(Boolean isDelete);
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,8 @@ public Page<Senior> byField(String field, String postgradu, Integer page) {
Page<Senior> allByFieldSenior = seniorRepository.findAllByFieldSenior(field, postgradu, pageable);
return allByFieldSenior;
}

public List<Senior> allSeniorId() {
return seniorRepository.findAllByUser_IsDelete(FALSE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ public class SeniorController {
private final SeniorManageUseCase seniorManageUseCase;
private final SeniorInfoUseCase seniorInfoUseCase;

@GetMapping("/all")
@Operation(summary = "모든 SeniorID 조회")
public ResponseDto<AllSeniorIdResponse> 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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("후배 변경 가능 여부 확인에 성공하였습니다"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Mentoring> mentorings = List.of(mentoring1, mentoring2, mentoring3);

given(seniorGetService.byUser(user))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 5a5017f

Please sign in to comment.