Skip to content

Commit

Permalink
Merge pull request #32 from LearnMate-Dev/chore/#31
Browse files Browse the repository at this point in the history
[Chore/#31] accessToken 반환 방식 수정
  • Loading branch information
daeun084 authored Dec 3, 2024
2 parents e1b2a44 + e50a996 commit ed5a5ab
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 7 deletions.
9 changes: 4 additions & 5 deletions src/main/java/LearnMate/dev/controller/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
import LearnMate.dev.model.dto.request.UserSignInRequest;
import LearnMate.dev.model.dto.request.UserSignUpRequest;
import LearnMate.dev.model.dto.response.HomeResponse;
import LearnMate.dev.model.dto.response.UserSignInResponse;
import LearnMate.dev.model.dto.response.TokenDto;
import LearnMate.dev.service.UserService;
import com.google.protobuf.Api;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import jakarta.validation.Valid;
Expand All @@ -28,9 +27,9 @@ public ApiResponse<String> signUp(@RequestBody @Valid UserSignUpRequest request)
}

@PostMapping("/signIn")
public ApiResponse<String> signIn(@RequestBody @Valid UserSignInRequest request,
HttpServletResponse response,
HttpSession session) {
public ApiResponse<TokenDto> signIn(@RequestBody @Valid UserSignInRequest request,
HttpServletResponse response,
HttpSession session) {

return ApiResponse.onSuccessData("로그인 성공", userService.signIn(request, response, session));

Expand Down
11 changes: 11 additions & 0 deletions src/main/java/LearnMate/dev/model/converter/TokenConverter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package LearnMate.dev.model.converter;

import LearnMate.dev.model.dto.response.TokenDto;

public class TokenConverter {
public static TokenDto toToken(String token) {
return TokenDto.builder()
.accessToken(token)
.build();
}
}
14 changes: 14 additions & 0 deletions src/main/java/LearnMate/dev/model/dto/response/TokenDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package LearnMate.dev.model.dto.response;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class TokenDto {
private String accessToken;
}
6 changes: 4 additions & 2 deletions src/main/java/LearnMate/dev/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import LearnMate.dev.common.exception.ApiException;
import LearnMate.dev.common.ErrorStatus;
import LearnMate.dev.model.converter.HomeConverter;
import LearnMate.dev.model.converter.TokenConverter;
import LearnMate.dev.model.dto.request.UserSignInRequest;
import LearnMate.dev.model.dto.request.UserSignUpRequest;
import LearnMate.dev.model.dto.response.HomeResponse;
import LearnMate.dev.model.dto.response.TokenDto;
import LearnMate.dev.model.entity.Diary;
import LearnMate.dev.model.entity.Plan;
import LearnMate.dev.model.entity.User;
Expand Down Expand Up @@ -48,7 +50,7 @@ public String signUp(UserSignUpRequest request) {
return "회원가입 성공";
}

public String signIn(UserSignInRequest request, HttpServletResponse response, HttpSession session) {
public TokenDto signIn(UserSignInRequest request, HttpServletResponse response, HttpSession session) {

User user = findUserByLoginId(request.getLoginId());
validPassword(request.getPassword(), user.getPassword());
Expand All @@ -59,7 +61,7 @@ public String signIn(UserSignInRequest request, HttpServletResponse response, Ht
// RefreshToken 발급 및 세션에 저장
jwtProvider.storeRefreshTokenInSession(user, session);

return "accessToken: " + accessToken;
return TokenConverter.toToken(accessToken);

}

Expand Down

0 comments on commit ed5a5ab

Please sign in to comment.