Skip to content

Commit

Permalink
feat: Auth API에 Success Response 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
yeonjy committed Jun 30, 2024
1 parent e33a25e commit 7c4567d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public enum SuccessCode {
// statistics
GET_VIEWS_OF_DATE_SUCCESS(200, "최근 일주일 날짜별 뉴스 조회수 조회에 성공했습니다."),
GET_CATEGORY_VIEWS_SUCCESS(200, "카테고리별 조회수 조회에 성공했습니다."),

// auth
GET_SOCIAL_LOGIN_SUCCESS(201, "소셜 로그인에 성공했습니다."),
UPDATE_NICKNAME_SUCCESS(204, "닉네임 입력에 성공했습니다.")
;

private final int status;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.rollthedice.backend.global.oauth2.api;

import com.rollthedice.backend.domain.member.dto.MemberUpdateDto;
import com.rollthedice.backend.global.common.response.SuccessResponse;
import com.rollthedice.backend.global.oauth2.dto.LoginRequest;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
Expand All @@ -18,10 +19,10 @@ public interface AuthApi {
tags = {"인증"}
)
@ApiResponse(
responseCode = "201",
description = "Created"
responseCode = "200",
description = "소셜 로그인에 성공했습니다."
)
ResponseEntity<HttpStatus> login(
SuccessResponse<String> login(
@RequestBody LoginRequest request,
HttpServletResponse response
);
Expand All @@ -34,9 +35,9 @@ ResponseEntity<HttpStatus> login(
)
@ApiResponse(
responseCode = "201",
description = "Created"
description = "닉네임 입력에 성공했습니다."
)
ResponseEntity<HttpStatus> updateMember(
SuccessResponse<String> updateMember(
String email,
@RequestBody MemberUpdateDto memberUpdateDto
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.rollthedice.backend.domain.member.dto.MemberUpdateDto;
import com.rollthedice.backend.domain.member.service.MemberService;
import com.rollthedice.backend.global.annotation.LoginMemberEmail;
import com.rollthedice.backend.global.common.response.SuccessResponse;
import com.rollthedice.backend.global.oauth2.dto.LoginRequest;
import com.rollthedice.backend.global.oauth2.service.AuthService;
import jakarta.servlet.http.HttpServletResponse;
Expand All @@ -12,29 +13,33 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

import static com.rollthedice.backend.global.common.response.SuccessCode.GET_SOCIAL_LOGIN_SUCCESS;
import static com.rollthedice.backend.global.common.response.SuccessCode.UPDATE_NICKNAME_SUCCESS;

@Slf4j
@RestController
@RequiredArgsConstructor
public class AuthController implements AuthApi {
private final AuthService authService;
private final MemberService memberService;

@ResponseStatus(HttpStatus.OK)
@PostMapping("/login")
@Override
public ResponseEntity<HttpStatus> login(@RequestBody LoginRequest request, HttpServletResponse response) {
public SuccessResponse<String> login(@RequestBody LoginRequest request, HttpServletResponse response) {
authService.authenticateOrRegisterUser(request, response);
return new ResponseEntity<>(HttpStatus.OK);
return SuccessResponse.of(GET_SOCIAL_LOGIN_SUCCESS);
}

@PostMapping("/oauth2/sign-up")
@Override
public ResponseEntity<HttpStatus> updateMember(@LoginMemberEmail String email,
public SuccessResponse<String> updateMember(@LoginMemberEmail String email,
@RequestBody MemberUpdateDto memberUpdateDto) {
memberService.update(memberUpdateDto);

return ResponseEntity.status(HttpStatus.OK).build();
return SuccessResponse.of(UPDATE_NICKNAME_SUCCESS);
}

}

0 comments on commit 7c4567d

Please sign in to comment.