Skip to content

Commit

Permalink
♻️ refactor : bank 쑰회 API #494
Browse files Browse the repository at this point in the history
  • Loading branch information
hobeen-kim committed Oct 4, 2023
1 parent 94bd021 commit 2771804
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Server/src/docs/asciidoc/snippets/adjustment/bank.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
:doctype: book
:icons: font
:source-highlighter: highlightjs
:toc: left
:toclevels: 2
:sectlinks:
:docinfo: shared-head

[[bank]]
= 은행 λͺ©λ‘ API

== λΉ„λ””μ˜€λ³„ μ •μ‚° λ‚΄μ—­ νŽ˜μ΄μ§•
=== HTTP Request
include::{snippets}/adjustment/getbanks/http-request.adoc[]
==== Request Headers
include::{snippets}/adjustment/getbanks/request-headers.adoc[]
=== HTTP Response
include::{snippets}/adjustment/getbanks/http-response.adoc[]
==== Response Fields
include::{snippets}/adjustment/getbanks/response-fields.adoc[]
6 changes: 6 additions & 0 deletions Server/src/docs/asciidoc/snippets/common/bank.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
:doctype: book
:icons: font

[[answerStatus]]

include::{snippets}/common/enums/custom-response-fields-Bank.adoc[]
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.server.domain.adjustment.controller;

import com.server.domain.account.domain.Bank;
import com.server.domain.adjustment.controller.dto.request.AccountUpdateApiRequest;
import com.server.domain.adjustment.service.AdjustmentService;
import com.server.domain.adjustment.service.dto.response.*;
Expand All @@ -19,7 +20,9 @@
import javax.validation.constraints.Min;
import javax.validation.constraints.Positive;
import java.net.URI;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/adjustments")
Expand Down Expand Up @@ -92,6 +95,16 @@ public ResponseEntity<ApiSingleResponse<Void>> updateAccount(
return ResponseEntity.noContent().build();
}

@GetMapping("/banks")
public ResponseEntity<ApiSingleResponse<List<BankResponse>>> getBanks() {

List<BankResponse> responses = Arrays.stream(Bank.values())
.map(BankResponse::of)
.collect(Collectors.toList());

return ResponseEntity.ok(ApiSingleResponse.ok(responses, "은행 쑰회 성곡"));
}

private void checkValidDate(Integer month, Integer year) {
if(month != null && year == null) {
throw new AdjustmentDateException();
Expand All @@ -109,4 +122,5 @@ private String getAdjustmentMessage(Integer month, Integer year) {

return year + "λ…„";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.server.domain.adjustment.service.dto.response;

import com.server.domain.account.domain.Bank;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;

@AllArgsConstructor
@Getter
@Builder
public class BankResponse {

private String bank;
private String description;

public static BankResponse of(Bank bank) {
return BankResponse.builder()
.bank(bank.name())
.description(bank.getDescription())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
import org.springframework.test.web.servlet.ResultActions;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import static com.server.global.testhelper.RestDocsUtil.pageResponseFields;
import static com.server.global.testhelper.RestDocsUtil.singleResponseFields;
Expand Down Expand Up @@ -314,6 +316,43 @@ void calculateVideoRate() throws Exception {
);
}

@Test
@DisplayName("은행 쑰회 API")
void getBanks() throws Exception {
//given
List<BankResponse> responses = Arrays.stream(Bank.values())
.map(BankResponse::of)
.collect(Collectors.toList());

String apiResponse = objectMapper.writeValueAsString(ApiSingleResponse.ok(responses, "은행 쑰회 성곡"));

//when
ResultActions actions = mockMvc.perform(
get(BASE_URL + "/banks")
.header(AUTHORIZATION, TOKEN)
);

//then
actions
.andDo(print())
.andExpect(status().isOk())
.andExpect(content().string(apiResponse));

//restdocs
actions.andDo(
documentHandler.document(
requestHeaders(
headerWithName(AUTHORIZATION).description("μ•‘μ„ΈμŠ€ 토큰")
),
singleResponseFields(
fieldWithPath("data").description("은행 정보"),
fieldWithPath("data[].bank").description(generateLinkCode(Bank.class)),
fieldWithPath("data[].description").description("은행 μ„€λͺ…")
)
)
);
}

private List<MonthAdjustmentResponse> createToTalAdjustmentResponse(Integer year) {

List<MonthAdjustmentResponse> monthAdjustmentResponses = new ArrayList<>();
Expand Down

0 comments on commit 2771804

Please sign in to comment.