Skip to content

Commit

Permalink
Merge pull request #36 from WE-ARE-RACCOONS/RAC-137
Browse files Browse the repository at this point in the history
RAC-137 test : ν…ŒμŠ€νŠΈ μ½”λ“œ μž‘μ„±
  • Loading branch information
ywj9811 authored Nov 10, 2023
2 parents c2eb6ea + f9376ae commit 8787f33
Show file tree
Hide file tree
Showing 36 changed files with 742 additions and 194 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import com.postgraduate.domain.auth.application.dto.res.JwtTokenResponse;
import com.postgraduate.domain.user.domain.entity.User;
import com.postgraduate.global.auth.AuthDetails;
import com.postgraduate.global.config.security.util.SecurityUtils;
import com.postgraduate.global.jwt.JwtProvider;
import com.postgraduate.global.config.security.jwt.JwtProvider;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
Expand All @@ -14,7 +12,6 @@
@Service
public class JwtUseCase {
private final JwtProvider jwtProvider;
private final SecurityUtils securityUtils;
@Value("${jwt.refreshExpiration}")
private int refreshExpiration;
@Value("${jwt.accessExpiration}")
Expand All @@ -24,8 +21,7 @@ public JwtTokenResponse signIn(User user) {
return generateToken(user);
}

public JwtTokenResponse regenerateToken(AuthDetails authDetails, HttpServletRequest request) {
User user = securityUtils.getLoggedInUser(authDetails);
public JwtTokenResponse regenerateToken(User user, HttpServletRequest request) {
jwtProvider.checkRedis(user.getUserId(), request);
return generateToken(user);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public ResponseDto<JwtTokenResponse> signUpUser(@RequestBody SignUpRequest reque

@PostMapping("/refresh")
@Operation(summary = "토큰 μž¬λ°œκΈ‰", description = "refreshToken 으둜 토큰 μž¬λ°œκΈ‰")
public ResponseDto<JwtTokenResponse> refresh(@AuthenticationPrincipal AuthDetails authDetails, HttpServletRequest request) {
JwtTokenResponse jwtToken = jwtUseCase.regenerateToken(authDetails, request);
public ResponseDto<JwtTokenResponse> refresh(@AuthenticationPrincipal User user, HttpServletRequest request) {
JwtTokenResponse jwtToken = jwtUseCase.regenerateToken(user, request);
return ResponseDto.create(AUTH_UPDATE.getCode(), SUCCESS_REGENERATE_TOKEN.getMessage(), jwtToken);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import com.postgraduate.domain.senior.domain.entity.Senior;
import com.postgraduate.domain.senior.domain.service.SeniorGetService;
import com.postgraduate.domain.user.domain.entity.User;
import com.postgraduate.global.auth.AuthDetails;
import com.postgraduate.global.config.security.util.SecurityUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -16,21 +14,18 @@
@Transactional
@RequiredArgsConstructor
public class CheckIsMyMentoringUseCase {
private final SecurityUtils securityUtils;
private final SeniorGetService seniorGetService;
private final MentoringGetService mentoringGetService;

public Mentoring byUser(AuthDetails authDetails, Long mentoringId) {
User user = securityUtils.getLoggedInUser(authDetails);
public Mentoring byUser(User user, Long mentoringId) {
Mentoring mentoring = mentoringGetService.byMentoringId(mentoringId);
if (mentoring.getUser() != user) {
throw new PermissionDeniedException();
}
return mentoring;
}

public Mentoring bySenior(AuthDetails authDetails, Long mentoringId) {
User user = securityUtils.getLoggedInUser(authDetails);
public Mentoring bySenior(User user, Long mentoringId) {
Senior senior = seniorGetService.byUser(user);
Mentoring mentoring = mentoringGetService.byMentoringId(mentoringId);
if (mentoring.getSenior() != senior) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import com.postgraduate.domain.senior.domain.entity.Senior;
import com.postgraduate.domain.senior.domain.service.SeniorGetService;
import com.postgraduate.domain.user.domain.entity.User;
import com.postgraduate.global.auth.AuthDetails;
import com.postgraduate.global.config.security.util.SecurityUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -17,12 +15,10 @@
@Transactional
@RequiredArgsConstructor
public class MentoringApplyUseCase {
private final SecurityUtils securityUtils;
private final MentoringSaveService mentoringSaveService;
private final SeniorGetService seniorGetService;

public void applyMentoring(AuthDetails authDetails, MentoringApplyRequest request) {
User user = securityUtils.getLoggedInUser(authDetails);
public void applyMentoring(User user, MentoringApplyRequest request) {
Senior senior = seniorGetService.bySeniorId(request.getSeniorId());
Mentoring mentoring = MentoringMapper.mapToMentoring(user, senior, request);
mentoringSaveService.save(mentoring);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
import com.postgraduate.domain.senior.domain.entity.Senior;
import com.postgraduate.domain.senior.domain.service.SeniorGetService;
import com.postgraduate.domain.user.domain.entity.User;
import com.postgraduate.global.auth.AuthDetails;
import com.postgraduate.global.config.security.util.SecurityUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -34,20 +32,13 @@ public class MentoringInfoUseCase {
private final MentoringGetService mentoringGetService;
private final CheckIsMyMentoringUseCase checkIsMyMentoringUseCase;
private final SeniorGetService seniorGetService;
private final SecurityUtils securityUtils;
/**
* securityUtils 이후 μˆ˜μ •
*/

public AppliedMentoringResponse getMentorings(Status status, AuthDetails authDetails) {
User user = securityUtils.getLoggedInUser(authDetails);

public AppliedMentoringResponse getMentorings(Status status, User user) {
List<Mentoring> mentorings = mentoringGetService.mentoringByUser(user, status);
return getCategories(status, mentorings);
}

public List<SeniorMentoringResponse> getSeniorMentorings(Status status, AuthDetails authDetails) {
User user = securityUtils.getLoggedInUser(authDetails);
public List<SeniorMentoringResponse> getSeniorMentorings(Status status, User user) {
Senior senior = seniorGetService.byUser(user);

List<Mentoring> mentorings = mentoringGetService.mentoringBySenior(senior, status);
Expand All @@ -74,16 +65,16 @@ private AppliedMentoringResponse getCategories(Status status, List<Mentoring> me
}
}

public AppliedMentoringDetailResponse getMentoringDetail(AuthDetails authDetails, Long mentoringId) {
Mentoring mentoring = checkIsMyMentoringUseCase.byUser(authDetails, mentoringId);
public AppliedMentoringDetailResponse getMentoringDetail(User user, Long mentoringId) {
Mentoring mentoring = checkIsMyMentoringUseCase.byUser(user, mentoringId);
if (mentoring.getStatus() != WAITING) {
throw new MentoringNotWaitingException();
}
return MentoringMapper.mapToAppliedDetailInfo(mentoring);
}

public SeniorMentoringDetailResponse getSeniorMentoringDetail(AuthDetails authDetails, Long mentoringId) {
Mentoring mentoring = checkIsMyMentoringUseCase.bySenior(authDetails, mentoringId);
public SeniorMentoringDetailResponse getSeniorMentoringDetail(User user, Long mentoringId) {
Mentoring mentoring = checkIsMyMentoringUseCase.bySenior(user, mentoringId);
if (mentoring.getStatus() == DONE) {
throw new MentoringDoneException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.postgraduate.domain.mentoring.domain.entity.constant.Status;
import com.postgraduate.domain.mentoring.domain.service.MentoringUpdateService;
import com.postgraduate.domain.mentoring.exception.MentoringNotWaitingException;
import com.postgraduate.global.auth.AuthDetails;
import com.postgraduate.domain.user.domain.entity.User;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -20,24 +20,24 @@ public class MentoringManageUseCase {
private final CheckIsMyMentoringUseCase checkIsMyMentoringUseCase;
private final MentoringUpdateService mentoringUpdateService;

public void updateStatus(AuthDetails authDetails, Long mentoringId, Status status) {
Mentoring mentoring = checkIsMyMentoringUseCase.byUser(authDetails, mentoringId);
public void updateStatus(User user, Long mentoringId, Status status) {
Mentoring mentoring = checkIsMyMentoringUseCase.byUser(user, mentoringId);
mentoringUpdateService.updateStatus(mentoring, status);
}

public void updateSeniorStatus(AuthDetails authDetails, Long mentoringId, Status status) {
Mentoring mentoring = checkIsMyMentoringUseCase.bySenior(authDetails, mentoringId);
public void updateSeniorStatus(User user, Long mentoringId, Status status) {
Mentoring mentoring = checkIsMyMentoringUseCase.bySenior(user, mentoringId);
mentoringUpdateService.updateStatus(mentoring, status);
}

public void updateRefuse(AuthDetails authDetails, Long mentoringId, MentoringRefuseRequest request, Status status) {
Mentoring mentoring = checkIsMyMentoringUseCase.bySenior(authDetails, mentoringId);
public void updateRefuse(User user, Long mentoringId, MentoringRefuseRequest request, Status status) {
Mentoring mentoring = checkIsMyMentoringUseCase.bySenior(user, mentoringId);
mentoringUpdateService.updateRefuse(mentoring, request.getRefuse());
mentoringUpdateService.updateStatus(mentoring, status);
}

public void updateDate(AuthDetails authDetails, Long mentoringId, MentoringDateRequest request) {
Mentoring mentoring = checkIsMyMentoringUseCase.bySenior(authDetails, mentoringId);
public void updateDate(User user, Long mentoringId, MentoringDateRequest request) {
Mentoring mentoring = checkIsMyMentoringUseCase.bySenior(user, mentoringId);
if (mentoring.getStatus() != WAITING) {
throw new MentoringNotWaitingException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import com.postgraduate.domain.mentoring.application.usecase.MentoringInfoUseCase;
import com.postgraduate.domain.mentoring.application.usecase.MentoringManageUseCase;
import com.postgraduate.domain.mentoring.domain.entity.constant.Status;
import com.postgraduate.global.auth.AuthDetails;
import com.postgraduate.domain.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;
Expand All @@ -35,77 +35,77 @@ public class MentoringController {

@GetMapping("/me")
@Operation(summary = "[λŒ€ν•™μƒ] μ‹ μ²­ν•œ λ©˜ν† λ§ λͺ©λ‘ 쑰회", description = "λŒ€ν•™μƒμ΄ μ‹ μ²­ν•œ λ©˜ν† λ§ λͺ©λ‘μ„ μ‘°νšŒν•©λ‹ˆλ‹€.")
public ResponseDto<AppliedMentoringResponse> getMentoringInfos(@RequestParam Status status, @AuthenticationPrincipal AuthDetails authDetails) {
AppliedMentoringResponse mentoringResponse = infoUsecase.getMentorings(status, authDetails);
public ResponseDto<AppliedMentoringResponse> getMentoringInfos(@RequestParam Status status, @AuthenticationPrincipal User user) {
AppliedMentoringResponse mentoringResponse = infoUsecase.getMentorings(status, user);
return ResponseDto.create(MENTORING_FIND.getCode(), GET_MENTORING_LIST_INFO.getMessage(), mentoringResponse);
}

@GetMapping("/me/{mentoringId}")
@Operation(summary = "[λŒ€ν•™μƒ] μ‹ μ²­ν•œ λ©˜ν† λ§ μƒμ„Έμ‘°νšŒ", description = "λŒ€ν•™μƒμ΄ μ‹ μ²­ν•œ λ©˜ν† λ§μ„ μƒμ„Έμ‘°νšŒν•©λ‹ˆλ‹€. <ν™•μ •λŒ€κΈ°> μƒνƒœμ˜ λ©˜ν† λ§λ§Œ 쑰회 κ°€λŠ₯ν•©λ‹ˆλ‹€.")
public ResponseDto<AppliedMentoringDetailResponse> getMentoringDetail(@AuthenticationPrincipal AuthDetails authDetails, @PathVariable Long mentoringId) {
AppliedMentoringDetailResponse mentoringDetail = infoUsecase.getMentoringDetail(authDetails, mentoringId);
public ResponseDto<AppliedMentoringDetailResponse> getMentoringDetail(@AuthenticationPrincipal User user, @PathVariable Long mentoringId) {
AppliedMentoringDetailResponse mentoringDetail = infoUsecase.getMentoringDetail(user, mentoringId);
return ResponseDto.create(MENTORING_FIND.getCode(), GET_MENTORING_DETAIL_INFO.getMessage(), mentoringDetail);
}

@PostMapping()
@Operation(summary = "[λŒ€ν•™μƒ] λ©˜ν† λ§ μ‹ μ²­", description = "λŒ€ν•™μƒμ΄ λ©˜ν† λ§μ„ μ‹ μ²­ν•©λ‹ˆλ‹€.")
public ResponseDto applyMentoring(@AuthenticationPrincipal AuthDetails authDetails, @RequestBody MentoringApplyRequest request) {
applyUseCase.applyMentoring(authDetails, request);
public ResponseDto applyMentoring(@AuthenticationPrincipal User user, @RequestBody MentoringApplyRequest request) {
applyUseCase.applyMentoring(user, request);
return ResponseDto.create(MENTORING_CREATE.getCode(), CREATE_MENTORING.getMessage());
}

@PatchMapping("/me/{mentoringId}/done")
@Operation(summary = "[λŒ€ν•™μƒ] λ©˜ν† λ§ μƒνƒœ μ—…λ°μ΄νŠΈ(μ™„λ£Œ)", description = "λŒ€ν•™μƒμ΄ λ©˜ν† λ§μ„ μ™„λ£Œν•©λ‹ˆλ‹€.")
public ResponseDto updateMentoringDone(@AuthenticationPrincipal AuthDetails authDetails,
public ResponseDto updateMentoringDone(@AuthenticationPrincipal User user,
@PathVariable Long mentoringId) {
manageUseCase.updateStatus(authDetails, mentoringId, Status.DONE);
manageUseCase.updateStatus(user, mentoringId, Status.DONE);
return ResponseDto.create(MENTORING_UPDATE.getCode(), UPDATE_MENTORING.getMessage());
}

@PatchMapping("/me/{mentoringId}/cancel")
@Operation(summary = "[λŒ€ν•™μƒ] λ©˜ν† λ§ μƒνƒœ μ—…λ°μ΄νŠΈ(μ·¨μ†Œ)", description = "λŒ€ν•™μƒμ΄ μ‹ μ²­ν•œ λ©˜ν† λ§μ„ μ·¨μ†Œν•©λ‹ˆλ‹€.")
public ResponseDto updateMentoringCancel(@AuthenticationPrincipal AuthDetails authDetails,
public ResponseDto updateMentoringCancel(@AuthenticationPrincipal User user,
@PathVariable Long mentoringId) {
manageUseCase.updateStatus(authDetails, mentoringId, Status.CANCEL);
manageUseCase.updateStatus(user, mentoringId, Status.CANCEL);
return ResponseDto.create(MENTORING_UPDATE.getCode(), UPDATE_MENTORING.getMessage());
}

@GetMapping("/senior/me")
@Operation(summary = "[λŒ€ν•™μ›μƒ] 신청받은 λ©˜ν† λ§ λͺ©λ‘ 쑰회", description = "λŒ€ν•™μ›μƒμ΄ 신청받은 λ©˜ν† λ§ λͺ©λ‘μ„ μ‘°νšŒν•©λ‹ˆλ‹€.")
public ResponseDto<List<SeniorMentoringResponse>> getSeniorMentorings(@RequestParam Status status, @AuthenticationPrincipal AuthDetails authDetails) {
List<SeniorMentoringResponse> seniorMentorings = infoUsecase.getSeniorMentorings(status, authDetails);
public ResponseDto<List<SeniorMentoringResponse>> getSeniorMentorings(@RequestParam Status status, @AuthenticationPrincipal User user) {
List<SeniorMentoringResponse> seniorMentorings = infoUsecase.getSeniorMentorings(status, user);
return ResponseDto.create(MENTORING_FIND.getCode(), GET_MENTORING_LIST_INFO.getMessage(), seniorMentorings);
}

@GetMapping("/senior/me/{mentoringId}")
@Operation(summary = "[λŒ€ν•™μ›μƒ] 신청받은 λ©˜ν† λ§ μƒμ„Έμ‘°νšŒ", description = "λŒ€ν•™μ›μƒμ΄ 신청받은 λ©˜ν† λ§μ„ μƒμ„Έμ‘°νšŒν•©λ‹ˆλ‹€. <μ™„λ£Œ> μƒνƒœμ˜ λ©˜ν† λ§μ€ μƒμ„Έμ‘°νšŒλ˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€.")
public ResponseDto<SeniorMentoringDetailResponse> getSeniorMentoringDetail(@AuthenticationPrincipal AuthDetails authDetails, @PathVariable Long mentoringId) {
SeniorMentoringDetailResponse seniorMentoringDetail = infoUsecase.getSeniorMentoringDetail(authDetails, mentoringId);
public ResponseDto<SeniorMentoringDetailResponse> getSeniorMentoringDetail(@AuthenticationPrincipal User user, @PathVariable Long mentoringId) {
SeniorMentoringDetailResponse seniorMentoringDetail = infoUsecase.getSeniorMentoringDetail(user, mentoringId);
return ResponseDto.create(MENTORING_FIND.getCode(), GET_MENTORING_DETAIL_INFO.getMessage(), seniorMentoringDetail);
}

@PatchMapping("/senior/me/{mentoringId}/time")
@Operation(summary = "[λŒ€ν•™μ›μƒ] λ©˜ν† λ§ μ‹œκ°„ 선택", description = "λŒ€ν•™μƒμ΄ μ‹ μ²­ν•œ μ‹œκ°„ μ˜΅μ…˜ 3개 쀑 ν•˜λ‚˜λ₯Ό μ„ νƒν•©λ‹ˆλ‹€. ν™•μ • λŒ€κΈ° μƒνƒœμ˜ λ©˜ν† λ§λ§Œ κ°€λŠ₯ν•©λ‹ˆλ‹€.")
public ResponseDto updateMentoringDate(@AuthenticationPrincipal AuthDetails authDetails,
public ResponseDto updateMentoringDate(@AuthenticationPrincipal User user,
@PathVariable Long mentoringId,
@RequestBody MentoringDateRequest request) {
manageUseCase.updateDate(authDetails, mentoringId, request);
manageUseCase.updateDate(user, mentoringId, request);
return ResponseDto.create(MENTORING_UPDATE.getCode(), UPDATE_MENTORING.getMessage());
}

@PatchMapping("/senior/me/{mentoringId}/expected")
@Operation(summary = "[λŒ€ν•™μ›μƒ] λ©˜ν† λ§ μƒνƒœ μ—…λ°μ΄νŠΈ(μ˜ˆμ •λœ λ©˜ν† λ§)", description = "λŒ€ν•™μ›μƒμ΄ λ©˜ν† λ§μ„ μˆ˜λ½ν•©λ‹ˆλ‹€.")
public ResponseDto updateMentoringExpected(@AuthenticationPrincipal AuthDetails authDetails, @PathVariable Long mentoringId) {
manageUseCase.updateSeniorStatus(authDetails, mentoringId, Status.EXPECTED);
public ResponseDto updateMentoringExpected(@AuthenticationPrincipal User user, @PathVariable Long mentoringId) {
manageUseCase.updateSeniorStatus(user, mentoringId, Status.EXPECTED);
return ResponseDto.create(MENTORING_UPDATE.getCode(), UPDATE_MENTORING.getMessage());
}

@PatchMapping("/senior/me/{mentoringId}/cancel")
@Operation(summary = "[λŒ€ν•™μ›μƒ] λ©˜ν† λ§ μƒνƒœ μ—…λ°μ΄νŠΈ(거절)", description = "λŒ€ν•™μ›μƒμ΄ λ©˜ν† λ§μ„ κ±°μ ˆν•˜κ³  κ±°μ ˆμ‚¬μœ λ₯Ό λ³€κ²½ν•©λ‹ˆλ‹€.")
public ResponseDto updateMentoringCancel(@AuthenticationPrincipal AuthDetails authDetails,
public ResponseDto updateMentoringCancel(@AuthenticationPrincipal User user,
@PathVariable Long mentoringId,
@RequestBody MentoringRefuseRequest request) {
manageUseCase.updateRefuse(authDetails, mentoringId, request, Status.CANCEL);
manageUseCase.updateRefuse(user, mentoringId, request, Status.CANCEL);
return ResponseDto.create(MENTORING_UPDATE.getCode(), UPDATE_MENTORING.getMessage());
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.postgraduate.domain.senior.application.dto.res;

import com.postgraduate.domain.senior.domain.entity.Account;
import com.postgraduate.domain.senior.domain.entity.Profile;
import lombok.AllArgsConstructor;
import lombok.Builder;
Expand All @@ -11,5 +10,6 @@
@AllArgsConstructor
public class SeniorProfileResponse {
private Profile profile;
private Account account;
private String account;
private String bank;
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ public static SeniorInfoResponse mapToSeniorInfo(Senior senior, Status certifica
public static SeniorProfileResponse mapToSeniorProfileInfo(Senior senior) {
return SeniorProfileResponse.builder()
.profile(senior.getProfile())
.account(senior.getAccount())
.account(senior.getAccount().getAccount())
.bank(senior.getAccount().getBank())
.build();
}
}
Loading

0 comments on commit 8787f33

Please sign in to comment.