Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT] TMAP-API 수정 + login 작업 수정 #26

Merged
merged 7 commits into from
Sep 26, 2023

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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이거 어떤 정보를 담는거야? 클래스명만 보면 기능 요론 느낌이라서 헷갈림

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아 이게 json 에 feature라 되있어서 .... 걍 클래스 명을 저렇게 함 구조가 보면 좌표하고 type이 같이 들어가 있는 Geometry 클래스를 한번더 type하고 감싼 걸 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