Skip to content

Commit

Permalink
feat : Api 공통 응답 추가
Browse files Browse the repository at this point in the history
- Api 공통 응답 추가
  • Loading branch information
seokho-1116 committed Jan 17, 2024
1 parent 39c0d02 commit aed2949
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import site.timecapsulearchive.core.domain.auth.dto.response.OAuthUrlResponse;
import site.timecapsulearchive.core.domain.auth.dto.response.TemporaryTokenResponse;
import site.timecapsulearchive.core.domain.auth.dto.response.TokenResponse;
import site.timecapsulearchive.core.global.common.response.ApiSpec;

public interface AuthApi {

Expand Down Expand Up @@ -111,18 +112,14 @@ public interface AuthApi {
@ApiResponses(value = {
@ApiResponse(
responseCode = "200",
description = "ok",
content = @Content(
mediaType = "application/json",
schema = @Schema(implementation = TemporaryTokenResponse.class)
)
description = "ok"
)
})
@GetMapping(
value = "/sign-up",
produces = {"application/json"}
)
ResponseEntity<TemporaryTokenResponse> signUpWithSocialProvider(SignUpRequest request);
ResponseEntity<ApiSpec<TemporaryTokenResponse>> signUpWithSocialProvider(SignUpRequest request);

@Operation(
summary = "액세스 토큰 재발급",
Expand All @@ -132,19 +129,15 @@ public interface AuthApi {
@ApiResponses(value = {
@ApiResponse(
responseCode = "200",
description = "ok",
content = @Content(
mediaType = "application/json",
schema = @Schema(implementation = TokenResponse.class)
)
description = "ok"
)
})
@PostMapping(
value = "/token/re-issue",
produces = {"application/json"},
consumes = {"application/json"}
)
ResponseEntity<TokenResponse> reIssueAccessToken(TokenReIssueRequest request);
ResponseEntity<ApiSpec<TokenResponse>> reIssueAccessToken(TokenReIssueRequest request);


@Operation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import site.timecapsulearchive.core.domain.auth.service.TokenService;
import site.timecapsulearchive.core.domain.member.dto.mapper.MemberMapper;
import site.timecapsulearchive.core.domain.member.service.MemberService;
import site.timecapsulearchive.core.global.common.response.ApiSpec;
import site.timecapsulearchive.core.global.common.response.SuccessCode;

@RestController
@RequiredArgsConstructor
Expand Down Expand Up @@ -45,17 +47,29 @@ public ResponseEntity<TemporaryTokenResponse> getTemporaryTokenResponseByGoogle(
}

@Override
public ResponseEntity<TokenResponse> reIssueAccessToken(
@Valid @RequestBody final TokenReIssueRequest request) {
return ResponseEntity.ok(tokenService.reIssueToken(request.refreshToken()));
public ResponseEntity<ApiSpec<TokenResponse>> reIssueAccessToken(
@Valid @RequestBody final TokenReIssueRequest request
) {
return ResponseEntity.ok(
ApiSpec.success(
SuccessCode.SUCCESS,
tokenService.reIssueToken(request.refreshToken())
)
);
}

@Override
public ResponseEntity<TemporaryTokenResponse> signUpWithSocialProvider(
@RequestBody final SignUpRequest request) {
public ResponseEntity<ApiSpec<TemporaryTokenResponse>> signUpWithSocialProvider(
@RequestBody final SignUpRequest request
) {
Long id = memberService.createMember(memberMapper.signUpRequestToEntity(request));

return ResponseEntity.ok(tokenService.createTemporaryToken(id));
return ResponseEntity.ok(
ApiSpec.success(
SuccessCode.SUCCESS,
tokenService.createTemporaryToken(id)
)
);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import org.springframework.validation.annotation.Validated;

@Schema(description = "임시 인증 토큰")
@Validated
public record TemporaryTokenResponse(

@Schema(description = "임시 액세스 토큰")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import org.springframework.validation.annotation.Validated;

@Schema(description = "완전한 인증 토큰")
@Validated
public record TokenResponse(

@Schema(description = "액세스 토큰")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import site.timecapsulearchive.core.domain.member.dto.reqeust.MemberDetailUpdateRequest;
import site.timecapsulearchive.core.domain.member.dto.response.MemberDetailResponse;
import site.timecapsulearchive.core.domain.member.dto.response.MemberStatusResponse;
import site.timecapsulearchive.core.global.common.response.ApiSpec;

public interface MemberApi {

Expand Down Expand Up @@ -65,17 +66,13 @@ public interface MemberApi {
@ApiResponses(value = {
@ApiResponse(
responseCode = "200",
description = "ok",
content = @Content(
mediaType = "application/json",
schema = @Schema(implementation = MemberStatusResponse.class)
)
description = "ok"
)
})
@GetMapping(
value = "/me/status",
produces = {"application/json"}
)
ResponseEntity<MemberStatusResponse> checkStatus(
ResponseEntity<ApiSpec<MemberStatusResponse>> checkStatus(
CheckStatusRequest request);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import site.timecapsulearchive.core.domain.member.dto.response.MemberDetailResponse;
import site.timecapsulearchive.core.domain.member.dto.response.MemberStatusResponse;
import site.timecapsulearchive.core.domain.member.service.MemberService;
import site.timecapsulearchive.core.global.common.response.ApiSpec;
import site.timecapsulearchive.core.global.common.response.SuccessCode;

@RestController
@RequiredArgsConstructor
Expand All @@ -30,12 +32,17 @@ public ResponseEntity<Void> updateMemberById(MemberDetailUpdateRequest request)
}

@Override
public ResponseEntity<MemberStatusResponse> checkStatus(
public ResponseEntity<ApiSpec<MemberStatusResponse>> checkStatus(
@Valid @RequestBody CheckStatusRequest request
) {
return ResponseEntity.ok(memberService.checkStatus(
request.authId(),
request.socialType())
return ResponseEntity.ok(
ApiSpec.success(
SuccessCode.SUCCESS,
memberService.checkStatus(
request.authId(),
request.socialType()
)
)
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package site.timecapsulearchive.core.global.common.response;

import io.swagger.v3.oas.annotations.media.Schema;

@Schema(description = "api 공통 응답 ")
public record ApiSpec<T>(

@Schema(description = "응답 코드")
String code,

@Schema(description = "응답 메시지")
String message,

@Schema(description = "응답 데이터")
T result
) {

public static <T> ApiSpec<T> empty(SuccessCode code) {
return new ApiSpec<>(code.getMessage(), code.getCode(), null);
}

public static <T> ApiSpec<T> success(SuccessCode code, T result) {
return new ApiSpec<>(code.getCode(), code.getMessage(), result);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package site.timecapsulearchive.core.global.common.response;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
public enum SuccessCode {
//success handle
SUCCESS("00", "요청 처리에 성공했습니다.");

private final String code;
private final String message;
}

0 comments on commit aed2949

Please sign in to comment.