Skip to content

Commit

Permalink
Merge pull request #41 from MAKAR-iOS/chore/#40
Browse files Browse the repository at this point in the history
[Chore/#40] API URI 통일
  • Loading branch information
daeun084 authored Jul 29, 2024
2 parents db6fd60 + 23f0e07 commit a7e721d
Show file tree
Hide file tree
Showing 12 changed files with 101 additions and 95 deletions.
15 changes: 7 additions & 8 deletions src/main/java/makar/dev/controller/AuthController.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
import lombok.RequiredArgsConstructor;
import makar.dev.common.response.ApiResponse;
import makar.dev.common.status.SuccessStatus;
import makar.dev.dto.request.SignInRequest;
import makar.dev.dto.request.SignUpRequest;
import makar.dev.dto.response.SignResponse;
import makar.dev.dto.request.AuthRequest;
import makar.dev.dto.response.AuthResponse;
import makar.dev.service.AuthService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
Expand All @@ -15,7 +14,7 @@

@RequiredArgsConstructor
@RestController
@RequestMapping("/auth")
@RequestMapping("/api/v1/auth")
public class AuthController {
private final AuthService authService;

Expand All @@ -24,8 +23,8 @@ public class AuthController {
description = "회원가입 후 토큰을 반환합니다."
)
@PostMapping("/sign-up")
public ApiResponse<SignResponse> signUp(@RequestBody SignUpRequest request) {
SignResponse response = authService.signUp(request);
public ApiResponse<AuthResponse.SignDto> signUp(@RequestBody AuthRequest.SignUpRequest request) {
AuthResponse.SignDto response = authService.signUp(request);

return ApiResponse.SuccessResponse(SuccessStatus._OK, response);
}
Expand All @@ -35,8 +34,8 @@ public ApiResponse<SignResponse> signUp(@RequestBody SignUpRequest request) {
description = "로그인 후 토큰을 반환합니다."
)
@PostMapping("/sign-in")
public ApiResponse<SignResponse> signIn(@RequestBody SignInRequest request) {
SignResponse response = authService.signIn(request.getId(), request.getPassword());
public ApiResponse<AuthResponse.SignDto> signIn(@RequestBody AuthRequest.SignInRequest request) {
AuthResponse.SignDto response = authService.signIn(request.getId(), request.getPassword());

return ApiResponse.SuccessResponse(SuccessStatus._OK, response);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/makar/dev/controller/NotiController.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

@RequiredArgsConstructor
@RestController
@RequestMapping("/noti")
@RequestMapping("/api/v1/noti")
public class NotiController {
private final NotiService notiService;

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

import makar.dev.common.security.dto.AuthTokenDto;
import makar.dev.dto.response.AuthResponse;

public class AuthConverter {
public static AuthResponse.SignDto toSignDto(AuthTokenDto accessToken, AuthTokenDto refreshToken){
return AuthResponse.SignDto.builder()
.accessToken(accessToken)
.refreshToken(refreshToken)
.build();
}
}
10 changes: 10 additions & 0 deletions src/main/java/makar/dev/converter/UserConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import makar.dev.domain.Noti;
import makar.dev.domain.Route;
import makar.dev.domain.User;
import makar.dev.dto.response.NotiResponse;
import makar.dev.dto.response.RouteResponse;
import makar.dev.dto.response.UserResponse;
Expand Down Expand Up @@ -46,4 +47,13 @@ public static UserResponse.HomeDto toHomeDto(boolean isRouteSet, List<Noti> noti
.recentRouteList(recentRouteDtoList)
.build();
}

public static User toUser(String id, String password, String email, String username){
return User.builder()
.id(id)
.password(password)
.email(email)
.username(username)
.build();
}
}
43 changes: 43 additions & 0 deletions src/main/java/makar/dev/dto/request/AuthRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package makar.dev.dto.request;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

public class AuthRequest {
@Data
@AllArgsConstructor
@NoArgsConstructor
public static class SignInRequest {
@NotBlank
@Schema(description = "아이디")
private String id;

@NotBlank
@Schema(description = "비밀번호")
private String password;
}

@Data
@AllArgsConstructor
@NoArgsConstructor
public static class SignUpRequest {
@NotBlank
@Schema(description = "아이디")
private String id;

@NotBlank
@Schema(description = "비밀번호")
private String password;

@NotBlank
@Schema(description = "이메일")
private String email;

@NotBlank
@Schema(description = "닉네임")
private String username;
}
}
20 changes: 0 additions & 20 deletions src/main/java/makar/dev/dto/request/SignInRequest.java

This file was deleted.

26 changes: 0 additions & 26 deletions src/main/java/makar/dev/dto/request/SignUpRequest.java

This file was deleted.

4 changes: 0 additions & 4 deletions src/main/java/makar/dev/dto/request/UserRequest.java

This file was deleted.

19 changes: 19 additions & 0 deletions src/main/java/makar/dev/dto/response/AuthResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package makar.dev.dto.response;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import makar.dev.common.security.dto.AuthTokenDto;

public class AuthResponse {

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public static class SignDto {
private AuthTokenDto accessToken;
private AuthTokenDto refreshToken;
}
}
23 changes: 0 additions & 23 deletions src/main/java/makar/dev/dto/response/SignResponse.java

This file was deleted.

13 changes: 7 additions & 6 deletions src/main/java/makar/dev/service/AuthService.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
import makar.dev.common.security.dto.AuthTokenDto;
import makar.dev.common.security.jwt.JwtService;
import makar.dev.common.util.PasswordEncoder;
import makar.dev.dto.request.SignUpRequest;
import makar.dev.dto.response.SignResponse;
import makar.dev.converter.AuthConverter;
import makar.dev.dto.request.AuthRequest;
import makar.dev.dto.response.AuthResponse;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import makar.dev.domain.User;
Expand All @@ -20,7 +21,7 @@ public class AuthService {
private final PasswordEncoder passwordEncoder;

@Transactional
public SignResponse signUp(SignUpRequest request) {
public AuthResponse.SignDto signUp(AuthRequest.SignUpRequest request) {
Optional<User> existingUser = userService.getOptionalUserById(request.getId());

if (existingUser.isPresent()) {
Expand All @@ -35,10 +36,10 @@ public SignResponse signUp(SignUpRequest request) {

user.setRefreshToken(refreshToken.getToken());

return SignResponse.of(accessToken, refreshToken);
return AuthConverter.toSignDto(accessToken, refreshToken);
}

public SignResponse signIn(String id, String password) {
public AuthResponse.SignDto signIn(String id, String password) {
User user = userService.getOptionalUserById(id)
.orElseThrow(() -> new IllegalArgumentException("가입되지 않은 아이디입니다."));

Expand All @@ -51,6 +52,6 @@ public SignResponse signIn(String id, String password) {

user.setRefreshToken(refreshToken.getToken());

return SignResponse.of(accessToken, refreshToken);
return AuthConverter.toSignDto(accessToken, refreshToken);
}
}
8 changes: 1 addition & 7 deletions src/main/java/makar/dev/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,7 @@ public Optional<User> getOptionalUserById(String id) {

@Transactional
public User createUser(String id, String password, String email, String username) {
User user = User.builder()
.id(id)
.password(password)
.email(email)
.username(username)
.build();

User user = UserConverter.toUser(id, password, email, username);
user = userRepository.save(user);

return user;
Expand Down

0 comments on commit a7e721d

Please sign in to comment.