From f2e34fde019f042c8bbec3335470a72669be3c21 Mon Sep 17 00:00:00 2001 From: ssongmina Date: Mon, 19 Aug 2024 23:05:39 +0900 Subject: [PATCH] =?UTF-8?q?[STYLE]=20DayBudgetService=EC=97=90=20=EC=8A=A4?= =?UTF-8?q?=EC=9B=A8=EA=B1=B0=EC=9D=98=20ApiResponse=20=EC=84=A4=EB=AA=85?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../umc/haruchi/service/DayBudgetService.java | 4 +- .../web/controller/DayBudgetController.java | 43 +++++++++++++++++++ 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/src/main/java/umc/haruchi/service/DayBudgetService.java b/src/main/java/umc/haruchi/service/DayBudgetService.java index 77b643f..9cf3ec2 100644 --- a/src/main/java/umc/haruchi/service/DayBudgetService.java +++ b/src/main/java/umc/haruchi/service/DayBudgetService.java @@ -53,9 +53,7 @@ public MonthBudget check(Long memberId){ MonthBudget monthBudget = monthBudgetRepository.findByMemberIdAndYearAndMonth(memberId, year, month) .orElseThrow(() -> new MonthBudgetHandler(ErrorStatus.MONTH_BUDGET_NOT_FOUND)); - if(monthBudget == null){ - throw new MonthBudgetHandler(ErrorStatus.MONTH_BUDGET_NOT_FOUND); - } + return monthBudget; } diff --git a/src/main/java/umc/haruchi/web/controller/DayBudgetController.java b/src/main/java/umc/haruchi/web/controller/DayBudgetController.java index 479125d..949d7d2 100644 --- a/src/main/java/umc/haruchi/web/controller/DayBudgetController.java +++ b/src/main/java/umc/haruchi/web/controller/DayBudgetController.java @@ -1,6 +1,9 @@ package umc.haruchi.web.controller; import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponses; import jakarta.validation.Valid; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.core.annotation.AuthenticationPrincipal; @@ -26,6 +29,12 @@ public class DayBudgetController { @Operation(summary = "하루 예산을 조회하는 API.", description = "회원의 하루 예산을 조회하는 API 입니다.") + @ApiResponses({ + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200",description = "OK, 성공"), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "MEMBER4005", description = "존재하지 않는 회원입니다.",content = @Content(schema = @Schema(implementation = ApiResponse.class))), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "MONTHBUDGET4001", description = "한달 예산이 존재하지 않습니다.",content = @Content(schema = @Schema(implementation = ApiResponse.class))), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "DAYBUDGET4001", description = "하루예산이 존재하지 않습니다.",content = @Content(schema = @Schema(implementation = ApiResponse.class))), + }) @GetMapping("") public ApiResponse getDailyBudget(@AuthenticationPrincipal MemberDetail memberDetail){ Integer todayBudget = dayBudgetService.findDayBudget(memberDetail.getMember().getId()); @@ -33,6 +42,12 @@ public ApiResponse getDailyBudget(@Authentica } @Operation(summary = "날짜별 예산 금액 조회하는 API.", description = "오늘부터 말일까지의 예산을 조회하는 API 입니다.") + @ApiResponses({ + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200",description = "OK, 성공"), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "MEMBER4005", description = "존재하지 않는 회원입니다.",content = @Content(schema = @Schema(implementation = ApiResponse.class))), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "MONTHBUDGET4001", description = "한달 예산이 존재하지 않습니다.",content = @Content(schema = @Schema(implementation = ApiResponse.class))), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "DAYBUDGET4002", description = "특정 날짜의 예산이 존재하지 않습니다.",content = @Content(schema = @Schema(implementation = ApiResponse.class))), + }) @GetMapping("/list") public ApiResponse getAllBudget(@AuthenticationPrincipal MemberDetail memberDetail){ List allBudget = dayBudgetService.findAllBudget(memberDetail.getMember().getId()); @@ -40,6 +55,12 @@ public ApiResponse getAllBudget(@Authenticat } @Operation(summary = "수입 등록 API", description = "하루 수입을 등록하는 API 입니다.") + @ApiResponses({ + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200",description = "OK, 성공"), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "MEMBER4005", description = "존재하지 않는 회원입니다.",content = @Content(schema = @Schema(implementation = ApiResponse.class))), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "MONTHBUDGET4001", description = "한달 예산이 존재하지 않습니다.",content = @Content(schema = @Schema(implementation = ApiResponse.class))), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "DAYBUDGET4002", description = "특정 날짜의 예산이 존재하지 않습니다.",content = @Content(schema = @Schema(implementation = ApiResponse.class))), + }) @PostMapping("/income") public ApiResponse createIncome(@Valid @RequestBody DayBudgetRequestDTO.createIncomeDTO request, @AuthenticationPrincipal MemberDetail memberDetail){ @@ -49,6 +70,14 @@ public ApiResponse createIncome(@Valid @RequestB } @Operation(summary = "수입 삭제 API", description = "기록했던 하루 수입을 삭제하는 API 입니다.") + @ApiResponses({ + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200",description = "OK, 성공"), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "MEMBER4005", description = "존재하지 않는 회원입니다.",content = @Content(schema = @Schema(implementation = ApiResponse.class))), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "MONTHBUDGET4001", description = "한달 예산이 존재하지 않습니다.",content = @Content(schema = @Schema(implementation = ApiResponse.class))), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "DAYBUDGET4002", description = "특정 날짜의 예산이 존재하지 않습니다.",content = @Content(schema = @Schema(implementation = ApiResponse.class))), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "MONTHBUDGET4003", description = "오늘 지출은 마감되었습니다.",content = @Content(schema = @Schema(implementation = ApiResponse.class))), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "INCOME4001", description = "해당 수입이 존재하지 않습니다.",content = @Content(schema = @Schema(implementation = ApiResponse.class))), + }) @DeleteMapping("/income/{incomeId}") public ApiResponse deleteIncome(@PathVariable Long incomeId, @AuthenticationPrincipal MemberDetail memberDetail){ @@ -57,6 +86,12 @@ public ApiResponse deleteIncome(@PathVariable Long incomeId, } @Operation(summary = "지출 등록 API", description = "하루 지출을 등록하는 API 입니다.") + @ApiResponses({ + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200",description = "OK, 성공"), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "MEMBER4005", description = "존재하지 않는 회원입니다.",content = @Content(schema = @Schema(implementation = ApiResponse.class))), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "MONTHBUDGET4001", description = "한달 예산이 존재하지 않습니다.",content = @Content(schema = @Schema(implementation = ApiResponse.class))), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "DAYBUDGET4002", description = "특정 날짜의 예산이 존재하지 않습니다.",content = @Content(schema = @Schema(implementation = ApiResponse.class))), + }) @PostMapping("/expenditure") public ApiResponse createExpenditure(@Valid @RequestBody DayBudgetRequestDTO.createExpenditureDTO request, @AuthenticationPrincipal MemberDetail memberDetail){ @@ -65,6 +100,14 @@ public ApiResponse createExpenditure(@Valid } @Operation(summary = "지출 삭제 API", description = "기록했던 하루 지출을 삭제하는 APi 입니다.") + @ApiResponses({ + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200",description = "OK, 성공"), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "MEMBER4005", description = "존재하지 않는 회원입니다.",content = @Content(schema = @Schema(implementation = ApiResponse.class))), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "MONTHBUDGET4001", description = "한달 예산이 존재하지 않습니다.",content = @Content(schema = @Schema(implementation = ApiResponse.class))), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "DAYBUDGET4002", description = "특정 날짜의 예산이 존재하지 않습니다.",content = @Content(schema = @Schema(implementation = ApiResponse.class))), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "MONTHBUDGET4003", description = "오늘 지출은 마감되었습니다.",content = @Content(schema = @Schema(implementation = ApiResponse.class))), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "EXPENDITURE4001", description = "해당 지출이 존재하지 않습니다.",content = @Content(schema = @Schema(implementation = ApiResponse.class))), + }) @DeleteMapping("/expenditure/{expenditureId}") public ApiResponse deleteExpenditure(@PathVariable Long expenditureId, @AuthenticationPrincipal MemberDetail memberDetail){