Skip to content

Commit

Permalink
Merge pull request #13 from Team-UMC/feature/#11/base_response_error_…
Browse files Browse the repository at this point in the history
…handler

[FEAT] API 응답 통일 & 에러 핸들러 설정
  • Loading branch information
junseokkim authored Jan 13, 2024
2 parents 667edd9 + 150f889 commit d6df8da
Show file tree
Hide file tree
Showing 40 changed files with 294 additions and 74 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ repositories {
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-validation'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'com.mysql:mysql-connector-j'
annotationProcessor 'org.projectlombok:lombok'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.umc.networkingService.domain.album.entity;

import com.umc.networkingService.domain.member.entity.Member;
import com.umc.networkingService.global.common.BaseEntity;
import com.umc.networkingService.global.common.base.BaseEntity;
import com.umc.networkingService.global.common.Semester;
import jakarta.persistence.*;
import lombok.AccessLevel;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.umc.networkingService.domain.album.entity;

import com.umc.networkingService.domain.member.entity.Member;
import com.umc.networkingService.global.common.BaseEntity;
import com.umc.networkingService.global.common.base.BaseEntity;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.umc.networkingService.domain.album.entity;

import com.umc.networkingService.domain.member.entity.Member;
import com.umc.networkingService.global.common.BaseEntity;
import com.umc.networkingService.global.common.base.BaseEntity;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.umc.networkingService.domain.album.entity;

import com.umc.networkingService.global.common.BaseEntity;
import com.umc.networkingService.global.common.base.BaseEntity;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.umc.networkingService.domain.board.entity;

import com.umc.networkingService.domain.member.entity.Member;
import com.umc.networkingService.global.common.BaseEntity;
import com.umc.networkingService.global.common.base.BaseEntity;
import com.umc.networkingService.global.common.Semester;
import jakarta.persistence.*;
import lombok.AccessLevel;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.umc.networkingService.domain.board.entity;

import com.umc.networkingService.domain.member.entity.Member;
import com.umc.networkingService.global.common.BaseEntity;
import com.umc.networkingService.global.common.base.BaseEntity;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


import com.umc.networkingService.domain.member.entity.Member;
import com.umc.networkingService.global.common.BaseEntity;
import com.umc.networkingService.global.common.base.BaseEntity;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


import com.umc.networkingService.domain.member.entity.Member;
import com.umc.networkingService.global.common.BaseEntity;
import com.umc.networkingService.global.common.base.BaseEntity;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.umc.networkingService.domain.board.entity;

import com.umc.networkingService.global.common.BaseEntity;
import com.umc.networkingService.global.common.base.BaseEntity;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.umc.networkingService.domain.branch.entity;

import com.umc.networkingService.global.common.BaseEntity;
import com.umc.networkingService.global.common.base.BaseEntity;
import com.umc.networkingService.global.common.Semester;
import jakarta.persistence.*;
import lombok.AccessLevel;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.umc.networkingService.domain.branch.entity;

import com.umc.networkingService.domain.university.entity.University;
import com.umc.networkingService.global.common.BaseEntity;
import com.umc.networkingService.global.common.base.BaseEntity;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.umc.networkingService.domain.friend.entity;

import com.umc.networkingService.domain.member.entity.Member;
import com.umc.networkingService.global.common.BaseEntity;
import jakarta.persistence.*;
import com.umc.networkingService.global.common.base.BaseEntity;

import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.umc.networkingService.domain.inviteCode.entity;

import com.umc.networkingService.domain.member.entity.Member;
import com.umc.networkingService.global.common.BaseEntity;
import com.umc.networkingService.global.common.base.BaseEntity;
import com.umc.networkingService.global.common.Role;
import jakarta.persistence.*;
import lombok.AccessLevel;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.umc.networkingService.domain.mascot.entity;

import com.umc.networkingService.global.common.BaseEntity;
import com.umc.networkingService.global.common.base.BaseEntity;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.umc.networkingService.domain.branch.entity.Branch;
import com.umc.networkingService.domain.university.entity.University;
import com.umc.networkingService.global.common.BaseEntity;
import com.umc.networkingService.global.common.base.BaseEntity;
import com.umc.networkingService.global.common.Part;
import com.umc.networkingService.global.common.Role;
import com.umc.networkingService.global.common.Semester;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.umc.networkingService.domain.member.entity;

import com.umc.networkingService.domain.university.entity.University;
import com.umc.networkingService.global.common.BaseEntity;
import com.umc.networkingService.global.common.base.BaseEntity;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.umc.networkingService.domain.message.entity;

import com.umc.networkingService.global.common.BaseEntity;
import com.umc.networkingService.global.common.base.BaseEntity;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.umc.networkingService.domain.message.entity;

import com.umc.networkingService.global.common.BaseEntity;
import com.umc.networkingService.global.common.base.BaseEntity;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.umc.networkingService.domain.project.entity;

import com.umc.networkingService.global.common.BaseEntity;
import com.umc.networkingService.global.common.base.BaseEntity;
import com.umc.networkingService.global.common.Semester;
import jakarta.persistence.*;
import lombok.AccessLevel;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.umc.networkingService.domain.project.entity;

import com.umc.networkingService.domain.member.entity.Member;
import com.umc.networkingService.global.common.BaseEntity;
import com.umc.networkingService.global.common.base.BaseEntity;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.umc.networkingService.domain.project.entity;

import com.umc.networkingService.domain.member.entity.Member;
import com.umc.networkingService.global.common.BaseEntity;
import com.umc.networkingService.global.common.base.BaseEntity;
import com.umc.networkingService.global.common.Part;
import jakarta.persistence.*;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.umc.networkingService.domain.proposal.entity;

import com.umc.networkingService.domain.member.entity.Member;
import com.umc.networkingService.global.common.BaseEntity;
import com.umc.networkingService.global.common.base.BaseEntity;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.umc.networkingService.domain.proposal.entity;

import com.umc.networkingService.global.common.BaseEntity;
import com.umc.networkingService.global.common.base.BaseEntity;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.umc.networkingService.domain.board.entity.HostType;
import com.umc.networkingService.domain.member.entity.Member;
import com.umc.networkingService.global.common.BaseEntity;
import com.umc.networkingService.global.common.base.BaseEntity;
import com.umc.networkingService.global.common.Semester;
import jakarta.persistence.*;
import lombok.AccessLevel;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.umc.networkingService.domain.session.entity;

import com.umc.networkingService.domain.member.entity.Member;
import com.umc.networkingService.global.common.BaseEntity;
import com.umc.networkingService.global.common.base.BaseEntity;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,60 @@
package com.umc.networkingService.domain.test.controller;

import com.umc.networkingService.domain.test.dto.TestRequest;
import com.umc.networkingService.domain.test.dto.TestResponse;
import com.umc.networkingService.domain.test.service.TestService;
import com.umc.networkingService.global.common.base.BaseResponse;
import io.swagger.v3.oas.annotations.Hidden;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

@Tag(name = "예제 API", description = "Swagger 테스트용 API")
@Tag(name = "예제 API", description = "테스트용 API")
@RestController
@RequiredArgsConstructor
@RequestMapping("/test")
public class TestController {
@Operation(summary = "문자열 반복", description = "파라미터로 받은 문자열을 2번 반복합니다.")
@Parameter(name = "str", description = "2번 반복할 문자열")
@GetMapping("/returnStr")
public String returnStr(@RequestParam String str) {
return str + "\n" + str;
private final TestService testService;


@Operation(summary = "성공적인 응답 반환 API", description = "테스트 문자열을 반환하는 API입니다.")
@ApiResponse(responseCode = "200", description = "테스트 문자열을 성공적으로 반환")
@GetMapping("/success")
public BaseResponse<TestResponse.TempTestDTO> successResponseAPI() {
return BaseResponse.onSuccess(TestResponse.TempTestDTO.builder().testString("This is Test!").build());
}

@GetMapping("/example")
public String example() {
return "예시 API";


@Operation(summary = "예외처리 API", description = "flag 값에 따라 예외를 발생시키는 API입니다.")
@Parameter(name = "flag", description = "1인 경우 예외처리", example = "1", required = true)
@ApiResponses(value = {
@ApiResponse(responseCode = "COMMON200", description = "성공"),
@ApiResponse(responseCode = "TEMP4001", description = "예외 처리 테스트입니다.")
})
@GetMapping("/exception")
public BaseResponse<TestResponse.TempExceptionDTO> exceptionAPI(@RequestParam Integer flag) {
testService.CheckFlag(flag);
return BaseResponse.onSuccess(TestResponse.TempExceptionDTO.builder()
.flag(flag)
.build());
}

@Hidden
@GetMapping("/ignore")
public String ignore() {
return "무시되는 API";
@Operation(summary = "유효성 검사 API", description = "요청 객체의 유효성을 검사하는 API입니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "COMMON200", description = "성공"),
@ApiResponse(responseCode = "COMMON400", description = "testString가 공백일 경우")
})
@PostMapping("/validation")
public BaseResponse<TestResponse.TempTestDTO> testValidationAPI(
@RequestBody @Valid TestRequest.TempTestRequest request) {
return BaseResponse.onSuccess(TestResponse.TempTestDTO.builder()
.testString(request.getTestString())
.build());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.umc.networkingService.domain.test.dto;

import jakarta.validation.constraints.NotBlank;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

public class TestRequest {

@Builder
@Getter
@NoArgsConstructor
@AllArgsConstructor
public static class TempTestRequest {
@NotBlank(message = "testString은 필수입니다.")
private String testString;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.umc.networkingService.domain.test.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

public class TestResponse {

@Builder
@Getter
@NoArgsConstructor
@AllArgsConstructor
public static class TempTestDTO {
String testString;
}

@Builder
@Getter
@NoArgsConstructor
@AllArgsConstructor
public static class TempExceptionDTO {
Integer flag;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.umc.networkingService.domain.test.service;

import com.umc.networkingService.global.common.exception.RestApiException;
import com.umc.networkingService.global.common.exception.ErrorCode;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class TestService {
public void CheckFlag(Integer flag) {
if (flag == 1)
throw new RestApiException(ErrorCode.TEMP_EXCEPTION);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.umc.networkingService.domain.todayILearned.entity;

import com.umc.networkingService.domain.member.entity.Member;
import com.umc.networkingService.global.common.BaseEntity;
import com.umc.networkingService.global.common.base.BaseEntity;
import com.umc.networkingService.global.common.Part;
import jakarta.persistence.*;
import lombok.AccessLevel;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.umc.networkingService.domain.todayILearned.entity;

import com.umc.networkingService.global.common.BaseEntity;
import com.umc.networkingService.global.common.base.BaseEntity;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.umc.networkingService.domain.todoList.entity;

import com.umc.networkingService.domain.member.entity.Member;
import com.umc.networkingService.global.common.BaseEntity;
import com.umc.networkingService.global.common.base.BaseEntity;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Getter;
Expand Down
Loading

0 comments on commit d6df8da

Please sign in to comment.