Skip to content

Commit

Permalink
Merge pull request #26 from HongDam-org/feat/login-fix
Browse files Browse the repository at this point in the history
[FEAT] TMAP-API 수정 + login 작업 수정
  • Loading branch information
jinjoo-lab authored Sep 26, 2023
2 parents 70dcc26 + 4bd6342 commit de1b076
Show file tree
Hide file tree
Showing 14 changed files with 65 additions and 105 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.twtw.backend.config.mapper;
package com.twtw.backend.config.web;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.twtw.backend.domain.member.dto.request.MemberSaveRequest;
import com.twtw.backend.domain.member.dto.request.OAuthRequest;
import com.twtw.backend.domain.member.dto.request.TokenRequest;
import com.twtw.backend.domain.member.dto.response.AfterLoginDto;
import com.twtw.backend.domain.member.dto.response.TokenDto;
import com.twtw.backend.domain.member.service.AuthService;

Expand All @@ -27,20 +28,15 @@ public ResponseEntity<TokenDto> authorize(@RequestBody TokenRequest tokenRequest
}

@PostMapping("/save")
public ResponseEntity<TokenDto> saveMember(@RequestBody MemberSaveRequest memberSaveRequest) {
TokenDto tokenDto = authService.saveMember(memberSaveRequest);
public ResponseEntity<AfterLoginDto> saveMember(
@RequestBody MemberSaveRequest memberSaveRequest) {
AfterLoginDto tokenDto = authService.saveMember(memberSaveRequest);

return ResponseEntity.status(HttpStatus.OK).body(tokenDto);
}

@PostMapping("/login")
public ResponseEntity<TokenDto> afterSocialLogin(@RequestBody OAuthRequest request) {
TokenDto tokenDto = authService.getTokenByOAuth(request);

if (tokenDto == null) {
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(tokenDto);
} else {
return ResponseEntity.status(HttpStatus.OK).body(tokenDto);
}
public ResponseEntity<AfterLoginDto> afterSocialLogin(@RequestBody OAuthRequest request) {
return ResponseEntity.status(HttpStatus.OK).body(authService.getTokenByOAuth(request));
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.twtw.backend.domain.member.dto.request;

import com.twtw.backend.domain.member.entity.Role;

import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;

import lombok.AllArgsConstructor;
import lombok.Getter;
Expand All @@ -17,10 +14,5 @@ public class MemberSaveRequest {

private String profileImage;

private String phoneNumber;

@Enumerated(EnumType.STRING)
private Role role;

private OAuthRequest oauthRequest;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.twtw.backend.domain.member.dto.response;

import com.twtw.backend.domain.member.entity.AuthStatus;

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

@Getter
@NoArgsConstructor
@AllArgsConstructor
public class AfterLoginDto {
private AuthStatus status;
private TokenDto tokenDto;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.twtw.backend.domain.member.entity;

public enum AuthStatus {
SU,
SI
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,15 @@ public class Member {

private String profileImage;

private String phoneNumber;

@Enumerated(EnumType.STRING)
private Role role;

@Embedded private OAuth2Info oAuth2Info;

public Member(String nickname, String profileImage, String phoneNumber, Role role) {
public Member(String nickname, String profileImage) {
this.nickname = nickname;
this.profileImage = profileImage;
this.phoneNumber = phoneNumber;
this.role = role;
this.role = Role.ROLE_USER;
}

public void updateOAuth(OAuth2Info oAuth2Info) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@
public class MemberMapper {

public Member toMemberEntity(MemberSaveRequest request) {
Member member =
new Member(
request.getNickname(),
request.getProfileImage(),
request.getPhoneNumber(),
request.getRole());
Member member = new Member(request.getNickname(), request.getProfileImage());
return member;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import com.twtw.backend.config.security.jwt.TokenProvider;
import com.twtw.backend.domain.member.dto.request.MemberSaveRequest;
import com.twtw.backend.domain.member.dto.request.OAuthRequest;
import com.twtw.backend.domain.member.dto.response.AfterLoginDto;
import com.twtw.backend.domain.member.dto.response.TokenDto;
import com.twtw.backend.domain.member.entity.AuthStatus;
import com.twtw.backend.domain.member.entity.Member;
import com.twtw.backend.domain.member.entity.RefreshToken;
import com.twtw.backend.domain.member.mapper.MemberMapper;
Expand Down Expand Up @@ -44,7 +46,7 @@ public AuthService(
* */

@Transactional
public TokenDto saveMember(MemberSaveRequest request) {
public AfterLoginDto saveMember(MemberSaveRequest request) {
Member member = memberMapper.toMemberEntity(request);

String clientId = request.getOauthRequest().getToken();
Expand All @@ -56,15 +58,15 @@ public TokenDto saveMember(MemberSaveRequest request) {
UsernamePasswordAuthenticationToken credit = tokenProvider.makeCredit(member);
TokenDto tokenDto = saveRefreshToken(credit, member.getId().toString());

return tokenDto;
return new AfterLoginDto(AuthStatus.SI, tokenDto);
}

/*
* 1.로그인(Social) 후의 토큰 발급
* 2.JWT 토큰 발급 -> OAuth 정보 (clientId , AuthType)으로 진행
*
* */
public TokenDto getTokenByOAuth(OAuthRequest request) {
public AfterLoginDto getTokenByOAuth(OAuthRequest request) {
String clientId = request.getToken();

Optional<Member> member =
Expand All @@ -74,10 +76,10 @@ public TokenDto getTokenByOAuth(OAuthRequest request) {
Member curMember = member.get();
UsernamePasswordAuthenticationToken credit = tokenProvider.makeCredit(curMember);
TokenDto tokenDto = saveRefreshToken(credit, curMember.getId().toString());
return tokenDto;
return new AfterLoginDto(AuthStatus.SI, tokenDto);
}

return null;
return new AfterLoginDto(AuthStatus.SU, null);
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public SearchPedPathResponse request(SearchPedPathRequest request) {
.uri(uri -> getPathUri(uri))
.accept(MediaType.APPLICATION_JSON)
.acceptCharset(StandardCharsets.UTF_8)
.header("appKey", tmapProperties.getAppKey())
.bodyValue(request)
.retrieve()
.bodyToMono(SearchPedPathResponse.class)
Expand All @@ -40,8 +39,7 @@ public SearchPedPathResponse request(SearchPedPathRequest request) {
}

private URI getPathUri(final UriBuilder uriBuilder) {
final UriBuilder builder = uriBuilder.queryParam("version", 1);

final UriBuilder builder = uriBuilder.queryParam("version", 1.1);
return builder.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.twtw.backend.domain.path.dto.client.ped;

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

@Getter
@NoArgsConstructor
@AllArgsConstructor
public class Feature {
private String type;
private Geometry geometry;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
@AllArgsConstructor
public class SearchPedPathResponse {
private String type;
private List<Geometry> geometry;
private List<Feature> features;
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
import com.twtw.backend.domain.member.dto.request.MemberSaveRequest;
import com.twtw.backend.domain.member.dto.request.OAuthRequest;
import com.twtw.backend.domain.member.dto.request.TokenRequest;
import com.twtw.backend.domain.member.dto.response.AfterLoginDto;
import com.twtw.backend.domain.member.dto.response.TokenDto;
import com.twtw.backend.domain.member.entity.AuthStatus;
import com.twtw.backend.domain.member.entity.AuthType;
import com.twtw.backend.domain.member.entity.Role;
import com.twtw.backend.domain.member.service.AuthService;
Expand Down Expand Up @@ -64,7 +66,9 @@ void authorize() throws Exception {
@DisplayName("첫 로그인 API가 수행되는가")
void saveMember() throws Exception {
// given
final TokenDto expected = new TokenDto("access.token.value", "refresh.token.value");
final AfterLoginDto expected =
new AfterLoginDto(
AuthStatus.SI, new TokenDto("access.token.value", "refresh.token.value"));
given(authService.saveMember(any())).willReturn(expected);

// when
Expand All @@ -84,8 +88,8 @@ void saveMember() throws Exception {

// then
perform.andExpect(status().isOk())
.andExpect(jsonPath("$.accessToken").isString())
.andExpect(jsonPath("$.refreshToken").isString());
.andExpect(jsonPath("$.tokenDto.accessToken").isString())
.andExpect(jsonPath("$.tokenDto.refreshToken").isString());

// docs
perform.andDo(print())
Expand All @@ -96,7 +100,9 @@ void saveMember() throws Exception {
@DisplayName("멤버가 저장된 상태에서의 로그인 API가 수행되는가")
void afterSocialLogin() throws Exception {
// given
final TokenDto expected = new TokenDto("access.token.value", "refresh.token.value");
final AfterLoginDto expected =
new AfterLoginDto(
AuthStatus.SI, new TokenDto("access.token.value", "refresh.token.value"));
given(authService.getTokenByOAuth(any())).willReturn(expected);

// when
Expand All @@ -110,8 +116,8 @@ void afterSocialLogin() throws Exception {

// then
perform.andExpect(status().isOk())
.andExpect(jsonPath("$.accessToken").isString())
.andExpect(jsonPath("$.refreshToken").isString());
.andExpect(jsonPath("$.tokenDto.accessToken").isString())
.andExpect(jsonPath("$.tokenDto.refreshToken").isString());

// docs
perform.andDo(print())
Expand Down

0 comments on commit de1b076

Please sign in to comment.