Skip to content

Commit

Permalink
Merge pull request #87 from onetime-with-members/feature/#81/refactor…
Browse files Browse the repository at this point in the history
…-error

[feat] : 유효성 검증 및 에러 처리를 추가한다
  • Loading branch information
bbbang105 authored Oct 21, 2024
2 parents 54d3770 + 0aecfd8 commit a83aa5d
Show file tree
Hide file tree
Showing 32 changed files with 295 additions and 307 deletions.
3 changes: 2 additions & 1 deletion src/main/java/side/onetime/controller/EventController.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package side.onetime.controller;

import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
Expand All @@ -20,7 +21,7 @@ public class EventController {
// 이벤트 생성 API
@PostMapping
public ResponseEntity<ApiResponse<CreateEventResponse>> createEvent(
@RequestBody CreateEventRequest createEventRequest,
@Valid @RequestBody CreateEventRequest createEventRequest,
@RequestHeader(value = "Authorization", required = false) String authorizationHeader) {

CreateEventResponse createEventResponse;
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/side/onetime/controller/MemberController.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package side.onetime.controller;

import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
Expand All @@ -25,7 +26,7 @@ public class MemberController {
// 멤버 등록 API
@PostMapping("/action-register")
public ResponseEntity<ApiResponse<RegisterMemberResponse>> registerMember(
@RequestBody RegisterMemberRequest registerMemberRequest) {
@Valid @RequestBody RegisterMemberRequest registerMemberRequest) {

RegisterMemberResponse registerMemberResponse = memberService.registerMember(registerMemberRequest);
return ApiResponse.onSuccess(SuccessStatus._REGISTER_MEMBER, registerMemberResponse);
Expand All @@ -34,7 +35,7 @@ public ResponseEntity<ApiResponse<RegisterMemberResponse>> registerMember(
// 멤버 로그인 API
@PostMapping("/action-login")
public ResponseEntity<ApiResponse<LoginMemberResponse>> loginMember(
@RequestBody LoginMemberRequest loginMemberRequest) {
@Valid @RequestBody LoginMemberRequest loginMemberRequest) {

LoginMemberResponse loginMemberResponse = memberService.loginMember(loginMemberRequest);
return ApiResponse.onSuccess(SuccessStatus._LOGIN_MEMBER, loginMemberResponse);
Expand All @@ -43,7 +44,7 @@ public ResponseEntity<ApiResponse<LoginMemberResponse>> loginMember(
// 이름 중복 확인 API
@PostMapping("/name/action-check")
public ResponseEntity<ApiResponse<IsDuplicateResponse>> isDuplicate(
@RequestBody IsDuplicateRequest isDuplicateRequest) {
@Valid @RequestBody IsDuplicateRequest isDuplicateRequest) {

IsDuplicateResponse isDuplicateResponse = memberService.isDuplicate(isDuplicateRequest);
return ApiResponse.onSuccess(SuccessStatus._IS_POSSIBLE_NAME, isDuplicateResponse);
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/side/onetime/controller/ScheduleController.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package side.onetime.controller;

import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
Expand All @@ -23,7 +24,7 @@ public class ScheduleController {
// 요일 스케줄 등록 API
@PostMapping("/day")
public ResponseEntity<ApiResponse<SuccessStatus>> createDaySchedules(
@RequestBody CreateDayScheduleRequest createDayScheduleRequest,
@Valid @RequestBody CreateDayScheduleRequest createDayScheduleRequest,
@RequestHeader(value = "Authorization", required = false) String authorizationHeader) {

if (authorizationHeader != null) {
Expand All @@ -37,7 +38,7 @@ public ResponseEntity<ApiResponse<SuccessStatus>> createDaySchedules(
// 날짜 스케줄 등록 API
@PostMapping("/date")
public ResponseEntity<ApiResponse<SuccessStatus>> createDateSchedules(
@RequestBody CreateDateScheduleRequest createDateScheduleRequest,
@Valid @RequestBody CreateDateScheduleRequest createDateScheduleRequest,
@RequestHeader(value = "Authorization", required = false) String authorizationHeader) {

if (authorizationHeader != null) {
Expand Down Expand Up @@ -80,7 +81,7 @@ public ResponseEntity<ApiResponse<PerDaySchedulesResponse>> getUserDaySchedules(
// 멤버 필터링 요일 스케줄 조회 API
@GetMapping("/day/action-filtering")
public ResponseEntity<ApiResponse<List<PerDaySchedulesResponse>>> getFilteredDaySchedules(
@RequestBody GetFilteredSchedulesRequest getFilteredSchedulesRequest) {
@Valid @RequestBody GetFilteredSchedulesRequest getFilteredSchedulesRequest) {

List<PerDaySchedulesResponse> perDaySchedulesResponses = scheduleService.getFilteredDaySchedules(getFilteredSchedulesRequest);
return ApiResponse.onSuccess(SuccessStatus._GET_FILTERED_DAY_SCHEDULES, perDaySchedulesResponses);
Expand Down Expand Up @@ -118,7 +119,7 @@ public ResponseEntity<ApiResponse<PerDateSchedulesResponse>> getUserDateSchedule
// 멤버 필터링 날짜 스케줄 조회 API
@GetMapping("/date/action-filtering")
public ResponseEntity<ApiResponse<List<PerDateSchedulesResponse>>> getFilteredDateSchedules(
@RequestBody GetFilteredSchedulesRequest getFilteredSchedulesRequest) {
@Valid @RequestBody GetFilteredSchedulesRequest getFilteredSchedulesRequest) {

List<PerDateSchedulesResponse> perDateSchedulesResponses = scheduleService.getFilteredDateSchedules(getFilteredSchedulesRequest);
return ApiResponse.onSuccess(SuccessStatus._GET_FILTERED_DATE_SCHEDULES, perDateSchedulesResponses);
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/side/onetime/controller/TokenController.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package side.onetime.controller;

import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
Expand All @@ -21,7 +22,7 @@ public class TokenController {
// 액세스 토큰 재발행 API
@PostMapping("/action-reissue")
public ResponseEntity<ApiResponse<ReissueTokenResponse>> reissueToken(
@RequestBody ReissueTokenRequest reissueAccessTokenRequest) {
@Valid @RequestBody ReissueTokenRequest reissueAccessTokenRequest) {

ReissueTokenResponse reissueTokenResponse = tokenService.reissueToken(reissueAccessTokenRequest);
return ApiResponse.onSuccess(SuccessStatus._REISSUE_TOKENS, reissueTokenResponse);
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/side/onetime/controller/UrlController.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package side.onetime.controller;

import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
Expand All @@ -23,7 +24,7 @@ public class UrlController {
// 원본 -> 단축 URL API
@PostMapping("/action-shorten")
public ResponseEntity<ApiResponse<ConvertToShortenUrlResponse>> convertToShortenUrl(
@RequestBody ConvertToShortenUrlRequest covertToShortenUrlRequest) {
@Valid @RequestBody ConvertToShortenUrlRequest covertToShortenUrlRequest) {

ConvertToShortenUrlResponse convertToShortenUrlResponse = urlService.convertToShortenUrl(covertToShortenUrlRequest);
return ApiResponse.onSuccess(SuccessStatus._CONVERT_TO_SHORTEN_URL, convertToShortenUrlResponse);
Expand All @@ -32,7 +33,7 @@ public ResponseEntity<ApiResponse<ConvertToShortenUrlResponse>> convertToShorten
// 단축 -> 원본 URL API
@PostMapping("/action-original")
public ResponseEntity<ApiResponse<ConvertToOriginalUrlResponse>> convertToOriginalUrl(
@RequestBody ConvertToOriginalUrlRequest convertToOriginalUrlRequest) {
@Valid @RequestBody ConvertToOriginalUrlRequest convertToOriginalUrlRequest) {

ConvertToOriginalUrlResponse convertToOriginalUrlResponse = urlService.convertToOriginalUrl(convertToOriginalUrlRequest);
return ApiResponse.onSuccess(SuccessStatus._CONVERT_TO_ORIGINAL_URL, convertToOriginalUrlResponse);
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/side/onetime/controller/UserController.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package side.onetime.controller;

import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
Expand All @@ -20,7 +21,7 @@ public class UserController {
// 유저 온보딩 API
@PostMapping("/onboarding")
public ResponseEntity<ApiResponse<OnboardUserResponse>> onboardUser(
@RequestBody OnboardUserRequest onboardUserRequest) {
@Valid @RequestBody OnboardUserRequest onboardUserRequest) {

OnboardUserResponse onboardUserResponse = userService.onboardUser(onboardUserRequest);
return ApiResponse.onSuccess(SuccessStatus._ONBOARD_USER, onboardUserResponse);
Expand All @@ -39,7 +40,7 @@ public ResponseEntity<ApiResponse<GetUserProfileResponse>> getUserProfile(
@PatchMapping("/profile/action-update")
public ResponseEntity<ApiResponse<SuccessStatus>> updateUserProfile(
@RequestHeader("Authorization") String authorizationHeader,
@RequestBody UpdateUserProfileRequest updateUserProfileRequest) {
@Valid @RequestBody UpdateUserProfileRequest updateUserProfileRequest) {

userService.updateUserProfile(authorizationHeader, updateUserProfileRequest);
return ApiResponse.onSuccess(SuccessStatus._UPDATE_USER_PROFILE);
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/side/onetime/exception/CustomException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package side.onetime.exception;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import side.onetime.global.common.code.BaseErrorCode;

@Getter
@RequiredArgsConstructor
public class CustomException extends RuntimeException {
private final BaseErrorCode errorCode;

@Override
public String getMessage() {
return errorCode.getReasonHttpStatus().getMessage();
}

public String getCode() {
return errorCode.getReasonHttpStatus().getCode();
}

public HttpStatus getHttpStatus() {
return errorCode.getReasonHttpStatus().getHttpStatus();
}
}
15 changes: 0 additions & 15 deletions src/main/java/side/onetime/exception/EventException.java

This file was deleted.

This file was deleted.

Loading

0 comments on commit a83aa5d

Please sign in to comment.