diff --git a/server/src/main/java/server/haengdong/application/response/EventDetailAppResponse.java b/server/src/main/java/server/haengdong/application/response/EventDetailAppResponse.java index 53fd0b48c..899ea76ec 100644 --- a/server/src/main/java/server/haengdong/application/response/EventDetailAppResponse.java +++ b/server/src/main/java/server/haengdong/application/response/EventDetailAppResponse.java @@ -4,10 +4,11 @@ public record EventDetailAppResponse( String eventName, - String account + String bankName, + String accountNumber ) { public static EventDetailAppResponse of(Event event) { - return new EventDetailAppResponse(event.getName(), event.getAccount()); + return new EventDetailAppResponse(event.getName(), event.getBankName(), event.getAccountNumber()); } } diff --git a/server/src/main/java/server/haengdong/domain/event/Event.java b/server/src/main/java/server/haengdong/domain/event/Event.java index 30dd2a8a4..58d080a43 100644 --- a/server/src/main/java/server/haengdong/domain/event/Event.java +++ b/server/src/main/java/server/haengdong/domain/event/Event.java @@ -7,6 +7,7 @@ import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; +import java.util.Arrays; import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; @@ -92,7 +93,23 @@ private void validateAccountNumber(String accountNumber) { int accountLength = accountNumber.trim().length(); if (accountLength < MIN_ACCOUNT_NUMBER_LENGTH || MAX_ACCOUNT_NUMBER_LENGTH < accountLength) { throw new HaengdongException( - HaengdongErrorCode.ACCOUNT_LENGTH_INVALID, MIN_ACCOUNT_NUMBER_LENGTH, MAX_ACCOUNT_NUMBER_LENGTH); + HaengdongErrorCode.ACCOUNT_LENGTH_INVALID, MIN_ACCOUNT_NUMBER_LENGTH, MAX_ACCOUNT_NUMBER_LENGTH); } } + + public String getBankName() { + String[] bankNameAndAccountNumber = account.split(" "); + if (bankNameAndAccountNumber.length > 0) { + return bankNameAndAccountNumber[0]; + } + return ""; + } + + public String getAccountNumber() { + String[] bankNameAndAccountNumber = account.split(" "); + if (bankNameAndAccountNumber.length > 1) { + return String.join(" ", Arrays.copyOfRange(bankNameAndAccountNumber, 1, bankNameAndAccountNumber.length)); + } + return ""; + } } diff --git a/server/src/main/java/server/haengdong/presentation/response/EventDetailResponse.java b/server/src/main/java/server/haengdong/presentation/response/EventDetailResponse.java index c03ae8178..e5421940c 100644 --- a/server/src/main/java/server/haengdong/presentation/response/EventDetailResponse.java +++ b/server/src/main/java/server/haengdong/presentation/response/EventDetailResponse.java @@ -4,10 +4,11 @@ public record EventDetailResponse( String eventName, - String account + String bankName, + String accountNumber ) { public static EventDetailResponse of(EventDetailAppResponse response) { - return new EventDetailResponse(response.eventName(), response.account()); + return new EventDetailResponse(response.eventName(), response.bankName(), response.accountNumber()); } } diff --git a/server/src/test/java/server/haengdong/application/EventServiceTest.java b/server/src/test/java/server/haengdong/application/EventServiceTest.java index e5fef4184..e40a682dc 100644 --- a/server/src/test/java/server/haengdong/application/EventServiceTest.java +++ b/server/src/test/java/server/haengdong/application/EventServiceTest.java @@ -76,7 +76,8 @@ void updateEventTest() { Event updateEvent = eventRepository.findByToken(event.getToken()).get(); assertAll( () -> assertThat(updateEvent.getName()).isEqualTo("새로운 행사 이름"), - () -> assertThat(updateEvent.getAccount()).isEqualTo("토스뱅크 12345678") + () -> assertThat(updateEvent.getBankName()).isEqualTo("토스뱅크"), + () -> assertThat(updateEvent.getAccountNumber()).isEqualTo("12345678") ); } @@ -92,7 +93,8 @@ void updateEventTest1() { Event updateEvent = eventRepository.findByToken(event.getToken()).get(); assertAll( () -> assertThat(updateEvent.getName()).isEqualTo("행동대장 비대위"), - () -> assertThat(updateEvent.getAccount()).isEqualTo("토스뱅크 12345678") + () -> assertThat(updateEvent.getBankName()).isEqualTo("토스뱅크"), + () -> assertThat(updateEvent.getAccountNumber()).isEqualTo("12345678") ); } @@ -108,7 +110,8 @@ void updateEventTest2() { Event updateEvent = eventRepository.findByToken(event.getToken()).get(); assertAll( () -> assertThat(updateEvent.getName()).isEqualTo("행동대장 정상 영업"), - () -> assertThat(updateEvent.getAccount()).isEqualTo("") + () -> assertThat(updateEvent.getBankName()).isEqualTo(""), + () -> assertThat(updateEvent.getAccountNumber()).isEqualTo("") ); } @@ -124,7 +127,8 @@ void updateEventTest3() { Event updateEvent = eventRepository.findByToken(event.getToken()).get(); assertAll( () -> assertThat(updateEvent.getName()).isEqualTo("행동대장 비대위"), - () -> assertThat(updateEvent.getAccount()).isEqualTo("") + () -> assertThat(updateEvent.getBankName()).isEqualTo(""), + () -> assertThat(updateEvent.getAccountNumber()).isEqualTo("") ); } diff --git a/server/src/test/java/server/haengdong/docs/EventControllerDocsTest.java b/server/src/test/java/server/haengdong/docs/EventControllerDocsTest.java index 36a752953..83144f135 100644 --- a/server/src/test/java/server/haengdong/docs/EventControllerDocsTest.java +++ b/server/src/test/java/server/haengdong/docs/EventControllerDocsTest.java @@ -57,7 +57,7 @@ protected Object initController() { @Test void findEventTest() throws Exception { String eventId = "망쵸토큰"; - EventDetailAppResponse eventDetailAppResponse = new EventDetailAppResponse("행동대장 회식", "토스 12312455"); + EventDetailAppResponse eventDetailAppResponse = new EventDetailAppResponse("행동대장 회식", "토스뱅크", "12312455"); given(eventService.findEvent(eventId)).willReturn(eventDetailAppResponse); mockMvc.perform(get("/api/events/{eventId}", eventId)) @@ -73,7 +73,8 @@ void findEventTest() throws Exception { ), responseFields( fieldWithPath("eventName").type(JsonFieldType.STRING).description("행사 이름"), - fieldWithPath("account").type(JsonFieldType.STRING).description("행사 계좌") + fieldWithPath("bankName").type(JsonFieldType.STRING).description("토스뱅크"), + fieldWithPath("accountNumber").type(JsonFieldType.STRING).description("12312455") ) ) ); diff --git a/server/src/test/java/server/haengdong/domain/event/EventTest.java b/server/src/test/java/server/haengdong/domain/event/EventTest.java index 83cd700a0..67c5420b0 100644 --- a/server/src/test/java/server/haengdong/domain/event/EventTest.java +++ b/server/src/test/java/server/haengdong/domain/event/EventTest.java @@ -3,6 +3,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatCode; import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.jupiter.api.Assertions.assertAll; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -81,7 +82,10 @@ void changeAccountTest() { event.changeAccount("토스뱅크", "12345678"); - assertThat(event.getAccount()).isEqualTo("토스뱅크 12345678"); + assertAll( + () -> assertThat(event.getBankName()).isEqualTo("토스뱅크"), + () -> assertThat(event.getAccountNumber()).isEqualTo("12345678") + ); } @DisplayName("계좌 정보에 은행 이름과 계좌 번호가 모두 포함되지 않으면 예외가 발생한다.") @@ -132,4 +136,30 @@ void changeAccountTest5(String accountNumber) { assertThatThrownBy(() -> event.changeAccount("토스뱅크", accountNumber)) .isInstanceOf(HaengdongException.class); } + + @DisplayName("계좌 정보를 조회한다.") + @Test + void getBankNameTest() { + Event event = new Event("이름", "1234", "TEST_TOKEN"); + + event.changeAccount("토스뱅크", "12345678"); + + assertAll( + () -> assertThat(event.getBankName()).isEqualTo("토스뱅크"), + () -> assertThat(event.getAccountNumber()).isEqualTo("12345678") + ); + } + + @DisplayName("계좌 번호에 공백이 있어도 계좌 정보를 정상적으로 조회한다.") + @Test + void getBankNameTest1() { + Event event = new Event("이름", "1234", "TEST_TOKEN"); + + event.changeAccount("토스뱅크", "1234 5678 9012"); + + assertAll( + () -> assertThat(event.getBankName()).isEqualTo("토스뱅크"), + () -> assertThat(event.getAccountNumber()).isEqualTo("1234 5678 9012") + ); + } } diff --git a/server/src/test/java/server/haengdong/presentation/EventControllerTest.java b/server/src/test/java/server/haengdong/presentation/EventControllerTest.java index f1f11d4a6..5facbb740 100644 --- a/server/src/test/java/server/haengdong/presentation/EventControllerTest.java +++ b/server/src/test/java/server/haengdong/presentation/EventControllerTest.java @@ -29,7 +29,7 @@ class EventControllerTest extends ControllerTestSupport { @Test void findEventTest() throws Exception { String eventId = "망쵸토큰"; - EventDetailAppResponse eventDetailAppResponse = new EventDetailAppResponse("행동대장 회식", "토스 1231245"); + EventDetailAppResponse eventDetailAppResponse = new EventDetailAppResponse("행동대장 회식", "토스뱅크", "1231245"); given(eventService.findEvent(eventId)).willReturn(eventDetailAppResponse); mockMvc.perform(get("/api/events/{eventId}", eventId))