Skip to content

Commit

Permalink
Merge pull request #70 from WE-ARE-RACCOONS/RAC-224
Browse files Browse the repository at this point in the history
RAC-224 fix : ํšŒ์› ํƒˆํ‡ด ๋กœ์ง ์ถ”๊ฐ€ ๋ฐ ๊ธฐ์กด ์กฐํšŒ ์ˆ˜์ •
  • Loading branch information
ywj9811 authored Dec 17, 2023
2 parents ad1ce67 + de2fa1a commit 4719624
Show file tree
Hide file tree
Showing 29 changed files with 200 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ public SalaryDetailsResponse getSalary(Long seniorId) {
public SalaryManageResponse getSalaries() {
List<SalaryInfo> responses = new ArrayList<>();
List<Senior> seniors = seniorGetService.all();
for (Senior senior : seniors) {
List<Salary> salaries = salaryGetService.bySeniorAndSalaryDateAndStatus(senior, getSalaryDate(), true);
if (getStatus(salaries) != DONE) {
continue;
}
seniors.forEach(senior -> {
List<Salary> salaries = salaryGetService.bySeniorAndSalaryDateAndStatus(senior, getSalaryDate(), true)
.stream()
.filter(salary -> (salary.getStatus().equals(DONE)))
.toList();
SalaryInfo response = getSalaryInfo(senior, salaries);
responses.add(response);
}
});
return new SalaryManageResponse(responses);
}

Expand All @@ -80,8 +80,6 @@ private SalaryInfo getSalaryInfo(Senior senior, List<Salary> salaries) {
public void updateSalaryStatus(Long seniorId, Boolean status) {
Senior senior = seniorGetService.bySeniorId(seniorId);
List<Salary> salaries = salaryGetService.bySeniorAndSalaryDate(senior, getSalaryDate());
for (Salary salary : salaries) {
salaryUpdateService.updateStatus(salary, status);
}
salaries.forEach(salary -> salaryUpdateService.updateStatus(salary, status));
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,7 @@
package com.postgraduate.domain.auth.application.dto.res;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import jakarta.validation.constraints.NotNull;

@Builder
@Getter
@AllArgsConstructor
@NoArgsConstructor
public class KakaoTokenInfoResponse {
private String access_token;
private String token_type;
private String refresh_token;
private String id_token;
private int expires_in;
private String cope;
private int refresh_token_expires_in;
public record KakaoTokenInfoResponse(@NotNull String access_token, @NotNull String token_type, @NotNull String refresh_token, @NotNull String id_token,
@NotNull int expires_in, @NotNull String cope, @NotNull int refresh_token_expires_in) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.postgraduate.domain.auth.application.dto.res.JwtTokenResponse;
import com.postgraduate.domain.user.domain.entity.User;
import com.postgraduate.domain.user.exception.DeletedUserException;
import com.postgraduate.global.config.security.jwt.util.JwtUtils;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
Expand All @@ -26,11 +27,15 @@ public void logout(User user) {
}

public JwtTokenResponse regenerateToken(User user, HttpServletRequest request) {
if (user.getIsDelete())
throw new DeletedUserException();
jwtUtils.checkRedis(user.getUserId(), request);
return generateToken(user);
}

private JwtTokenResponse generateToken(User user) {
if (user.getIsDelete())
throw new DeletedUserException();
String accessToken = jwtUtils.generateAccessToken(user.getUserId(), user.getRole());
String refreshToken = jwtUtils.generateRefreshToken(user.getUserId(), user.getRole());
return new JwtTokenResponse(accessToken, accessExpiration, refreshToken, refreshExpiration, user.getRole());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.postgraduate.domain.auth.application.usecase.oauth;

import com.postgraduate.domain.auth.application.usecase.SignInUseCase;
import com.postgraduate.domain.auth.application.usecase.oauth.kakao.KakaoSignInUseCase;
import com.postgraduate.domain.auth.application.usecase.oauth.kakao.KakaoSignOutUseCase;
import com.postgraduate.domain.auth.exception.OauthException;
import com.postgraduate.domain.auth.presentation.constant.Provider;
import lombok.RequiredArgsConstructor;
Expand All @@ -13,10 +13,17 @@
@Component
public class SelectOauth {
private final KakaoSignInUseCase kakaoSignInUseCase;
private final KakaoSignOutUseCase kakaoSignOutUseCase;

public SignInUseCase selectStrategy(Provider provider) {
public SignInUseCase selectSignIn(Provider provider) {
if (provider.equals(KAKAO))
return kakaoSignInUseCase;
throw new OauthException();
}

public SignOutUseCase selectSignOut(Provider provider) {
if (provider.equals(KAKAO))
return kakaoSignOutUseCase;
throw new OauthException();
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.postgraduate.domain.auth.application.usecase;
package com.postgraduate.domain.auth.application.usecase.oauth;

import com.postgraduate.domain.auth.application.dto.req.CodeRequest;
import com.postgraduate.domain.auth.application.dto.res.AuthUserResponse;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.postgraduate.domain.auth.application.usecase.oauth;

public interface SignOutUseCase {
void signOut(Long userId);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.postgraduate.domain.auth.application.usecase;
package com.postgraduate.domain.auth.application.usecase.oauth;

import com.postgraduate.domain.auth.application.dto.req.SeniorChangeRequest;
import com.postgraduate.domain.auth.application.dto.req.SeniorSignUpRequest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public KakaoUserInfoResponse getAccessToken (CodeRequest codeRequest) {
.retrieve()
.bodyToMono(KakaoTokenInfoResponse.class)
.block();
return getUserInfo(tokenInfoResponse.getAccess_token());
return getUserInfo(tokenInfoResponse.access_token());
} catch (WebClientResponseException ex) {
throw new KakaoCodeException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.postgraduate.domain.auth.application.dto.res.AuthUserResponse;
import com.postgraduate.domain.auth.application.dto.res.KakaoUserInfoResponse;
import com.postgraduate.domain.auth.application.mapper.AuthMapper;
import com.postgraduate.domain.auth.application.usecase.SignInUseCase;
import com.postgraduate.domain.auth.application.usecase.oauth.SignInUseCase;
import com.postgraduate.domain.user.domain.entity.User;
import com.postgraduate.domain.user.domain.service.UserGetService;
import lombok.RequiredArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.postgraduate.domain.auth.application.usecase.oauth.kakao;

import com.postgraduate.domain.auth.application.usecase.oauth.SignOutUseCase;
import com.postgraduate.domain.auth.exception.KakaoException;
import com.postgraduate.domain.user.domain.entity.User;
import com.postgraduate.domain.user.domain.service.UserGetService;
import com.postgraduate.domain.user.domain.service.UserUpdateService;
import com.postgraduate.global.config.security.jwt.util.JwtUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.reactive.function.client.WebClientResponseException;

@Service
@RequiredArgsConstructor
@Transactional
public class KakaoSignOutUseCase implements SignOutUseCase {
private final WebClient webClient;
private final UserUpdateService userUpdateService;
private final UserGetService userGetService;
private final JwtUtils jwtUtils;

@Value("${admin-id.kakao}")
private String ADMIN_ID;
private static final String AUTHORIZATION = "KakaoAK ";
private static final String KAKAO_UNLINK_URI = "https://kapi.kakao.com/v1/user/unlink";

@Override
public void signOut(Long userId) {
try {
User user = userGetService.getUser(userId);
MultiValueMap<String, String> requestBody = getRequestBody(user.getSocialId());
webClient.post()
.uri(KAKAO_UNLINK_URI)
.headers(h -> h.setContentType(MediaType.APPLICATION_FORM_URLENCODED))
.headers(h -> h.set(HttpHeaders.AUTHORIZATION, AUTHORIZATION + ADMIN_ID))
.bodyValue(requestBody)
.retrieve()
.bodyToMono(String.class)
.block();
userUpdateService.updateDelete(user.getUserId());
jwtUtils.makeExpired(userId);
} catch (WebClientResponseException ex) {
throw new KakaoException();
}
}

private MultiValueMap<String, String> getRequestBody(Long socialId) {
MultiValueMap<String, String> requestBody = new LinkedMultiValueMap<>();
requestBody.add("target_id_type", "user_id");
requestBody.add("target_id", socialId.toString());
return requestBody;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
import com.postgraduate.domain.auth.application.dto.res.AuthUserResponse;
import com.postgraduate.domain.auth.application.dto.res.JwtTokenResponse;
import com.postgraduate.domain.auth.application.usecase.oauth.SelectOauth;
import com.postgraduate.domain.auth.application.usecase.SignUpUseCase;
import com.postgraduate.domain.auth.application.usecase.oauth.SignOutUseCase;
import com.postgraduate.domain.auth.application.usecase.oauth.SignUpUseCase;
import com.postgraduate.domain.auth.application.usecase.jwt.JwtUseCase;
import com.postgraduate.domain.auth.application.usecase.SignInUseCase;
import com.postgraduate.domain.auth.application.usecase.oauth.SignInUseCase;
import com.postgraduate.domain.auth.presentation.constant.Provider;
import com.postgraduate.domain.user.domain.entity.User;
import com.postgraduate.global.dto.ResponseDto;
Expand Down Expand Up @@ -38,7 +39,7 @@ public class AuthController {
@PostMapping("/login/{provider}")
@Operation(summary = "์†Œ์…œ ๋กœ๊ทธ์ธ", description = "ํšŒ์›์ธ ๊ฒฝ์šฐ JWT๋ฅผ, ํšŒ์›์ด ์•„๋‹Œ ๊ฒฝ์šฐ socialId๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค(ํšŒ์›๊ฐ€์ž…์€ ์ง„ํ–‰ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค).")
public ResponseDto<?> authLogin(@RequestBody @Valid CodeRequest request, @PathVariable Provider provider) {
SignInUseCase signInUseCase = selectOauth.selectStrategy(provider);
SignInUseCase signInUseCase = selectOauth.selectSignIn(provider);
AuthUserResponse authUser = signInUseCase.getUser(request);
if (authUser.getUser().isEmpty())
return ResponseDto.create(AUTH_NONE.getCode(), NOT_REGISTERED_USER.getMessage(), authUser);
Expand All @@ -53,6 +54,18 @@ public ResponseDto logout(@AuthenticationPrincipal User user) {
return ResponseDto.create(AUTH_DELETE.getCode(), LOGOUT_USER.getMessage());
}

/**
* ์šฐ์„  ๋ฌธ์˜๋ฅผ ํ†ตํ•ด ํƒˆํ‡ด๋ฅผ ์‹œ์ผœ์ค€๋‹ค ํ–ˆ์œผ๋‹ˆ ์œ ์ € ํ† ํฐ์„ ๋ฐ›์„ ์ˆ˜ ์—†๋‹ค
* ๋‹ค๋งŒ, userId๋ฅผ ํ†ตํ•ด ํƒˆํ‡ด๋ฅผ ์ฒ˜๋ฆฌ์‹œ์ผœ์ค„ ๋•Œ ๊ทธ ์–ด๋–ค ๋ณด์•ˆ ์žฅ์น˜๋„ ์—†๋‹ค๋ฉด ๋ฌธ์ œ์ธ ๊ฒƒ ๊ฐ™์œผ๋‹ˆ ๊ด€๋ฆฌ์ž์˜ ๊ถŒํ•œ์œผ๋กœ ์ฒ˜๋ฆฌํ•œ๋‹ค
*/
@PostMapping("/signout/{provider}/{userId}")
@Operation(summary = "ํšŒ์› ํƒˆํ‡ด | ๊ด€๋ฆฌ์ž ํ† ํฐ ํ•„์š”", description = "ํšŒ์› ํƒˆํ‡ด ์ง„ํ–‰")
public ResponseDto signOut(@PathVariable Provider provider, @PathVariable Long userId) {
SignOutUseCase signOutUseCase = selectOauth.selectSignOut(provider);
signOutUseCase.signOut(userId);
return ResponseDto.create(AUTH_DELETE.getCode(), SIGNOUT_USER.getMessage());
}

@PostMapping("/user/signup")
@Operation(summary = "๋Œ€ํ•™์ƒ ํšŒ์›๊ฐ€์ž…", description = "๋กœ๊ทธ์ธ API์—์„œ ๋ฐ˜ํ™˜ํ•œ socialId, ๋‹‰๋„ค์ž„, ๋ฒˆํ˜ธ, ๋งˆ์ผ€ํŒ… ์ˆ˜์‹ ์—ฌ๋ถ€, ํฌ๋ง ํ•™๊ณผ, ํฌ๋ง ๋ถ„์•ผ, ๋งค์นญ ํฌ๋ง ์—ฌ๋ถ€")
public ResponseDto<JwtTokenResponse> signUpUser(@RequestBody @Valid SignUpRequest request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public enum AuthResponseMessage {
NOT_REGISTERED_USER("๊ฐ€์ž…ํ•˜์ง€ ์•Š์€ ์œ ์ €์ž…๋‹ˆ๋‹ค."),
SUCCESS_REGENERATE_TOKEN("ํ† ํฐ ์žฌ๋ฐœ๊ธ‰์— ์„ฑ๊ณตํ•˜์˜€์Šต๋‹ˆ๋‹ค."),
LOGOUT_USER("๋กœ๊ทธ์•„์›ƒ์— ์„ฑ๊ณตํ•˜์˜€์Šต๋‹ˆ๋‹ค."),
SIGNOUT_USER("ํšŒ์›ํƒˆํ‡ด์— ์„ฑ๊ณตํ•˜์˜€์Šต๋‹ˆ๋‹ค."),

PERMISSION_DENIED("๊ถŒํ•œ์ด ์—†์Šต๋‹ˆ๋‹ค."),
KAKAO_INVALID("์นด์นด์˜ค ์ •๋ณด๊ฐ€ ์œ ํšจํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
@Transactional
@RequiredArgsConstructor
public class CheckIsMyMentoringUseCase {
private final SeniorGetService seniorGetService;
private final MentoringGetService mentoringGetService;

public Mentoring byUser(User user, Long mentoringId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ public Boolean updateExpected(User user, Long mentoringId, MentoringDateRequest
public void updateCancel() {
LocalDate now = LocalDate.now();
List<Mentoring> mentorings = mentoringGetService.byStatusAndCreatedAt(WAITING, now);
for (Mentoring mentoring : mentorings) {
mentoringUpdateService.updateStatus(mentoring, CANCEL);
Refuse refuse = RefuseMapper.mapToRefuse(mentoring);
refuseSaveService.saveRefuse(refuse);
//TODO : ์•Œ๋ฆผ ๋ณด๋‚ด๊ฑฐ๋‚˜ ๋‚˜๋จธ์ง€ ์ž‘์—…
}
mentorings.forEach(mentoring -> {
mentoringUpdateService.updateStatus(mentoring, CANCEL);
Refuse refuse = RefuseMapper.mapToRefuse(mentoring);
refuseSaveService.saveRefuse(refuse);
//TODO : ์•Œ๋ฆผ ๋ณด๋‚ด๊ฑฐ๋‚˜ ๋‚˜๋จธ์ง€ ์ž‘์—…
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.postgraduate.domain.mentoring.application.dto.ExpectedSeniorMentoringInfo;
import com.postgraduate.domain.mentoring.application.dto.WaitingSeniorMentoringInfo;
import com.postgraduate.domain.mentoring.application.dto.res.*;
import com.postgraduate.domain.mentoring.application.mapper.MentoringMapper;
import com.postgraduate.domain.mentoring.domain.entity.Mentoring;
import com.postgraduate.domain.mentoring.domain.entity.constant.Status;
import com.postgraduate.domain.mentoring.domain.service.MentoringGetService;
Expand Down Expand Up @@ -45,34 +46,35 @@ public SeniorMentoringDetailResponse getSeniorMentoringDetail(User user, Long me

public SeniorMentoringResponse getSeniorWaiting(User user) {
List<Mentoring> mentorings = getMentorings(user, WAITING);
List<WaitingSeniorMentoringInfo> waitingMentoringInfos = new ArrayList<>();
for (Mentoring mentoring : mentorings) {
LocalDateTime expiredAt = mentoring.getCreatedAt()
.plusDays(2)
.atStartOfDay();
LocalDateTime now = LocalDateTime.now();
long remain = Duration.between(now, expiredAt).toMinutes();
waitingMentoringInfos.add(mapToSeniorWaitingInfo(mentoring, remain));
}
List<WaitingSeniorMentoringInfo> waitingMentoringInfos = mentorings.stream()
.map(mentoring -> {
LocalDateTime expiredAt = mentoring.getCreatedAt()
.plusDays(2)
.atStartOfDay();
LocalDateTime now = LocalDateTime.now();
long remain = Duration.between(now, expiredAt).toMinutes();
return mapToSeniorWaitingInfo(mentoring, remain);
})
.toList();
return new SeniorMentoringResponse(waitingMentoringInfos);
}

public SeniorMentoringResponse getSeniorExpected(User user) {
List<Mentoring> mentorings = getMentorings(user, EXPECTED);
List<ExpectedSeniorMentoringInfo> expectedMentoringInfos = new ArrayList<>();
for (Mentoring mentoring : mentorings) {
expectedMentoringInfos.add(mapToSeniorExpectedInfo(mentoring));
}
List<ExpectedSeniorMentoringInfo> expectedMentoringInfos = mentorings.stream()
.map(MentoringMapper::mapToSeniorExpectedInfo)
.toList();
return new SeniorMentoringResponse(expectedMentoringInfos);
}

public SeniorMentoringResponse getSeniorDone(User user) {
List<Mentoring> mentorings = getMentorings(user, DONE);
List<DoneSeniorMentoringInfo> doneMentoringInfos = new ArrayList<>();
for (Mentoring mentoring : mentorings) {
Salary salary = salaryGetService.byMentoring(mentoring);
doneMentoringInfos.add(mapToSeniorDoneInfo(mentoring, salary));
}
List<DoneSeniorMentoringInfo> doneMentoringInfos = mentorings.stream()
.map(mentoring -> {
Salary salary = salaryGetService.byMentoring(mentoring);
return mapToSeniorDoneInfo(mentoring, salary);
})
.toList();
return new SeniorMentoringResponse(doneMentoringInfos);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.postgraduate.domain.mentoring.application.dto.WaitingMentoringInfo;
import com.postgraduate.domain.mentoring.application.dto.res.AppliedMentoringDetailResponse;
import com.postgraduate.domain.mentoring.application.dto.res.AppliedMentoringResponse;
import com.postgraduate.domain.mentoring.application.mapper.MentoringMapper;
import com.postgraduate.domain.mentoring.domain.entity.Mentoring;
import com.postgraduate.domain.mentoring.domain.service.MentoringGetService;
import com.postgraduate.domain.mentoring.exception.MentoringDoneException;
Expand All @@ -13,7 +14,6 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

import static com.postgraduate.domain.mentoring.application.mapper.MentoringMapper.*;
Expand All @@ -36,28 +36,25 @@ public AppliedMentoringDetailResponse getMentoringDetail(User user, Long mentori

public AppliedMentoringResponse getWaiting(User user) {
List<Mentoring> mentorings = mentoringGetService.mentoringByUser(user, WAITING);
List<WaitingMentoringInfo> waitingMentoringInfos = new ArrayList<>();
for (Mentoring mentoring : mentorings) {
waitingMentoringInfos.add(mapToWaitingInfo(mentoring));
}
List<WaitingMentoringInfo> waitingMentoringInfos = mentorings.stream()
.map(MentoringMapper::mapToWaitingInfo)
.toList();
return new AppliedMentoringResponse(waitingMentoringInfos);
}

public AppliedMentoringResponse getExpected(User user) {
List<Mentoring> mentorings = mentoringGetService.mentoringByUser(user, EXPECTED);
List<ExpectedMentoringInfo> expectedMentoringInfos = new ArrayList<>();
for (Mentoring mentoring : mentorings) {
expectedMentoringInfos.add(mapToExpectedInfo(mentoring));
}
List<ExpectedMentoringInfo> expectedMentoringInfos = mentorings.stream()
.map(MentoringMapper::mapToExpectedInfo)
.toList();
return new AppliedMentoringResponse(expectedMentoringInfos);
}

public AppliedMentoringResponse getDone(User user) {
List<Mentoring> mentorings = mentoringGetService.mentoringByUser(user, DONE);
List<DoneMentoringInfo> doneMentoringInfos = new ArrayList<>();
for (Mentoring mentoring : mentorings) {
doneMentoringInfos.add(mapToDoneInfo(mentoring));
}
List<DoneMentoringInfo> doneMentoringInfos = mentorings.stream()
.map(MentoringMapper::mapToDoneInfo)
.toList();
return new AppliedMentoringResponse(doneMentoringInfos);
}
}
Loading

0 comments on commit 4719624

Please sign in to comment.