From 5460df5a2a244e792816e4df35a55c72d4202431 Mon Sep 17 00:00:00 2001 From: parksey Date: Wed, 12 Jul 2023 05:14:42 +0900 Subject: [PATCH 01/28] =?UTF-8?q?feat:=20=ED=9A=8C=EC=9B=90=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20=EB=B0=8F=20=EC=A1=B0=ED=9A=8C=EC=97=90=20=EB=8C=80?= =?UTF-8?q?=ED=95=9C=20=EB=A7=A4=ED=95=91=20=EC=B6=94=EA=B0=80=20=EB=B0=8F?= =?UTF-8?q?=20=EC=9B=B9=20=ED=8E=98=EC=9D=B4=EC=A7=80=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 24 ++- .../weekly/VoucherManageApplication.java | 1 + .../dto/response/CustomerResponse.java | 12 ++ .../dto/response/CustomersResponse.java | 6 +- .../web/customer/CustomerWebController.java | 50 ++++++ .../weekly/web/exception/WebExceptionDto.java | 14 ++ src/main/resources/static/form.css | 147 ++++++++++++++++++ src/main/resources/static/main.css | 3 + .../templates/customer/createCustomer.html | 20 +++ .../templates/customer/findCustomers.html | 36 +++++ .../templates/exception/exception.html | 14 ++ src/main/resources/templates/form/form.html | 31 ++++ .../weekly/VoucherManageApplicationTests.java | 5 - .../customer/JdbcCustomerRepositoryTest.java | 8 +- 14 files changed, 356 insertions(+), 15 deletions(-) create mode 100644 src/main/java/org/weekly/weekly/web/customer/CustomerWebController.java create mode 100644 src/main/java/org/weekly/weekly/web/exception/WebExceptionDto.java create mode 100644 src/main/resources/static/form.css create mode 100644 src/main/resources/static/main.css create mode 100644 src/main/resources/templates/customer/createCustomer.html create mode 100644 src/main/resources/templates/customer/findCustomers.html create mode 100644 src/main/resources/templates/exception/exception.html create mode 100644 src/main/resources/templates/form/form.html diff --git a/pom.xml b/pom.xml index 72e5a7a170..ea55bea69b 100644 --- a/pom.xml +++ b/pom.xml @@ -11,12 +11,12 @@ org.weekly weekly 0.0.1-SNAPSHOT - weekly + weekly21 + war Demo project for Spring Boot 17 - jar org.springframework.boot @@ -35,7 +35,23 @@ - mysql + org.springframework.boot + spring-boot-starter-thymeleaf + + + + org.springframework.boot + spring-boot-starter-tomcat + provided + + + + org.springframework.boot + spring-boot-starter-web + + + + ` mysql mysql-connector-java 8.0.28 @@ -58,6 +74,8 @@ 1.18.3 test + + diff --git a/src/main/java/org/weekly/weekly/VoucherManageApplication.java b/src/main/java/org/weekly/weekly/VoucherManageApplication.java index 7fe8ed5f34..081a262e55 100644 --- a/src/main/java/org/weekly/weekly/VoucherManageApplication.java +++ b/src/main/java/org/weekly/weekly/VoucherManageApplication.java @@ -2,6 +2,7 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; import org.springframework.context.ApplicationContext; @SpringBootApplication diff --git a/src/main/java/org/weekly/weekly/customer/dto/response/CustomerResponse.java b/src/main/java/org/weekly/weekly/customer/dto/response/CustomerResponse.java index 343af5edb7..e53e8a5154 100644 --- a/src/main/java/org/weekly/weekly/customer/dto/response/CustomerResponse.java +++ b/src/main/java/org/weekly/weekly/customer/dto/response/CustomerResponse.java @@ -21,6 +21,18 @@ public static CustomerResponse of(Customer customer) { return new CustomerResponse(customer.getName(), customer.getEmail(), customer.getCreateAt()); } + public String getEmail() { + return email; + } + + public LocalDateTime getCreateAt() { + return createAt; + } + + public String getName() { + return name; + } + @Override public String getResult() { return MessageFormat.format("[이름: {0}, 이메일: {1}, 생성 시기: {2}]", name, email, createAt); diff --git a/src/main/java/org/weekly/weekly/customer/dto/response/CustomersResponse.java b/src/main/java/org/weekly/weekly/customer/dto/response/CustomersResponse.java index eb601c9e82..5bcb0fff5d 100644 --- a/src/main/java/org/weekly/weekly/customer/dto/response/CustomersResponse.java +++ b/src/main/java/org/weekly/weekly/customer/dto/response/CustomersResponse.java @@ -2,9 +2,7 @@ import org.weekly.weekly.customer.domain.Customer; import org.weekly.weekly.util.PrintMessageType; -import org.weekly.weekly.voucher.domain.Voucher; import org.weekly.weekly.voucher.dto.Response; -import org.weekly.weekly.voucher.dto.response.VoucherCreationResponse; import java.util.List; import java.util.stream.Collectors; @@ -28,4 +26,8 @@ public String getResult() { result.forEach(customerResponse-> resultBuilder.append(customerResponse.getResult()).append('\n')); return resultBuilder.toString(); } + + public List getCustomerResponses() { + return result; + } } diff --git a/src/main/java/org/weekly/weekly/web/customer/CustomerWebController.java b/src/main/java/org/weekly/weekly/web/customer/CustomerWebController.java new file mode 100644 index 0000000000..86a40b8b18 --- /dev/null +++ b/src/main/java/org/weekly/weekly/web/customer/CustomerWebController.java @@ -0,0 +1,50 @@ +package org.weekly.weekly.web.customer; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.weekly.weekly.customer.dto.request.CustomerCreationRequest; +import org.weekly.weekly.customer.dto.response.CustomerResponse; +import org.weekly.weekly.customer.dto.response.CustomersResponse; +import org.weekly.weekly.customer.exception.CustomerException; +import org.weekly.weekly.customer.service.CustomerService; +import org.weekly.weekly.web.exception.WebExceptionDto; + +@Controller +@RequestMapping("/customer") +public class CustomerWebController { + private final Logger logger = LoggerFactory.getLogger(CustomerWebController.class); + private final CustomerService customerService; + + public CustomerWebController(CustomerService customerService) { + this.customerService = customerService; + } + + @GetMapping("/findCustomers") + public String findCustomers(Model model) { + CustomersResponse customersResponse = customerService.findAllCustomer(); + model.addAttribute("customers", customersResponse); + return "customer/findCustomers"; + } + + @GetMapping("/create") + public String createCustomer() { + return "customer/createCustomer"; + } + + @PostMapping("/create") + public String createCustomer(CustomerCreationRequest creationRequest, Model model) { + try { + CustomerResponse customerResponse = customerService.createCustomer(creationRequest); + model.addAttribute("customer", customerResponse); + } catch (CustomerException exception) { + model.addAttribute("exception", new WebExceptionDto(exception)); + return "exception/exception"; + } + return "redirect:"; + } +} diff --git a/src/main/java/org/weekly/weekly/web/exception/WebExceptionDto.java b/src/main/java/org/weekly/weekly/web/exception/WebExceptionDto.java new file mode 100644 index 0000000000..da26e5c13c --- /dev/null +++ b/src/main/java/org/weekly/weekly/web/exception/WebExceptionDto.java @@ -0,0 +1,14 @@ +package org.weekly.weekly.web.exception; + +import org.weekly.weekly.customer.exception.CustomerException; + +public class WebExceptionDto { + private String message; + public WebExceptionDto(CustomerException error) { + this.message = error.getMessage(); + } + + public String getMessage() { + return message; + } +} diff --git a/src/main/resources/static/form.css b/src/main/resources/static/form.css new file mode 100644 index 0000000000..02fee27c9f --- /dev/null +++ b/src/main/resources/static/form.css @@ -0,0 +1,147 @@ +*{ + margin: 0; + padding: 0; + outline: none; + box-sizing: border-box; + font-family: 'Poppins', sans-serif; +} +body{ + display: flex; + align-items: center; + justify-content: center; + min-height: 100vh; + padding: 10px; + font-family: 'Poppins', sans-serif; +} +.container{ + max-width: 800px; + background: #fff; + width: 800px; + padding: 25px 40px 10px 40px; + box-shadow: 0px 0px 10px rgba(0,0,0,0.1); +} + +.text { + color: #3498db; +} +.container .text{ + text-align: center; + font-size: 41px; + font-weight: 600; + font-family: 'Poppins', sans-serif; +} +.container form{ + padding: 30px 0 0 0; +} +.container form .form-row{ + display: flex; + margin: 32px 0; +} +form .form-row .input-data{ + width: 100%; + height: 40px; + margin: 0 20px; + position: relative; +} +form .form-row .textarea{ + height: 70px; +} +.input-data input, +.textarea textarea{ + display: block; + width: 100%; + height: 100%; + border: none; + font-size: 17px; + border-bottom: 2px solid rgba(0,0,0, 0.12); +} +.input-data input:focus ~ label, .textarea textarea:focus ~ label, +.input-data input:valid ~ label, .textarea textarea:valid ~ label{ + transform: translateY(-20px); + font-size: 14px; + color: #3498db; +} +.textarea textarea{ + resize: none; + padding-top: 10px; +} +.input-data label{ + position: absolute; + pointer-events: none; + bottom: 10px; + font-size: 16px; + transition: all 0.3s ease; +} +.textarea label{ + width: 100%; + bottom: 40px; + background: #fff; +} +.input-data .underline{ + position: absolute; + bottom: 0; + height: 2px; + width: 100%; + background: #3498db; +} +.input-data .underline:before{ + position: absolute; + content: ""; + height: 2px; + width: 100%; + background: #3498db; + transform: scaleX(0); + transform-origin: center; + transition: transform 0.3s ease; +} +.input-data input:focus ~ .underline:before, +.input-data input:valid ~ .underline:before, +.textarea textarea:focus ~ .underline:before, +.textarea textarea:valid ~ .underline:before{ + transform: scale(1); +} +.submit-btn .input-data{ + overflow: hidden; + height: 45px!important; + width: 25%!important; +} +.submit-btn .input-data .inner{ + height: 100%; + width: 300%; + position: absolute; + left: -100%; + transition: all 0.4s; + background-color: #56d8e4; +} +.submit-btn .input-data:hover .inner{ + left: 0; +} +.submit-btn .input-data input{ + background: none; + border: none; + color: #fff; + font-size: 17px; + font-weight: 500; + text-transform: uppercase; + letter-spacing: 1px; + cursor: pointer; + position: relative; + z-index: 2; +} +@media (max-width: 700px) { + .container .text{ + font-size: 30px; + } + .container form{ + padding: 10px 0 0 0; + } + .container form .form-row{ + display: block; + } + form .form-row .input-data{ + margin: 35px 0!important; + } + .submit-btn .input-data{ + width: 40%!important; + } +} \ No newline at end of file diff --git a/src/main/resources/static/main.css b/src/main/resources/static/main.css new file mode 100644 index 0000000000..45f310b972 --- /dev/null +++ b/src/main/resources/static/main.css @@ -0,0 +1,3 @@ +.title-line { + text-align: center; +} \ No newline at end of file diff --git a/src/main/resources/templates/customer/createCustomer.html b/src/main/resources/templates/customer/createCustomer.html new file mode 100644 index 0000000000..20714dea3c --- /dev/null +++ b/src/main/resources/templates/customer/createCustomer.html @@ -0,0 +1,20 @@ + + + + + + + + + + Document + + +
+

고객 생성

+
+
+ + + diff --git a/src/main/resources/templates/customer/findCustomers.html b/src/main/resources/templates/customer/findCustomers.html new file mode 100644 index 0000000000..3ddab1d115 --- /dev/null +++ b/src/main/resources/templates/customer/findCustomers.html @@ -0,0 +1,36 @@ + + + + + + + + + + Document + + +
+

고객 리스트

+ + + + + + + + + + + + + + + + + +
번호이름이에밀생성일
+
+ + \ No newline at end of file diff --git a/src/main/resources/templates/exception/exception.html b/src/main/resources/templates/exception/exception.html new file mode 100644 index 0000000000..7d9d5d8fce --- /dev/null +++ b/src/main/resources/templates/exception/exception.html @@ -0,0 +1,14 @@ + + + + + + + Document + + +

Error Page

+

+ + \ No newline at end of file diff --git a/src/main/resources/templates/form/form.html b/src/main/resources/templates/form/form.html new file mode 100644 index 0000000000..4aa624db74 --- /dev/null +++ b/src/main/resources/templates/form/form.html @@ -0,0 +1,31 @@ + +
+
+
+ +
+
+
+
+ +
+
+
+
+ +
+
+
+ +
+ +
+
+ +
+ +
+
+
+ + diff --git a/src/test/java/org/weekly/weekly/VoucherManageApplicationTests.java b/src/test/java/org/weekly/weekly/VoucherManageApplicationTests.java index 4d2b02e11a..d70e8574cd 100644 --- a/src/test/java/org/weekly/weekly/VoucherManageApplicationTests.java +++ b/src/test/java/org/weekly/weekly/VoucherManageApplicationTests.java @@ -5,9 +5,4 @@ @SpringBootTest class VoucherManageApplicationTests { - - @Test - void contextLoads() { - } - } diff --git a/src/test/java/org/weekly/weekly/customer/JdbcCustomerRepositoryTest.java b/src/test/java/org/weekly/weekly/customer/JdbcCustomerRepositoryTest.java index 54b4f22fed..f7ad68a255 100644 --- a/src/test/java/org/weekly/weekly/customer/JdbcCustomerRepositoryTest.java +++ b/src/test/java/org/weekly/weekly/customer/JdbcCustomerRepositoryTest.java @@ -6,7 +6,6 @@ import org.springframework.test.context.ActiveProfiles; import org.testcontainers.junit.jupiter.Testcontainers; import org.weekly.weekly.customer.domain.Customer; -import org.weekly.weekly.customer.exception.CustomerException; import org.weekly.weekly.customer.repository.JdbcCustomerRepository; import java.util.List; @@ -14,12 +13,9 @@ import java.util.UUID; import static org.assertj.core.api.Assertions.assertThatCode; -import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.samePropertyValuesAs; -@Testcontainers @TestMethodOrder(MethodOrderer.OrderAnnotation.class) @ActiveProfiles("test") @SpringBootTest @@ -59,7 +55,9 @@ void deleteCustomer() { // Then assertThat(findCustomer.isEmpty(), is(false)); - assertThat(findCustomer.get(), samePropertyValuesAs(insertCustomer)); + assertThat(findCustomer.get().getCustomerId(), is(insertCustomer.getCustomerId())); + assertThat(findCustomer.get().getName(), is(insertCustomer.getName())); + assertThat(findCustomer.get().getEmail(), is(insertCustomer.getEmail())); } @Test From 6243aca7067762f2788c7752e7b396899973efaf Mon Sep 17 00:00:00 2001 From: parksey Date: Wed, 12 Jul 2023 06:12:55 +0900 Subject: [PATCH 02/28] =?UTF-8?q?feat:=20=EB=A9=94=EC=9D=B8=20=ED=8E=98?= =?UTF-8?q?=EC=9D=B4=EC=A7=80=20=EB=B0=8F=20=ED=9A=8C=EC=9B=90=20=ED=8E=98?= =?UTF-8?q?=EC=9D=B4=EC=A7=80=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/customer/CustomerWebController.java | 9 +++-- src/main/resources/static/main.css | 6 ++++ .../templates/customer/createCustomer.html | 11 ++---- .../templates/customer/findCustomer.html | 10 ++++++ .../templates/customer/findCustomers.html | 8 +---- .../resources/templates/customer/menu.html | 35 +++++++++++++++++++ .../templates/{form => global}/form.html | 2 +- src/main/resources/templates/global/head.html | 10 ++++++ src/main/resources/templates/index.html | 25 +++++++++++++ 9 files changed, 97 insertions(+), 19 deletions(-) create mode 100644 src/main/resources/templates/customer/findCustomer.html create mode 100644 src/main/resources/templates/customer/menu.html rename src/main/resources/templates/{form => global}/form.html (92%) create mode 100644 src/main/resources/templates/global/head.html create mode 100644 src/main/resources/templates/index.html diff --git a/src/main/java/org/weekly/weekly/web/customer/CustomerWebController.java b/src/main/java/org/weekly/weekly/web/customer/CustomerWebController.java index 86a40b8b18..d23733fe9e 100644 --- a/src/main/java/org/weekly/weekly/web/customer/CustomerWebController.java +++ b/src/main/java/org/weekly/weekly/web/customer/CustomerWebController.java @@ -40,11 +40,16 @@ public String createCustomer() { public String createCustomer(CustomerCreationRequest creationRequest, Model model) { try { CustomerResponse customerResponse = customerService.createCustomer(creationRequest); - model.addAttribute("customer", customerResponse); +// model.addAttribute("customer", customerResponse); } catch (CustomerException exception) { model.addAttribute("exception", new WebExceptionDto(exception)); return "exception/exception"; } - return "redirect:"; + return "redirect:/"; + } + + @GetMapping("/findCustomer") + public String findCustomer() { + return "customer/findCustomer"; } } diff --git a/src/main/resources/static/main.css b/src/main/resources/static/main.css index 45f310b972..106ec7a98d 100644 --- a/src/main/resources/static/main.css +++ b/src/main/resources/static/main.css @@ -1,3 +1,9 @@ .title-line { text-align: center; +} + +.menu-list { + list-style: none; + padding: 0; + text-align: center; } \ No newline at end of file diff --git a/src/main/resources/templates/customer/createCustomer.html b/src/main/resources/templates/customer/createCustomer.html index 20714dea3c..526387cc9d 100644 --- a/src/main/resources/templates/customer/createCustomer.html +++ b/src/main/resources/templates/customer/createCustomer.html @@ -1,19 +1,12 @@ - - - - - - - + Document

고객 생성

-
+
diff --git a/src/main/resources/templates/customer/findCustomer.html b/src/main/resources/templates/customer/findCustomer.html new file mode 100644 index 0000000000..15e29b543d --- /dev/null +++ b/src/main/resources/templates/customer/findCustomer.html @@ -0,0 +1,10 @@ + + + + + Title + + + + + \ No newline at end of file diff --git a/src/main/resources/templates/customer/findCustomers.html b/src/main/resources/templates/customer/findCustomers.html index 3ddab1d115..e2f8bfd2db 100644 --- a/src/main/resources/templates/customer/findCustomers.html +++ b/src/main/resources/templates/customer/findCustomers.html @@ -1,13 +1,7 @@ - - - - - - + Document diff --git a/src/main/resources/templates/customer/menu.html b/src/main/resources/templates/customer/menu.html new file mode 100644 index 0000000000..b325096dc3 --- /dev/null +++ b/src/main/resources/templates/customer/menu.html @@ -0,0 +1,35 @@ + + + + Document + + +
+

회원 메뉴

+ + + +
+ + \ No newline at end of file diff --git a/src/main/resources/templates/form/form.html b/src/main/resources/templates/global/form.html similarity index 92% rename from src/main/resources/templates/form/form.html rename to src/main/resources/templates/global/form.html index 4aa624db74..be39737769 100644 --- a/src/main/resources/templates/form/form.html +++ b/src/main/resources/templates/global/form.html @@ -18,7 +18,7 @@
- +
diff --git a/src/main/resources/templates/global/head.html b/src/main/resources/templates/global/head.html new file mode 100644 index 0000000000..ed86195cba --- /dev/null +++ b/src/main/resources/templates/global/head.html @@ -0,0 +1,10 @@ + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html new file mode 100644 index 0000000000..ba1ceab444 --- /dev/null +++ b/src/main/resources/templates/index.html @@ -0,0 +1,25 @@ + + + + Document + + +
+

메인 페이지

+ +
+ +
+ +
+ + \ No newline at end of file From f2c490a2b06e4db815effa1f507e63f9e57c75c4 Mon Sep 17 00:00:00 2001 From: parksey Date: Thu, 13 Jul 2023 16:55:52 +0900 Subject: [PATCH 03/28] =?UTF-8?q?feat:=20=ED=9A=8C=EC=9B=90=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20web=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/request/CustomerUpdateRequest.java | 10 +++++- .../repository/JdbcCustomerRepository.java | 5 --- .../web/customer/CustomerWebController.java | 30 +++++++++++++---- .../weekly/web/exception/WebExceptionDto.java | 4 +-- .../templates/customer/createCustomer.html | 6 +++- .../templates/customer/customerInfo.html | 23 +++++++++++++ .../templates/customer/findCustomer.html | 7 ++++ .../templates/customer/findCustomers.html | 33 ++++++++----------- .../resources/templates/customer/menu.html | 2 ++ .../resources/templates/global/customer.html | 18 ++++++++++ src/main/resources/templates/global/form.html | 10 ++++++ 11 files changed, 113 insertions(+), 35 deletions(-) create mode 100644 src/main/resources/templates/customer/customerInfo.html create mode 100644 src/main/resources/templates/global/customer.html diff --git a/src/main/java/org/weekly/weekly/customer/dto/request/CustomerUpdateRequest.java b/src/main/java/org/weekly/weekly/customer/dto/request/CustomerUpdateRequest.java index 5567f226b4..2167479380 100644 --- a/src/main/java/org/weekly/weekly/customer/dto/request/CustomerUpdateRequest.java +++ b/src/main/java/org/weekly/weekly/customer/dto/request/CustomerUpdateRequest.java @@ -1,11 +1,14 @@ package org.weekly.weekly.customer.dto.request; +import org.springframework.beans.factory.annotation.Autowired; import org.weekly.weekly.ui.exception.InputValidator; public class CustomerUpdateRequest { private String email; private String newEmail; + private CustomerUpdateRequest(){} + private CustomerUpdateRequest(String email, String afterEmail) { this.email = email; this.newEmail = afterEmail; @@ -14,11 +17,13 @@ private CustomerUpdateRequest(String email) { this.email = email; } + public static CustomerUpdateRequest of(String email) { InputValidator.isEmpty(email); return new CustomerUpdateRequest(email); } + public static CustomerUpdateRequest of(String email, String afterEmail) { InputValidator.isEmpty(email); InputValidator.isEmpty(afterEmail); @@ -28,6 +33,9 @@ public static CustomerUpdateRequest of(String email, String afterEmail) { public String email() { return email; } - public String newEmail() {return newEmail;} + + public void setEmail(String email) { + this.email = email; + } } diff --git a/src/main/java/org/weekly/weekly/customer/repository/JdbcCustomerRepository.java b/src/main/java/org/weekly/weekly/customer/repository/JdbcCustomerRepository.java index b332fa85f4..33916e3e2c 100644 --- a/src/main/java/org/weekly/weekly/customer/repository/JdbcCustomerRepository.java +++ b/src/main/java/org/weekly/weekly/customer/repository/JdbcCustomerRepository.java @@ -1,23 +1,18 @@ package org.weekly.weekly.customer.repository; import org.springframework.context.annotation.Profile; -import org.springframework.dao.DataAccessException; import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Repository; import org.weekly.weekly.customer.domain.Customer; import org.weekly.weekly.customer.exception.CustomerException; import org.weekly.weekly.util.ExceptionMsg; -import org.weekly.weekly.voucher.domain.DiscountType; -import org.weekly.weekly.voucher.domain.Voucher; -import org.weekly.weekly.voucher.exception.VoucherException; import javax.sql.DataSource; import java.nio.ByteBuffer; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Timestamp; -import java.time.LocalDate; import java.time.LocalDateTime; import java.util.List; import java.util.Optional; diff --git a/src/main/java/org/weekly/weekly/web/customer/CustomerWebController.java b/src/main/java/org/weekly/weekly/web/customer/CustomerWebController.java index d23733fe9e..5ec9103505 100644 --- a/src/main/java/org/weekly/weekly/web/customer/CustomerWebController.java +++ b/src/main/java/org/weekly/weekly/web/customer/CustomerWebController.java @@ -2,12 +2,13 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.*; +import org.weekly.weekly.customer.domain.Customer; import org.weekly.weekly.customer.dto.request.CustomerCreationRequest; +import org.weekly.weekly.customer.dto.request.CustomerUpdateRequest; import org.weekly.weekly.customer.dto.response.CustomerResponse; import org.weekly.weekly.customer.dto.response.CustomersResponse; import org.weekly.weekly.customer.exception.CustomerException; @@ -24,6 +25,11 @@ public CustomerWebController(CustomerService customerService) { this.customerService = customerService; } + @GetMapping("/menu") + public String menu() { + return "customer/menu"; + } + @GetMapping("/findCustomers") public String findCustomers(Model model) { CustomersResponse customersResponse = customerService.findAllCustomer(); @@ -37,19 +43,31 @@ public String createCustomer() { } @PostMapping("/create") - public String createCustomer(CustomerCreationRequest creationRequest, Model model) { + public String createCustomer( CustomerCreationRequest creationRequest, Model model) { try { CustomerResponse customerResponse = customerService.createCustomer(creationRequest); -// model.addAttribute("customer", customerResponse); + model.addAttribute("customer", customerResponse); } catch (CustomerException exception) { model.addAttribute("exception", new WebExceptionDto(exception)); return "exception/exception"; } - return "redirect:/"; + return "customer/customerInfo"; } + @GetMapping("/findCustomer") public String findCustomer() { return "customer/findCustomer"; } + + @PostMapping("/findCustomer") + public String findCustomer(CustomerUpdateRequest updateRequest, Model model) { + try { + CustomerResponse customerResponse = customerService.findDetailCustomer(updateRequest); + model.addAttribute("customer", customerResponse); + } catch(CustomerException | EmptyResultDataAccessException exception) { + return "redirect:/customer/findCustomer"; + } + return "customer/customerInfo"; + } } diff --git a/src/main/java/org/weekly/weekly/web/exception/WebExceptionDto.java b/src/main/java/org/weekly/weekly/web/exception/WebExceptionDto.java index da26e5c13c..079463b752 100644 --- a/src/main/java/org/weekly/weekly/web/exception/WebExceptionDto.java +++ b/src/main/java/org/weekly/weekly/web/exception/WebExceptionDto.java @@ -1,10 +1,8 @@ package org.weekly.weekly.web.exception; -import org.weekly.weekly.customer.exception.CustomerException; - public class WebExceptionDto { private String message; - public WebExceptionDto(CustomerException error) { + public WebExceptionDto(RuntimeException error) { this.message = error.getMessage(); } diff --git a/src/main/resources/templates/customer/createCustomer.html b/src/main/resources/templates/customer/createCustomer.html index 526387cc9d..7bc752c868 100644 --- a/src/main/resources/templates/customer/createCustomer.html +++ b/src/main/resources/templates/customer/createCustomer.html @@ -5,7 +5,11 @@
-

고객 생성

+
+

고객 생성

+ Home +
+
diff --git a/src/main/resources/templates/customer/customerInfo.html b/src/main/resources/templates/customer/customerInfo.html new file mode 100644 index 0000000000..33f25a18bc --- /dev/null +++ b/src/main/resources/templates/customer/customerInfo.html @@ -0,0 +1,23 @@ + + + + Customer Info + + +
+
+

고객 정보

+ Home +
+
+ + + + +
+
+
+ + + + diff --git a/src/main/resources/templates/customer/findCustomer.html b/src/main/resources/templates/customer/findCustomer.html index 15e29b543d..0d6911f025 100644 --- a/src/main/resources/templates/customer/findCustomer.html +++ b/src/main/resources/templates/customer/findCustomer.html @@ -5,6 +5,13 @@ Title +
+
+

고객 정보 찾기

+ Home +
+
+
\ No newline at end of file diff --git a/src/main/resources/templates/customer/findCustomers.html b/src/main/resources/templates/customer/findCustomers.html index e2f8bfd2db..67cca75501 100644 --- a/src/main/resources/templates/customer/findCustomers.html +++ b/src/main/resources/templates/customer/findCustomers.html @@ -6,25 +6,20 @@
-

고객 리스트

- - - - - - - - - - - - - - - - - -
번호이름이에밀생성일
+
+

고객 리스트

+ Home +
+
+ + + + + + + +
+
\ No newline at end of file diff --git a/src/main/resources/templates/customer/menu.html b/src/main/resources/templates/customer/menu.html index b325096dc3..a1a54d6ff4 100644 --- a/src/main/resources/templates/customer/menu.html +++ b/src/main/resources/templates/customer/menu.html @@ -5,6 +5,7 @@
+

회원 메뉴

@@ -27,6 +28,7 @@

회원 메뉴

  • 회원 전체 삭제
  • +
  • Home
  • diff --git a/src/main/resources/templates/global/customer.html b/src/main/resources/templates/global/customer.html new file mode 100644 index 0000000000..1fe1b6735d --- /dev/null +++ b/src/main/resources/templates/global/customer.html @@ -0,0 +1,18 @@ +
    + + + 번호 + 이름 + 이에밀 + 생성일 + + +
    + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/templates/global/form.html b/src/main/resources/templates/global/form.html index be39737769..f6bc747d94 100644 --- a/src/main/resources/templates/global/form.html +++ b/src/main/resources/templates/global/form.html @@ -29,3 +29,13 @@
    +
    +
    +
    + +
    + +
    +
    +
    + From a908e82fb751cb94e0976ed729c5eff992f0fe35 Mon Sep 17 00:00:00 2001 From: parksey Date: Thu, 13 Jul 2023 17:27:14 +0900 Subject: [PATCH 04/28] =?UTF-8?q?feat:=20=ED=9A=8C=EC=9B=90=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=20=EB=B0=8F=20=EC=A0=84=EC=B2=B4=20=EC=82=AD=EC=A0=9C?= =?UTF-8?q?=20controller=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/customer/CustomerWebController.java | 36 +++++++++++++++++-- .../templates/customer/deleteAll.html | 17 +++++++++ .../templates/customer/deleteCustomer.html | 16 +++++++++ .../templates/customer/findCustomer.html | 2 +- .../resources/templates/customer/menu.html | 4 +-- src/main/resources/templates/global/form.html | 12 +++++++ 6 files changed, 81 insertions(+), 6 deletions(-) create mode 100644 src/main/resources/templates/customer/deleteAll.html create mode 100644 src/main/resources/templates/customer/deleteCustomer.html diff --git a/src/main/java/org/weekly/weekly/web/customer/CustomerWebController.java b/src/main/java/org/weekly/weekly/web/customer/CustomerWebController.java index 5ec9103505..c232531c77 100644 --- a/src/main/java/org/weekly/weekly/web/customer/CustomerWebController.java +++ b/src/main/java/org/weekly/weekly/web/customer/CustomerWebController.java @@ -30,7 +30,7 @@ public String menu() { return "customer/menu"; } - @GetMapping("/findCustomers") + @GetMapping("/findAll") public String findCustomers(Model model) { CustomersResponse customersResponse = customerService.findAllCustomer(); model.addAttribute("customers", customersResponse); @@ -55,12 +55,12 @@ public String createCustomer( CustomerCreationRequest creationRequest, Model mod } - @GetMapping("/findCustomer") + @GetMapping("/find") public String findCustomer() { return "customer/findCustomer"; } - @PostMapping("/findCustomer") + @PostMapping("/find") public String findCustomer(CustomerUpdateRequest updateRequest, Model model) { try { CustomerResponse customerResponse = customerService.findDetailCustomer(updateRequest); @@ -70,4 +70,34 @@ public String findCustomer(CustomerUpdateRequest updateRequest, Model model) { } return "customer/customerInfo"; } + + @GetMapping("/delete") + public String deleteCustomer() { + return "customer/deleteCustomer"; + } + + @PostMapping("/delete") + public String deleteCustomer(CustomerUpdateRequest updateRequest, Model model) { + try { + customerService.deleteCustomer(updateRequest); + } catch(CustomerException | EmptyResultDataAccessException exception) { + return "redirect:/customer/delete"; + } + return "redirect:/"; + } + + @GetMapping("/deleteAll") + public String deleteAllCustomer() { + return "customer/deleteAll"; + } + + @PostMapping("/deleteAll") + public String deleteAllCustomers() { + try { + customerService.deleteAllCustomers(); + } catch(CustomerException | EmptyResultDataAccessException exception) { + return "redirect:/customer/deleteAll"; + } + return "redirect:/"; + } } diff --git a/src/main/resources/templates/customer/deleteAll.html b/src/main/resources/templates/customer/deleteAll.html new file mode 100644 index 0000000000..aaa4a9fe94 --- /dev/null +++ b/src/main/resources/templates/customer/deleteAll.html @@ -0,0 +1,17 @@ + + + + + Title + + +
    +
    +

    고객 전체 삭제

    + Home +
    + +
    +
    + + \ No newline at end of file diff --git a/src/main/resources/templates/customer/deleteCustomer.html b/src/main/resources/templates/customer/deleteCustomer.html new file mode 100644 index 0000000000..8551c68a48 --- /dev/null +++ b/src/main/resources/templates/customer/deleteCustomer.html @@ -0,0 +1,16 @@ + + + + Document + + +
    +
    +

    고객 삭제

    + Home +
    + +
    +
    + + \ No newline at end of file diff --git a/src/main/resources/templates/customer/findCustomer.html b/src/main/resources/templates/customer/findCustomer.html index 0d6911f025..24fc8bc237 100644 --- a/src/main/resources/templates/customer/findCustomer.html +++ b/src/main/resources/templates/customer/findCustomer.html @@ -11,7 +11,7 @@

    고객 정보 찾기

    Home
    -
    +
    \ No newline at end of file diff --git a/src/main/resources/templates/customer/menu.html b/src/main/resources/templates/customer/menu.html index a1a54d6ff4..9932fa0830 100644 --- a/src/main/resources/templates/customer/menu.html +++ b/src/main/resources/templates/customer/menu.html @@ -11,10 +11,10 @@

    회원 메뉴

    + +
    +
    +
    +
    +
    + +
    +
    +
    +
    + From 8e3e18c3289553ec9c9a81aa2757d1dbae2b2f04 Mon Sep 17 00:00:00 2001 From: parksey Date: Thu, 13 Jul 2023 17:39:17 +0900 Subject: [PATCH 05/28] =?UTF-8?q?feat:=20=ED=9A=8C=EC=9B=90=20=EC=9D=B4?= =?UTF-8?q?=EB=A9=94=EC=9D=BC=20=EC=97=85=EB=8D=B0=EC=9D=B4=ED=8A=B8=20con?= =?UTF-8?q?troller=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/request/CustomerUpdateRequest.java | 4 +++ .../web/customer/CustomerWebController.java | 28 ++++++++++++++++--- .../templates/customer/createCustomer.html | 4 +-- .../templates/customer/updateCustomer.html | 17 +++++++++++ src/main/resources/templates/global/form.html | 15 ++++++++++ 5 files changed, 62 insertions(+), 6 deletions(-) create mode 100644 src/main/resources/templates/customer/updateCustomer.html diff --git a/src/main/java/org/weekly/weekly/customer/dto/request/CustomerUpdateRequest.java b/src/main/java/org/weekly/weekly/customer/dto/request/CustomerUpdateRequest.java index 2167479380..dd4f8e924d 100644 --- a/src/main/java/org/weekly/weekly/customer/dto/request/CustomerUpdateRequest.java +++ b/src/main/java/org/weekly/weekly/customer/dto/request/CustomerUpdateRequest.java @@ -38,4 +38,8 @@ public String email() { public void setEmail(String email) { this.email = email; } + + public void setNewEmail(String newEmail) { + this.newEmail = newEmail; + } } diff --git a/src/main/java/org/weekly/weekly/web/customer/CustomerWebController.java b/src/main/java/org/weekly/weekly/web/customer/CustomerWebController.java index c232531c77..dc7cf9a60e 100644 --- a/src/main/java/org/weekly/weekly/web/customer/CustomerWebController.java +++ b/src/main/java/org/weekly/weekly/web/customer/CustomerWebController.java @@ -66,7 +66,8 @@ public String findCustomer(CustomerUpdateRequest updateRequest, Model model) { CustomerResponse customerResponse = customerService.findDetailCustomer(updateRequest); model.addAttribute("customer", customerResponse); } catch(CustomerException | EmptyResultDataAccessException exception) { - return "redirect:/customer/findCustomer"; + model.addAttribute("exception", new WebExceptionDto(exception)); + return "exception/exception"; } return "customer/customerInfo"; } @@ -81,7 +82,8 @@ public String deleteCustomer(CustomerUpdateRequest updateRequest, Model model) { try { customerService.deleteCustomer(updateRequest); } catch(CustomerException | EmptyResultDataAccessException exception) { - return "redirect:/customer/delete"; + model.addAttribute("exception", new WebExceptionDto(exception)); + return "exception/exception"; } return "redirect:/"; } @@ -92,12 +94,30 @@ public String deleteAllCustomer() { } @PostMapping("/deleteAll") - public String deleteAllCustomers() { + public String deleteAllCustomers(Model model) { try { customerService.deleteAllCustomers(); } catch(CustomerException | EmptyResultDataAccessException exception) { - return "redirect:/customer/deleteAll"; + model.addAttribute("exception", new WebExceptionDto(exception)); + return "exception/exception"; } return "redirect:/"; } + + @GetMapping("/update") + public String updateCustomer() { + return "customer/updateCustomer"; + } + + @PostMapping("/update") + public String updateCustomer(CustomerUpdateRequest updateRequest, Model model) { + try { + CustomerResponse customerResponse = customerService.updateCustomer(updateRequest); + model.addAttribute("customer", customerResponse); + } catch(CustomerException | EmptyResultDataAccessException exception) { + model.addAttribute("exception", new WebExceptionDto(exception)); + return "exception/exception"; + } + return "customer/customerInfo"; + } } diff --git a/src/main/resources/templates/customer/createCustomer.html b/src/main/resources/templates/customer/createCustomer.html index 7bc752c868..45f3f09d92 100644 --- a/src/main/resources/templates/customer/createCustomer.html +++ b/src/main/resources/templates/customer/createCustomer.html @@ -5,8 +5,8 @@
    -
    -

    고객 생성

    +
    +

    고객 생성

    Home
    diff --git a/src/main/resources/templates/customer/updateCustomer.html b/src/main/resources/templates/customer/updateCustomer.html new file mode 100644 index 0000000000..2f2e305744 --- /dev/null +++ b/src/main/resources/templates/customer/updateCustomer.html @@ -0,0 +1,17 @@ + + + + + Title + + +
    +
    +

    고객 정보 업데이트

    + Home +
    + +
    +
    + + \ No newline at end of file diff --git a/src/main/resources/templates/global/form.html b/src/main/resources/templates/global/form.html index 61aa0243f7..8ed8742075 100644 --- a/src/main/resources/templates/global/form.html +++ b/src/main/resources/templates/global/form.html @@ -29,6 +29,21 @@
    +
    +
    +
    + +
    + +
    +
    + +
    + +
    +
    +
    +
    From ac70f27e2d877e300a04f1232d70801775a37454 Mon Sep 17 00:00:00 2001 From: parksey Date: Thu, 13 Jul 2023 22:10:34 +0900 Subject: [PATCH 06/28] =?UTF-8?q?feat:=20=ED=9A=8C=EC=9B=90=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20api=20=EC=83=9D=EC=84=B1=20=EB=B0=8F=20getResult?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=EB=AA=85=20javaBeans=EC=97=90=20?= =?UTF-8?q?=EB=A7=9E=EC=A7=80=20=EC=95=8A=EA=B2=8C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weekly/VoucherManagementController.java | 6 ++--- .../api/customer/CustomerAPIController.java | 25 +++++++++++++++++++ .../dto/request/CustomerCreationRequest.java | 8 ++++++ .../dto/response/CustomerResponse.java | 2 +- .../dto/response/CustomersResponse.java | 4 +-- .../weekly/ui/CommandLineApplication.java | 3 +-- .../weekly/weekly/voucher/dto/Response.java | 2 +- .../dto/response/VoucherCreationResponse.java | 2 +- .../dto/response/VouchersResponse.java | 4 +-- 9 files changed, 43 insertions(+), 13 deletions(-) create mode 100644 src/main/java/org/weekly/weekly/api/customer/CustomerAPIController.java diff --git a/src/main/java/org/weekly/weekly/VoucherManagementController.java b/src/main/java/org/weekly/weekly/VoucherManagementController.java index 8cc14adbd3..6826e35cef 100644 --- a/src/main/java/org/weekly/weekly/VoucherManagementController.java +++ b/src/main/java/org/weekly/weekly/VoucherManagementController.java @@ -17,8 +17,6 @@ import org.weekly.weekly.voucher.dto.Response; import org.weekly.weekly.voucher.dto.request.VoucherCreationRequest; -import java.util.List; - @Component public class VoucherManagementController { private final Logger logger = LoggerFactory.getLogger(VoucherManagementController.class); @@ -83,13 +81,13 @@ private boolean processVoucherMenuSelection(VoucherMenu selectMenu) { private void handleVoucherCreation() { VoucherCreationRequest voucherCreationRequest = commandLineApplication.createVoucherFromInput(); Response response = voucherController.createVoucher(voucherCreationRequest); - logger.info("{}{}", PrintMessageType.CREATE_VOUCHER_SUCCESS.getMessage(),response.getResult()); + logger.info("{}{}", PrintMessageType.CREATE_VOUCHER_SUCCESS.getMessage(),response.result()); commandLineApplication.printResult(response); } private void handleVoucherSearch() { Response response = voucherController.getVouchers(); - logger.info("{}{}", PrintMessageType.FIND_ALL_VOUCHER_SUCCESS.getMessage(), response.getResult()); + logger.info("{}{}", PrintMessageType.FIND_ALL_VOUCHER_SUCCESS.getMessage(), response.result()); commandLineApplication.printResult(response); } diff --git a/src/main/java/org/weekly/weekly/api/customer/CustomerAPIController.java b/src/main/java/org/weekly/weekly/api/customer/CustomerAPIController.java new file mode 100644 index 0000000000..6354c28cf0 --- /dev/null +++ b/src/main/java/org/weekly/weekly/api/customer/CustomerAPIController.java @@ -0,0 +1,25 @@ +package org.weekly.weekly.api.customer; + +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import org.weekly.weekly.customer.dto.request.CustomerCreationRequest; +import org.weekly.weekly.customer.dto.response.CustomerResponse; +import org.weekly.weekly.customer.service.CustomerService; + +@RestController +@RequestMapping("/api/v1") +public class CustomerAPIController { + private final CustomerService customerService; + + public CustomerAPIController(CustomerService customerService) { + this.customerService = customerService; + } + + @PostMapping("/customer") + public CustomerResponse create(@RequestBody CustomerCreationRequest creationRequest) { + CustomerResponse customerResponse = customerService.createCustomer(creationRequest); + return customerResponse; + } +} diff --git a/src/main/java/org/weekly/weekly/customer/dto/request/CustomerCreationRequest.java b/src/main/java/org/weekly/weekly/customer/dto/request/CustomerCreationRequest.java index f21ac3cb5b..4b8fb368fc 100644 --- a/src/main/java/org/weekly/weekly/customer/dto/request/CustomerCreationRequest.java +++ b/src/main/java/org/weekly/weekly/customer/dto/request/CustomerCreationRequest.java @@ -27,4 +27,12 @@ public Customer toCustomer() { public String getEmail() { return email; } + + public void setName(String name) { + this.name = name; + } + + public void setEmail(String email) { + this.email = email; + } } diff --git a/src/main/java/org/weekly/weekly/customer/dto/response/CustomerResponse.java b/src/main/java/org/weekly/weekly/customer/dto/response/CustomerResponse.java index e53e8a5154..7435b4170c 100644 --- a/src/main/java/org/weekly/weekly/customer/dto/response/CustomerResponse.java +++ b/src/main/java/org/weekly/weekly/customer/dto/response/CustomerResponse.java @@ -34,7 +34,7 @@ public String getName() { } @Override - public String getResult() { + public String result() { return MessageFormat.format("[이름: {0}, 이메일: {1}, 생성 시기: {2}]", name, email, createAt); } } diff --git a/src/main/java/org/weekly/weekly/customer/dto/response/CustomersResponse.java b/src/main/java/org/weekly/weekly/customer/dto/response/CustomersResponse.java index 5bcb0fff5d..d56df04428 100644 --- a/src/main/java/org/weekly/weekly/customer/dto/response/CustomersResponse.java +++ b/src/main/java/org/weekly/weekly/customer/dto/response/CustomersResponse.java @@ -17,13 +17,13 @@ public CustomersResponse(List customers) { } @Override - public String getResult() { + public String result() { if (result.isEmpty()) { return PrintMessageType.NO_VOUCHER_DATAS.getMessage(); } StringBuilder resultBuilder = new StringBuilder(); - result.forEach(customerResponse-> resultBuilder.append(customerResponse.getResult()).append('\n')); + result.forEach(customerResponse-> resultBuilder.append(customerResponse.result()).append('\n')); return resultBuilder.toString(); } diff --git a/src/main/java/org/weekly/weekly/ui/CommandLineApplication.java b/src/main/java/org/weekly/weekly/ui/CommandLineApplication.java index 5798232ca1..967ab428ed 100644 --- a/src/main/java/org/weekly/weekly/ui/CommandLineApplication.java +++ b/src/main/java/org/weekly/weekly/ui/CommandLineApplication.java @@ -16,7 +16,6 @@ import org.weekly.weekly.voucher.dto.request.VoucherInfoRequest; import org.weekly.weekly.voucher.dto.request.VoucherCreationRequest; -import java.util.List; import java.util.function.Supplier; @Component @@ -103,7 +102,7 @@ public void printErrorMsg(String errorMsg) { } public void printResult(Response response) { - commandWriter.printReuslt(response.getResult()); + commandWriter.printReuslt(response.result()); } public void printDeleteMessage() { diff --git a/src/main/java/org/weekly/weekly/voucher/dto/Response.java b/src/main/java/org/weekly/weekly/voucher/dto/Response.java index 86c2795d86..991e1271d8 100644 --- a/src/main/java/org/weekly/weekly/voucher/dto/Response.java +++ b/src/main/java/org/weekly/weekly/voucher/dto/Response.java @@ -4,5 +4,5 @@ * 모든 반환 값에 대해 동일한 동작을 적용시키고 싶어서 이렇게 했습니다. */ public interface Response { - String getResult(); + String result(); } diff --git a/src/main/java/org/weekly/weekly/voucher/dto/response/VoucherCreationResponse.java b/src/main/java/org/weekly/weekly/voucher/dto/response/VoucherCreationResponse.java index f02d0703a6..9577dd6e41 100644 --- a/src/main/java/org/weekly/weekly/voucher/dto/response/VoucherCreationResponse.java +++ b/src/main/java/org/weekly/weekly/voucher/dto/response/VoucherCreationResponse.java @@ -21,7 +21,7 @@ public VoucherCreationResponse(Voucher voucher) { } @Override - public String getResult() { + public String result() { return MessageFormat.format("[ID: {0}, 금액: {1}, 등록일자: {2}, 유효기간: {3}]", id, amount, registrationDate, expirationDate); } } diff --git a/src/main/java/org/weekly/weekly/voucher/dto/response/VouchersResponse.java b/src/main/java/org/weekly/weekly/voucher/dto/response/VouchersResponse.java index 64b16be1ce..e554ec4978 100644 --- a/src/main/java/org/weekly/weekly/voucher/dto/response/VouchersResponse.java +++ b/src/main/java/org/weekly/weekly/voucher/dto/response/VouchersResponse.java @@ -16,14 +16,14 @@ public VouchersResponse(List vouchers) { .collect(Collectors.toUnmodifiableList()); } - public String getResult() { + public String result() { if (result.isEmpty()) { return PrintMessageType.NO_VOUCHER_DATAS.getMessage(); } StringBuilder resultBuilder = new StringBuilder(); - result.forEach(voucherResponse-> resultBuilder.append(voucherResponse.getResult()).append('\n')); + result.forEach(voucherResponse-> resultBuilder.append(voucherResponse.result()).append('\n')); return resultBuilder.toString(); } } From c7a949e05e9c3d2ce67a73055a31ab84a7815862 Mon Sep 17 00:00:00 2001 From: parksey Date: Fri, 14 Jul 2023 01:43:29 +0900 Subject: [PATCH 07/28] =?UTF-8?q?feat:=20=ED=9A=8C=EC=9B=90=EC=97=90=20?= =?UTF-8?q?=EB=8C=80=ED=95=9C=20CRUD=20API=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/customer/CustomerAPIController.java | 44 ++++++++++++++++--- .../customer/service/CustomerService.java | 16 ++++--- 2 files changed, 49 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/weekly/weekly/api/customer/CustomerAPIController.java b/src/main/java/org/weekly/weekly/api/customer/CustomerAPIController.java index 6354c28cf0..79e49bba31 100644 --- a/src/main/java/org/weekly/weekly/api/customer/CustomerAPIController.java +++ b/src/main/java/org/weekly/weekly/api/customer/CustomerAPIController.java @@ -1,11 +1,13 @@ package org.weekly.weekly.api.customer; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.http.HttpStatus; +import org.springframework.http.HttpStatusCode; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; import org.weekly.weekly.customer.dto.request.CustomerCreationRequest; +import org.weekly.weekly.customer.dto.request.CustomerUpdateRequest; import org.weekly.weekly.customer.dto.response.CustomerResponse; +import org.weekly.weekly.customer.dto.response.CustomersResponse; import org.weekly.weekly.customer.service.CustomerService; @RestController @@ -18,8 +20,38 @@ public CustomerAPIController(CustomerService customerService) { } @PostMapping("/customer") - public CustomerResponse create(@RequestBody CustomerCreationRequest creationRequest) { + public ResponseEntity create(@RequestBody CustomerCreationRequest creationRequest) { CustomerResponse customerResponse = customerService.createCustomer(creationRequest); - return customerResponse; + return new ResponseEntity<>(customerResponse, HttpStatus.CREATED); + } + + @GetMapping("/customers") + public ResponseEntity customers() { + CustomersResponse customersResponse = customerService.findAllCustomer(); + return new ResponseEntity<>(customersResponse.getCustomerResponses(), HttpStatus.OK); + } + + @GetMapping("/find/{customerEmail}") + public ResponseEntity findCustomer(@PathVariable String customerEmail) { + CustomerResponse customerResponse = customerService.findDetailCustomer(customerEmail); + return new ResponseEntity(customerResponse, HttpStatus.OK); + } + + @PatchMapping("/update") + public ResponseEntity updateCustomer(@RequestBody CustomerUpdateRequest customerUpdateRequest) { + CustomerResponse customerResponse = customerService.updateCustomer(customerUpdateRequest); + return new ResponseEntity<>(customerResponse, HttpStatus.OK); + } + + @DeleteMapping("/delete/{customerEmail}") + public ResponseEntity deleteCustomerr(@PathVariable String customerEmail) { + customerService.deleteCustomer(customerEmail); + return new ResponseEntity(HttpStatus.NO_CONTENT); + } + + @DeleteMapping("/delete/all") + public ResponseEntity deleteAll() { + customerService.deleteAllCustomers(); + return new ResponseEntity(HttpStatus.NO_CONTENT); } } diff --git a/src/main/java/org/weekly/weekly/customer/service/CustomerService.java b/src/main/java/org/weekly/weekly/customer/service/CustomerService.java index dcfa849365..73cb0c03e9 100644 --- a/src/main/java/org/weekly/weekly/customer/service/CustomerService.java +++ b/src/main/java/org/weekly/weekly/customer/service/CustomerService.java @@ -33,21 +33,27 @@ public CustomerResponse createCustomer(CustomerCreationRequest creationRequest) @Transactional public void deleteCustomer(CustomerUpdateRequest updateRequest) { - String email = updateRequest.email(); - customerRepository.deleteByEmail(email); + deleteCustomer(updateRequest.email()); + } + + public void deleteCustomer(String customerEmail) { + customerRepository.deleteByEmail(customerEmail); } public void deleteAllCustomers() { customerRepository.deleteAll(); } - public CustomerResponse findDetailCustomer(CustomerUpdateRequest updateRequest) { - String email = updateRequest.email(); - Customer customer = validateCustomerExistAndGet(email); + return findDetailCustomer(updateRequest.email()); + } + + public CustomerResponse findDetailCustomer(String customerEmail) { + Customer customer = validateCustomerExistAndGet(customerEmail); return CustomerResponse.of(customer); } + public CustomersResponse findAllCustomer() { List customers = customerRepository.findAll(); return new CustomersResponse(customers); From 0a9e25d38ec92e7e79f7ed7372be025308ba5e5e Mon Sep 17 00:00:00 2001 From: parksey Date: Fri, 14 Jul 2023 02:35:56 +0900 Subject: [PATCH 08/28] =?UTF-8?q?feat:=20Voucher=20web=20controller=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/voucher/VoucherWebController.java | 47 +++++++++++++++++++ .../resources/templates/voucher/create.html | 0 .../resources/templates/voucher/vouchers.html | 0 3 files changed, 47 insertions(+) create mode 100644 src/main/java/org/weekly/weekly/web/voucher/VoucherWebController.java create mode 100644 src/main/resources/templates/voucher/create.html create mode 100644 src/main/resources/templates/voucher/vouchers.html diff --git a/src/main/java/org/weekly/weekly/web/voucher/VoucherWebController.java b/src/main/java/org/weekly/weekly/web/voucher/VoucherWebController.java new file mode 100644 index 0000000000..d5c6a19643 --- /dev/null +++ b/src/main/java/org/weekly/weekly/web/voucher/VoucherWebController.java @@ -0,0 +1,47 @@ +package org.weekly.weekly.web.voucher; + +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.weekly.weekly.voucher.dto.request.VoucherCreationRequest; +import org.weekly.weekly.voucher.dto.response.VoucherCreationResponse; +import org.weekly.weekly.voucher.dto.response.VouchersResponse; +import org.weekly.weekly.voucher.exception.VoucherException; +import org.weekly.weekly.voucher.service.VoucherService; +import org.weekly.weekly.web.exception.WebExceptionDto; + +@Controller +@RequestMapping("/voucher") +public class VoucherWebController { + private final VoucherService voucherService; + + + public VoucherWebController(VoucherService voucherService) { + this.voucherService = voucherService; + } + + @PostMapping("/create") + public String createVoucher(@ModelAttribute VoucherCreationRequest voucherCreationRequest, Model model) { + try { + VoucherCreationResponse voucherCreationResponse = voucherService.insertVoucher(voucherCreationRequest); + model.addAttribute("voucher", voucherCreationResponse); + } catch( VoucherException voucherException) { + model.addAttribute("exception", new WebExceptionDto(voucherException)); + } + return "voucher/create"; + } + + @GetMapping("/vouchers") + public String createVoucher(Model model) { + try { + VouchersResponse vouchersResponse = voucherService.getVouchers(); + model.addAttribute("vouchers", vouchersResponse); + } catch( VoucherException voucherException) { + model.addAttribute("exception", new WebExceptionDto(voucherException)); + } + return "voucher/vouchers"; + } +} diff --git a/src/main/resources/templates/voucher/create.html b/src/main/resources/templates/voucher/create.html new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/main/resources/templates/voucher/vouchers.html b/src/main/resources/templates/voucher/vouchers.html new file mode 100644 index 0000000000..e69de29bb2 From c9db3f9997de8705f2c827cab63c21f78d936819 Mon Sep 17 00:00:00 2001 From: parksey Date: Fri, 14 Jul 2023 15:35:54 +0900 Subject: [PATCH 09/28] =?UTF-8?q?feat:=20Voucher=20webcontroller=20?= =?UTF-8?q?=EC=98=88=EC=99=B8=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/response/CustomersResponse.java | 2 +- .../dto/request/VoucherCreationRequest.java | 16 +++++++- .../dto/request/VoucherInfoRequest.java | 15 ++++++-- .../dto/response/VoucherCreationResponse.java | 23 ++++++++++++ .../dto/response/VouchersResponse.java | 6 ++- .../voucher/exception/VoucherValidator.java | 2 +- .../web/voucher/VoucherWebController.java | 15 +++++++- src/main/resources/templates/global/form.html | 37 +++++++++++++++++++ .../resources/templates/global/voucher.html | 23 ++++++++++++ .../resources/templates/voucher/create.html | 17 +++++++++ .../resources/templates/voucher/menu.html | 26 +++++++++++++ .../resources/templates/voucher/vouchers.html | 25 +++++++++++++ 12 files changed, 198 insertions(+), 9 deletions(-) create mode 100644 src/main/resources/templates/global/voucher.html create mode 100644 src/main/resources/templates/voucher/menu.html diff --git a/src/main/java/org/weekly/weekly/customer/dto/response/CustomersResponse.java b/src/main/java/org/weekly/weekly/customer/dto/response/CustomersResponse.java index d56df04428..3ae346593e 100644 --- a/src/main/java/org/weekly/weekly/customer/dto/response/CustomersResponse.java +++ b/src/main/java/org/weekly/weekly/customer/dto/response/CustomersResponse.java @@ -13,7 +13,7 @@ public class CustomersResponse implements Response { public CustomersResponse(List customers) { result = customers.stream() .map(CustomerResponse::of) - .collect(Collectors.toUnmodifiableList()); + .toList(); } @Override diff --git a/src/main/java/org/weekly/weekly/voucher/dto/request/VoucherCreationRequest.java b/src/main/java/org/weekly/weekly/voucher/dto/request/VoucherCreationRequest.java index 76c137ed6e..c93cae63a8 100644 --- a/src/main/java/org/weekly/weekly/voucher/dto/request/VoucherCreationRequest.java +++ b/src/main/java/org/weekly/weekly/voucher/dto/request/VoucherCreationRequest.java @@ -8,14 +8,26 @@ import java.util.UUID; public class VoucherCreationRequest { - private final VoucherInfoRequest voucherInfoRequest; - private final DiscountType discountType; + private VoucherInfoRequest voucherInfoRequest; + private DiscountType discountType; public VoucherCreationRequest(VoucherInfoRequest voucherInfoRequest, DiscountType discountType) { this.voucherInfoRequest = voucherInfoRequest; this.discountType = discountType; } + public VoucherInfoRequest getVoucherInfoRequest() { + return voucherInfoRequest; + } + + public void setVoucherInfoRequest(VoucherInfoRequest voucherInfoRequest) { + this.voucherInfoRequest = voucherInfoRequest; + } + + public DiscountType getDiscountType() { + return discountType; + } + public Voucher toVoucher() { UUID id = UUID.randomUUID(); long amount = voucherInfoRequest.getAmount(); diff --git a/src/main/java/org/weekly/weekly/voucher/dto/request/VoucherInfoRequest.java b/src/main/java/org/weekly/weekly/voucher/dto/request/VoucherInfoRequest.java index 3aecb596c7..06f2bd48be 100644 --- a/src/main/java/org/weekly/weekly/voucher/dto/request/VoucherInfoRequest.java +++ b/src/main/java/org/weekly/weekly/voucher/dto/request/VoucherInfoRequest.java @@ -7,11 +7,12 @@ public class VoucherInfoRequest { private static final int AMOUNT_NO = 0; private static final int EXPIRATION = 1; - private final long amount; - private final long expiration; + private long amount; + private long expiration; + public VoucherInfoRequest() {} - private VoucherInfoRequest(long amount, long expiration) { + public VoucherInfoRequest(long amount, long expiration) { this.amount = amount; this.expiration = expiration; } @@ -33,6 +34,14 @@ public long getExpiration() { return expiration; } + public void setAmount(long amount) { + this.amount = amount; + } + + public void setExpiration(long expiration) { + this.expiration = expiration; + } + private static void checkReadVoucherException(String[] inputs) { InputValidator.notVoucherInputSize(inputs); InputValidator.notNumber(inputs); diff --git a/src/main/java/org/weekly/weekly/voucher/dto/response/VoucherCreationResponse.java b/src/main/java/org/weekly/weekly/voucher/dto/response/VoucherCreationResponse.java index 9577dd6e41..82f9302e9d 100644 --- a/src/main/java/org/weekly/weekly/voucher/dto/response/VoucherCreationResponse.java +++ b/src/main/java/org/weekly/weekly/voucher/dto/response/VoucherCreationResponse.java @@ -12,12 +12,35 @@ public class VoucherCreationResponse implements Response { private final LocalDate registrationDate; private final LocalDate expirationDate; private final long amount; + private final String voucherType; public VoucherCreationResponse(Voucher voucher) { this.id = voucher.getVoucherId(); this.registrationDate = voucher.getRegistrationDate(); this.expirationDate = voucher.getExpirationDate(); this.amount = voucher.getAmount(); + this.voucherType = voucher.getDiscountType().name(); + + } + + public UUID getId() { + return id; + } + + public long getAmount() { + return amount; + } + + public LocalDate getExpirationDate() { + return expirationDate; + } + + public LocalDate getRegistrationDate() { + return registrationDate; + } + + public String getVoucherType() { + return voucherType; } @Override diff --git a/src/main/java/org/weekly/weekly/voucher/dto/response/VouchersResponse.java b/src/main/java/org/weekly/weekly/voucher/dto/response/VouchersResponse.java index e554ec4978..ed49133c23 100644 --- a/src/main/java/org/weekly/weekly/voucher/dto/response/VouchersResponse.java +++ b/src/main/java/org/weekly/weekly/voucher/dto/response/VouchersResponse.java @@ -13,7 +13,11 @@ public class VouchersResponse implements Response { public VouchersResponse(List vouchers) { this.result = vouchers.stream() .map(VoucherCreationResponse::new) - .collect(Collectors.toUnmodifiableList()); + .toList(); + } + + public List getResult() { + return result; } public String result() { diff --git a/src/main/java/org/weekly/weekly/voucher/exception/VoucherValidator.java b/src/main/java/org/weekly/weekly/voucher/exception/VoucherValidator.java index 872558d980..0dc6518d71 100644 --- a/src/main/java/org/weekly/weekly/voucher/exception/VoucherValidator.java +++ b/src/main/java/org/weekly/weekly/voucher/exception/VoucherValidator.java @@ -27,7 +27,7 @@ public static void validateAmount(DiscountType discountType, long amount) { return; } - notRange(amount, input -> input < RANGE_START || input > RANGE_END); + notRange(amount, input -> input <= RANGE_START || input > RANGE_END); } private static void notRange(long userInput, LongPredicate ifCase) { diff --git a/src/main/java/org/weekly/weekly/web/voucher/VoucherWebController.java b/src/main/java/org/weekly/weekly/web/voucher/VoucherWebController.java index d5c6a19643..65ae4c466b 100644 --- a/src/main/java/org/weekly/weekly/web/voucher/VoucherWebController.java +++ b/src/main/java/org/weekly/weekly/web/voucher/VoucherWebController.java @@ -23,6 +23,11 @@ public VoucherWebController(VoucherService voucherService) { this.voucherService = voucherService; } + @GetMapping("/menu") + public String menu() { + return "voucher/menu"; + } + @PostMapping("/create") public String createVoucher(@ModelAttribute VoucherCreationRequest voucherCreationRequest, Model model) { try { @@ -30,17 +35,25 @@ public String createVoucher(@ModelAttribute VoucherCreationRequest voucherCreati model.addAttribute("voucher", voucherCreationResponse); } catch( VoucherException voucherException) { model.addAttribute("exception", new WebExceptionDto(voucherException)); + return "exception/exception"; } + return "redirect:/"; + } + + @GetMapping("/create") + public String createVoucher(Model model) { + model.addAttribute("voucherCreationRequest", new VoucherCreationRequest(null, null)); return "voucher/create"; } @GetMapping("/vouchers") - public String createVoucher(Model model) { + public String getVouchers(Model model) { try { VouchersResponse vouchersResponse = voucherService.getVouchers(); model.addAttribute("vouchers", vouchersResponse); } catch( VoucherException voucherException) { model.addAttribute("exception", new WebExceptionDto(voucherException)); + return "exception/exception"; } return "voucher/vouchers"; } diff --git a/src/main/resources/templates/global/form.html b/src/main/resources/templates/global/form.html index 8ed8742075..50e8762f08 100644 --- a/src/main/resources/templates/global/form.html +++ b/src/main/resources/templates/global/form.html @@ -13,6 +13,7 @@
    +
    @@ -66,3 +67,39 @@
    + +
    +
    +
    + +
    +
    +
    +
    + +
    +
    +
    +
    + + +
    +
    +
    + +
    + +
    +
    + +
    + +
    +
    + +
    +
    +
    \ No newline at end of file diff --git a/src/main/resources/templates/global/voucher.html b/src/main/resources/templates/global/voucher.html new file mode 100644 index 0000000000..0a0b0a1ba5 --- /dev/null +++ b/src/main/resources/templates/global/voucher.html @@ -0,0 +1,23 @@ +
    + + + 번호 + 바우처 아이디 + 할인가 + 바우처 타입 + 등록일 + 만료일 + + +
    + + + + + + + + + + + diff --git a/src/main/resources/templates/voucher/create.html b/src/main/resources/templates/voucher/create.html index e69de29bb2..0c4544cef7 100644 --- a/src/main/resources/templates/voucher/create.html +++ b/src/main/resources/templates/voucher/create.html @@ -0,0 +1,17 @@ + + + + Document + + +
    +
    +

    바우처 생성

    + Home +
    + +
    +
    + + + diff --git a/src/main/resources/templates/voucher/menu.html b/src/main/resources/templates/voucher/menu.html new file mode 100644 index 0000000000..b0b195cdd8 --- /dev/null +++ b/src/main/resources/templates/voucher/menu.html @@ -0,0 +1,26 @@ + + + + Document + + +
    + +

    회원 메뉴

    + + + +
    + + \ No newline at end of file diff --git a/src/main/resources/templates/voucher/vouchers.html b/src/main/resources/templates/voucher/vouchers.html index e69de29bb2..5e6a5a984c 100644 --- a/src/main/resources/templates/voucher/vouchers.html +++ b/src/main/resources/templates/voucher/vouchers.html @@ -0,0 +1,25 @@ + + + + + Document + + +
    +
    +

    바우처 리스트

    + Home +
    +
    + + + + + + + +
    +
    +
    + + \ No newline at end of file From cff3b44c0c191996346a9deccd286f54ae24f485 Mon Sep 17 00:00:00 2001 From: parksey Date: Fri, 14 Jul 2023 16:04:49 +0900 Subject: [PATCH 10/28] =?UTF-8?q?refactor:=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20=EA=B3=B5=EB=B0=B1=20=EB=B0=8F=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EC=88=9C=EC=84=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/customer/CustomerAPIController.java | 21 ++++++++++--------- .../controller/CustomerController.java | 2 -- .../dto/request/CustomerUpdateRequest.java | 5 ++--- .../dto/response/CustomersResponse.java | 1 - .../customer/exception/CustomerValidator.java | 5 +++-- .../repository/CustomerRepository.java | 1 - .../repository/JdbcCustomerRepository.java | 11 ++++------ .../weekly/ui/exception/InputValidator.java | 5 +++-- .../weekly/ui/reader/CommandReader.java | 2 -- .../weekly/weekly/ui/reader/ConsoleWrap.java | 6 +++--- .../org/weekly/weekly/util/CustomerMenu.java | 4 +++- .../org/weekly/weekly/util/VoucherMenu.java | 4 +++- .../voucher/controller/VoucherController.java | 3 --- .../weekly/voucher/domain/DiscountType.java | 2 -- .../voucher/domain/PercentDiscount.java | 2 +- .../weekly/weekly/voucher/domain/Voucher.java | 5 +---- .../dto/request/VoucherCreationRequest.java | 3 +-- .../dto/request/VoucherInfoRequest.java | 10 ++++----- .../dto/response/VoucherCreationResponse.java | 1 - .../dto/response/VouchersResponse.java | 1 - .../repository/JdbcVoucherRepository.java | 21 ++++++++----------- .../voucher/repository/VoucherRepository.java | 4 ---- .../voucher/service/VoucherService.java | 2 -- src/main/resources/templates/index.html | 3 +++ 24 files changed, 52 insertions(+), 72 deletions(-) diff --git a/src/main/java/org/weekly/weekly/api/customer/CustomerAPIController.java b/src/main/java/org/weekly/weekly/api/customer/CustomerAPIController.java index 79e49bba31..c590965309 100644 --- a/src/main/java/org/weekly/weekly/api/customer/CustomerAPIController.java +++ b/src/main/java/org/weekly/weekly/api/customer/CustomerAPIController.java @@ -1,7 +1,6 @@ package org.weekly.weekly.api.customer; import org.springframework.http.HttpStatus; -import org.springframework.http.HttpStatusCode; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import org.weekly.weekly.customer.dto.request.CustomerCreationRequest; @@ -10,6 +9,8 @@ import org.weekly.weekly.customer.dto.response.CustomersResponse; import org.weekly.weekly.customer.service.CustomerService; +import java.util.List; + @RestController @RequestMapping("/api/v1") public class CustomerAPIController { @@ -20,38 +21,38 @@ public CustomerAPIController(CustomerService customerService) { } @PostMapping("/customer") - public ResponseEntity create(@RequestBody CustomerCreationRequest creationRequest) { + public ResponseEntity create(@RequestBody CustomerCreationRequest creationRequest) { CustomerResponse customerResponse = customerService.createCustomer(creationRequest); return new ResponseEntity<>(customerResponse, HttpStatus.CREATED); } @GetMapping("/customers") - public ResponseEntity customers() { + public ResponseEntity> customers() { CustomersResponse customersResponse = customerService.findAllCustomer(); return new ResponseEntity<>(customersResponse.getCustomerResponses(), HttpStatus.OK); } @GetMapping("/find/{customerEmail}") - public ResponseEntity findCustomer(@PathVariable String customerEmail) { + public ResponseEntity findCustomer(@PathVariable String customerEmail) { CustomerResponse customerResponse = customerService.findDetailCustomer(customerEmail); - return new ResponseEntity(customerResponse, HttpStatus.OK); + return new ResponseEntity<>(customerResponse, HttpStatus.OK); } @PatchMapping("/update") - public ResponseEntity updateCustomer(@RequestBody CustomerUpdateRequest customerUpdateRequest) { + public ResponseEntity updateCustomer(@RequestBody CustomerUpdateRequest customerUpdateRequest) { CustomerResponse customerResponse = customerService.updateCustomer(customerUpdateRequest); return new ResponseEntity<>(customerResponse, HttpStatus.OK); } @DeleteMapping("/delete/{customerEmail}") - public ResponseEntity deleteCustomerr(@PathVariable String customerEmail) { + public ResponseEntity deleteCustomerr(@PathVariable String customerEmail) { customerService.deleteCustomer(customerEmail); - return new ResponseEntity(HttpStatus.NO_CONTENT); + return new ResponseEntity<>(HttpStatus.NO_CONTENT); } @DeleteMapping("/delete/all") - public ResponseEntity deleteAll() { + public ResponseEntity deleteAll() { customerService.deleteAllCustomers(); - return new ResponseEntity(HttpStatus.NO_CONTENT); + return new ResponseEntity<>(HttpStatus.NO_CONTENT); } } diff --git a/src/main/java/org/weekly/weekly/customer/controller/CustomerController.java b/src/main/java/org/weekly/weekly/customer/controller/CustomerController.java index 83abc90697..d2b6af0fb1 100644 --- a/src/main/java/org/weekly/weekly/customer/controller/CustomerController.java +++ b/src/main/java/org/weekly/weekly/customer/controller/CustomerController.java @@ -7,8 +7,6 @@ import org.weekly.weekly.customer.dto.response.CustomersResponse; import org.weekly.weekly.customer.service.CustomerService; -import java.util.List; - @Controller public class CustomerController { diff --git a/src/main/java/org/weekly/weekly/customer/dto/request/CustomerUpdateRequest.java b/src/main/java/org/weekly/weekly/customer/dto/request/CustomerUpdateRequest.java index dd4f8e924d..7fecabbebf 100644 --- a/src/main/java/org/weekly/weekly/customer/dto/request/CustomerUpdateRequest.java +++ b/src/main/java/org/weekly/weekly/customer/dto/request/CustomerUpdateRequest.java @@ -1,6 +1,5 @@ package org.weekly.weekly.customer.dto.request; -import org.springframework.beans.factory.annotation.Autowired; import org.weekly.weekly.ui.exception.InputValidator; public class CustomerUpdateRequest { @@ -13,17 +12,16 @@ private CustomerUpdateRequest(String email, String afterEmail) { this.email = email; this.newEmail = afterEmail; } + private CustomerUpdateRequest(String email) { this.email = email; } - public static CustomerUpdateRequest of(String email) { InputValidator.isEmpty(email); return new CustomerUpdateRequest(email); } - public static CustomerUpdateRequest of(String email, String afterEmail) { InputValidator.isEmpty(email); InputValidator.isEmpty(afterEmail); @@ -33,6 +31,7 @@ public static CustomerUpdateRequest of(String email, String afterEmail) { public String email() { return email; } + public String newEmail() {return newEmail;} public void setEmail(String email) { diff --git a/src/main/java/org/weekly/weekly/customer/dto/response/CustomersResponse.java b/src/main/java/org/weekly/weekly/customer/dto/response/CustomersResponse.java index 3ae346593e..6b1d966266 100644 --- a/src/main/java/org/weekly/weekly/customer/dto/response/CustomersResponse.java +++ b/src/main/java/org/weekly/weekly/customer/dto/response/CustomersResponse.java @@ -5,7 +5,6 @@ import org.weekly.weekly.voucher.dto.Response; import java.util.List; -import java.util.stream.Collectors; public class CustomersResponse implements Response { List result; diff --git a/src/main/java/org/weekly/weekly/customer/exception/CustomerValidator.java b/src/main/java/org/weekly/weekly/customer/exception/CustomerValidator.java index d30f721d32..8a11a8f573 100644 --- a/src/main/java/org/weekly/weekly/customer/exception/CustomerValidator.java +++ b/src/main/java/org/weekly/weekly/customer/exception/CustomerValidator.java @@ -5,11 +5,12 @@ import java.util.regex.Pattern; public class CustomerValidator { + private static final String EMAIL_FORMAT = "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,3}$"; - public CustomerValidator() { + private CustomerValidator() { throw new CustomerException(ExceptionMsg.UTIL_CLASS); } - private static final String EMAIL_FORMAT = "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,3}$"; + public static void validateEmailFormat(String email) { if (!Pattern.matches(EMAIL_FORMAT, email)) { throw new CustomerException(ExceptionMsg.NOT_EMAIL_FORMAT); diff --git a/src/main/java/org/weekly/weekly/customer/repository/CustomerRepository.java b/src/main/java/org/weekly/weekly/customer/repository/CustomerRepository.java index a8a7352288..788543ce38 100644 --- a/src/main/java/org/weekly/weekly/customer/repository/CustomerRepository.java +++ b/src/main/java/org/weekly/weekly/customer/repository/CustomerRepository.java @@ -11,7 +11,6 @@ public interface CustomerRepository { void deleteAll(); Optional findByEmail(String email); List findAll(); - Customer update(Customer customer, String newEmail); } diff --git a/src/main/java/org/weekly/weekly/customer/repository/JdbcCustomerRepository.java b/src/main/java/org/weekly/weekly/customer/repository/JdbcCustomerRepository.java index 33916e3e2c..dfa9152808 100644 --- a/src/main/java/org/weekly/weekly/customer/repository/JdbcCustomerRepository.java +++ b/src/main/java/org/weekly/weekly/customer/repository/JdbcCustomerRepository.java @@ -27,6 +27,10 @@ public JdbcCustomerRepository(DataSource dataSource) { this.jdbcTemplate = new JdbcTemplate(dataSource); } + private static UUID toUUID(byte[] bytes) { + var buffer = ByteBuffer.wrap(bytes); + return new UUID(buffer.getLong(), buffer.getLong()); + } @Override public Customer insert(Customer customer) { @@ -89,12 +93,6 @@ public Customer update(Customer customer, String newEmail) { return customer; } - - private static UUID toUUID(byte[] bytes) { - var buffer = ByteBuffer.wrap(bytes); - return new UUID(buffer.getLong(), buffer.getLong()); - } - private Customer mapToCustomer(ResultSet resultSet) throws SQLException { UUID customerId = toUUID(resultSet.getBytes("customer_id")); String name = resultSet.getString("name"); @@ -104,7 +102,6 @@ private Customer mapToCustomer(ResultSet resultSet) throws SQLException { return new Customer(customerId, name, email, createAt); } - private byte[] uuidToBytes(UUID voucherId) { return voucherId.toString().getBytes(); } diff --git a/src/main/java/org/weekly/weekly/ui/exception/InputValidator.java b/src/main/java/org/weekly/weekly/ui/exception/InputValidator.java index 0c4c3ef6c0..865303e990 100644 --- a/src/main/java/org/weekly/weekly/ui/exception/InputValidator.java +++ b/src/main/java/org/weekly/weekly/ui/exception/InputValidator.java @@ -6,14 +6,15 @@ import java.util.Arrays; public class InputValidator { - public InputValidator() { + + private InputValidator() { throw new InputException(ExceptionMsg.UTIL_CLASS); } private static final int VOUCHER_INPUT_SIZE = 2; public static void isEmpty(String userInput) { if (userInput == null || userInput.isBlank()) { - throw new RuntimeException(ExceptionMsg.EMPTY.getMsg()); + throw new InputException(ExceptionMsg.EMPTY); } } diff --git a/src/main/java/org/weekly/weekly/ui/reader/CommandReader.java b/src/main/java/org/weekly/weekly/ui/reader/CommandReader.java index 9ba5cf6055..2543b0e52a 100644 --- a/src/main/java/org/weekly/weekly/ui/reader/CommandReader.java +++ b/src/main/java/org/weekly/weekly/ui/reader/CommandReader.java @@ -1,7 +1,5 @@ package org.weekly.weekly.ui.reader; -import java.io.IOException; - public interface CommandReader { String readLine(); } diff --git a/src/main/java/org/weekly/weekly/ui/reader/ConsoleWrap.java b/src/main/java/org/weekly/weekly/ui/reader/ConsoleWrap.java index b4e02e6bb8..6ef24823ab 100644 --- a/src/main/java/org/weekly/weekly/ui/reader/ConsoleWrap.java +++ b/src/main/java/org/weekly/weekly/ui/reader/ConsoleWrap.java @@ -8,14 +8,14 @@ @Component @ConditionalOnProperty(value="command.read", havingValue = "console") public class ConsoleWrap implements CommandReader{ - private final Console consoleWrap; + private final Console console; public ConsoleWrap() { - consoleWrap = System.console(); + console = System.console(); } @Override public String readLine() { - return consoleWrap.readLine(); + return console.readLine(); } } diff --git a/src/main/java/org/weekly/weekly/util/CustomerMenu.java b/src/main/java/org/weekly/weekly/util/CustomerMenu.java index 14bcd473fe..f8ad92b79f 100644 --- a/src/main/java/org/weekly/weekly/util/CustomerMenu.java +++ b/src/main/java/org/weekly/weekly/util/CustomerMenu.java @@ -1,5 +1,7 @@ package org.weekly.weekly.util; +import org.weekly.weekly.customer.exception.CustomerException; + import java.util.Arrays; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -29,7 +31,7 @@ public static CustomerMenu getMenu(String userInput) { if (CUSTOMER_MENU_MAP.containsKey(userInput)) { return CUSTOMER_MENU_MAP.get(userInput); } - throw new RuntimeException(ExceptionMsg.NOT_MENU.getMsg()); + throw new CustomerException(ExceptionMsg.NOT_MENU); } @Override diff --git a/src/main/java/org/weekly/weekly/util/VoucherMenu.java b/src/main/java/org/weekly/weekly/util/VoucherMenu.java index a9b4e621ce..738d71afb1 100644 --- a/src/main/java/org/weekly/weekly/util/VoucherMenu.java +++ b/src/main/java/org/weekly/weekly/util/VoucherMenu.java @@ -1,5 +1,7 @@ package org.weekly.weekly.util; +import org.weekly.weekly.voucher.exception.VoucherException; + import java.util.Arrays; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -25,7 +27,7 @@ public static VoucherMenu getMenu(String userInput) { if (VOUCHER_MENU_MAP.containsKey(userInput)) { return VOUCHER_MENU_MAP.get(userInput); } - throw new RuntimeException(ExceptionMsg.NOT_MENU.getMsg()); + throw new VoucherException(ExceptionMsg.NOT_MENU); } @Override diff --git a/src/main/java/org/weekly/weekly/voucher/controller/VoucherController.java b/src/main/java/org/weekly/weekly/voucher/controller/VoucherController.java index 5e9c1e2804..e1b25c0f9e 100644 --- a/src/main/java/org/weekly/weekly/voucher/controller/VoucherController.java +++ b/src/main/java/org/weekly/weekly/voucher/controller/VoucherController.java @@ -9,15 +9,12 @@ @Controller public class VoucherController { - private final Logger logger = LoggerFactory.getLogger(VoucherController.class); private final VoucherService voucherService; - public VoucherController(VoucherService voucherService) { this.voucherService = voucherService; } - public Response createVoucher(VoucherCreationRequest voucherCreationRequest) { return voucherService.insertVoucher(voucherCreationRequest); } diff --git a/src/main/java/org/weekly/weekly/voucher/domain/DiscountType.java b/src/main/java/org/weekly/weekly/voucher/domain/DiscountType.java index d27a2b602f..c3e765c6d0 100644 --- a/src/main/java/org/weekly/weekly/voucher/domain/DiscountType.java +++ b/src/main/java/org/weekly/weekly/voucher/domain/DiscountType.java @@ -56,10 +56,8 @@ public Discount getNewInstance() { } catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException exception) { throw new VoucherException(ExceptionMsg.NOT_FOUND); } - } - public String getSelectMessage() { return selectMessage; } diff --git a/src/main/java/org/weekly/weekly/voucher/domain/PercentDiscount.java b/src/main/java/org/weekly/weekly/voucher/domain/PercentDiscount.java index 8670ab08ca..0ff80bba02 100644 --- a/src/main/java/org/weekly/weekly/voucher/domain/PercentDiscount.java +++ b/src/main/java/org/weekly/weekly/voucher/domain/PercentDiscount.java @@ -1,7 +1,7 @@ package org.weekly.weekly.voucher.domain; public class PercentDiscount implements Discount{ - private final int PERCENT = 100; + private static final int PERCENT = 100; @Override public long applyDiscount(long beforeAmount, long discountAmount) { return beforeAmount - beforeAmount * discountAmount / PERCENT; diff --git a/src/main/java/org/weekly/weekly/voucher/domain/Voucher.java b/src/main/java/org/weekly/weekly/voucher/domain/Voucher.java index f5242f721f..4b57c4e9c2 100644 --- a/src/main/java/org/weekly/weekly/voucher/domain/Voucher.java +++ b/src/main/java/org/weekly/weekly/voucher/domain/Voucher.java @@ -1,10 +1,7 @@ package org.weekly.weekly.voucher.domain; -import org.weekly.weekly.util.ExceptionMsg; -import org.weekly.weekly.voucher.exception.VoucherException; import org.weekly.weekly.voucher.exception.VoucherValidator; -import java.text.MessageFormat; import java.time.LocalDate; import java.util.UUID; @@ -17,7 +14,7 @@ public class Voucher { private long amount; - private Discount discount; + private final Discount discount; public Voucher(UUID voucherId, long amount, LocalDate registrationDate, LocalDate expirationDate, Discount discount) { diff --git a/src/main/java/org/weekly/weekly/voucher/dto/request/VoucherCreationRequest.java b/src/main/java/org/weekly/weekly/voucher/dto/request/VoucherCreationRequest.java index c93cae63a8..b1ea728e75 100644 --- a/src/main/java/org/weekly/weekly/voucher/dto/request/VoucherCreationRequest.java +++ b/src/main/java/org/weekly/weekly/voucher/dto/request/VoucherCreationRequest.java @@ -2,14 +2,13 @@ import org.weekly.weekly.voucher.domain.DiscountType; import org.weekly.weekly.voucher.domain.Voucher; -import org.weekly.weekly.voucher.exception.VoucherException; import java.time.LocalDate; import java.util.UUID; public class VoucherCreationRequest { private VoucherInfoRequest voucherInfoRequest; - private DiscountType discountType; + private final DiscountType discountType; public VoucherCreationRequest(VoucherInfoRequest voucherInfoRequest, DiscountType discountType) { this.voucherInfoRequest = voucherInfoRequest; diff --git a/src/main/java/org/weekly/weekly/voucher/dto/request/VoucherInfoRequest.java b/src/main/java/org/weekly/weekly/voucher/dto/request/VoucherInfoRequest.java index 06f2bd48be..dadcc98e2d 100644 --- a/src/main/java/org/weekly/weekly/voucher/dto/request/VoucherInfoRequest.java +++ b/src/main/java/org/weekly/weekly/voucher/dto/request/VoucherInfoRequest.java @@ -26,6 +26,11 @@ public static VoucherInfoRequest of(String userInput) { Long.parseLong(inputs[EXPIRATION].trim())); } + private static void checkReadVoucherException(String[] inputs) { + InputValidator.notVoucherInputSize(inputs); + InputValidator.notNumber(inputs); + } + public long getAmount() { return amount; } @@ -41,9 +46,4 @@ public void setAmount(long amount) { public void setExpiration(long expiration) { this.expiration = expiration; } - - private static void checkReadVoucherException(String[] inputs) { - InputValidator.notVoucherInputSize(inputs); - InputValidator.notNumber(inputs); - } } diff --git a/src/main/java/org/weekly/weekly/voucher/dto/response/VoucherCreationResponse.java b/src/main/java/org/weekly/weekly/voucher/dto/response/VoucherCreationResponse.java index 82f9302e9d..1be8a5f583 100644 --- a/src/main/java/org/weekly/weekly/voucher/dto/response/VoucherCreationResponse.java +++ b/src/main/java/org/weekly/weekly/voucher/dto/response/VoucherCreationResponse.java @@ -20,7 +20,6 @@ public VoucherCreationResponse(Voucher voucher) { this.expirationDate = voucher.getExpirationDate(); this.amount = voucher.getAmount(); this.voucherType = voucher.getDiscountType().name(); - } public UUID getId() { diff --git a/src/main/java/org/weekly/weekly/voucher/dto/response/VouchersResponse.java b/src/main/java/org/weekly/weekly/voucher/dto/response/VouchersResponse.java index ed49133c23..c3e8b4cb3d 100644 --- a/src/main/java/org/weekly/weekly/voucher/dto/response/VouchersResponse.java +++ b/src/main/java/org/weekly/weekly/voucher/dto/response/VouchersResponse.java @@ -5,7 +5,6 @@ import org.weekly.weekly.voucher.dto.Response; import java.util.List; -import java.util.stream.Collectors; public class VouchersResponse implements Response { private final List result; diff --git a/src/main/java/org/weekly/weekly/voucher/repository/JdbcVoucherRepository.java b/src/main/java/org/weekly/weekly/voucher/repository/JdbcVoucherRepository.java index 8892e68ef2..c5b138a1aa 100644 --- a/src/main/java/org/weekly/weekly/voucher/repository/JdbcVoucherRepository.java +++ b/src/main/java/org/weekly/weekly/voucher/repository/JdbcVoucherRepository.java @@ -29,6 +29,15 @@ public JdbcVoucherRepository(DataSource dataSource) { jdbcTemplate = new JdbcTemplate(dataSource); } + public static UUID toUUID(byte[] bytes) { + var buffer = ByteBuffer.wrap(bytes); + return new UUID(buffer.getLong(), buffer.getLong()); + } + + private byte[] uuidToBytes(UUID voucherId) { + return voucherId.toString().getBytes(); + } + @Override public Optional findById(UUID voucherId) { String sql = "SELECT * FROM vouchers WHERE voucher_id = UUID_TO_BIN(?)"; @@ -99,15 +108,6 @@ public void deleteAll() { jdbcTemplate.update(sql); } - public static UUID toUUID(byte[] bytes) { - var buffer = ByteBuffer.wrap(bytes); - return new UUID(buffer.getLong(), buffer.getLong()); - } - - private byte[] uuidToBytes(UUID voucherId) { - return voucherId.toString().getBytes(); - } - private Voucher mapToVoucher(ResultSet resultSet) throws SQLException { UUID voucherId = toUUID(resultSet.getBytes("voucher_id")); long amount = resultSet.getLong("amount"); @@ -117,7 +117,4 @@ private Voucher mapToVoucher(ResultSet resultSet) throws SQLException { return new Voucher(voucherId,amount, registrationDate, expirationDate, discountType.getNewInstance()); } - - - } diff --git a/src/main/java/org/weekly/weekly/voucher/repository/VoucherRepository.java b/src/main/java/org/weekly/weekly/voucher/repository/VoucherRepository.java index 0e794a4f2f..e9734beaef 100644 --- a/src/main/java/org/weekly/weekly/voucher/repository/VoucherRepository.java +++ b/src/main/java/org/weekly/weekly/voucher/repository/VoucherRepository.java @@ -11,12 +11,8 @@ public interface VoucherRepository { Voucher insert(Voucher voucher); Optional findById(UUID voucherId); List findAll(); - List findByDiscountType(DiscountType discountType); - Voucher update(Voucher voucher); - void deleteById(UUID voucherId); - void deleteAll(); } diff --git a/src/main/java/org/weekly/weekly/voucher/service/VoucherService.java b/src/main/java/org/weekly/weekly/voucher/service/VoucherService.java index a79e89cd54..f5ba6270e1 100644 --- a/src/main/java/org/weekly/weekly/voucher/service/VoucherService.java +++ b/src/main/java/org/weekly/weekly/voucher/service/VoucherService.java @@ -27,6 +27,4 @@ public VouchersResponse getVouchers() { List vouchers = voucherRepository.findAll(); return new VouchersResponse(vouchers); } - - } diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html index ba1ceab444..415d3d96c8 100644 --- a/src/main/resources/templates/index.html +++ b/src/main/resources/templates/index.html @@ -4,6 +4,9 @@ Document +
    + 1 +

    메인 페이지

    From e1548485e2e08dff68596958e7a5e080a3a78561 Mon Sep 17 00:00:00 2001 From: parksey Date: Fri, 14 Jul 2023 16:17:27 +0900 Subject: [PATCH 11/28] =?UTF-8?q?feat:=20voucher=20API=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/voucher/VoucherAPIController.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/main/java/org/weekly/weekly/api/voucher/VoucherAPIController.java diff --git a/src/main/java/org/weekly/weekly/api/voucher/VoucherAPIController.java b/src/main/java/org/weekly/weekly/api/voucher/VoucherAPIController.java new file mode 100644 index 0000000000..ebcad66ea4 --- /dev/null +++ b/src/main/java/org/weekly/weekly/api/voucher/VoucherAPIController.java @@ -0,0 +1,34 @@ +package org.weekly.weekly.api.voucher; + +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; +import org.weekly.weekly.voucher.dto.request.VoucherCreationRequest; +import org.weekly.weekly.voucher.dto.response.VoucherCreationResponse; +import org.weekly.weekly.voucher.dto.response.VouchersResponse; +import org.weekly.weekly.voucher.service.VoucherService; + +import java.util.List; + +@RestController +@RequestMapping("/api/v1") +public class VoucherAPIController { + private final VoucherService voucherService; + + public VoucherAPIController(VoucherService voucherService) { + this.voucherService = voucherService; + } + + @PostMapping("/voucher") + public ResponseEntity createVoucher(@RequestBody VoucherCreationRequest voucherCreationRequest) { + VoucherCreationResponse voucherCreationResponse = voucherService.insertVoucher(voucherCreationRequest); + return new ResponseEntity<>(voucherCreationResponse, HttpStatus.OK); + } + + + @GetMapping("/vouchers") + public ResponseEntity> getVouchers() { + VouchersResponse vouchersResponse = voucherService.getVouchers(); + return new ResponseEntity<>(vouchersResponse.getResult(), HttpStatus.OK); + } +} From 072cd3369ce23cae4774c41d41acf43f00f40b57 Mon Sep 17 00:00:00 2001 From: parksey Date: Fri, 14 Jul 2023 18:01:38 +0900 Subject: [PATCH 12/28] =?UTF-8?q?refactor:=20test=EC=9D=98=20=EC=88=9C?= =?UTF-8?q?=EC=84=9C=20=EC=9D=98=EC=A1=B4=EC=84=B1=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weekly/VoucherManagementController.java | 6 +- .../weekly/ui/CommandLineApplication.java | 2 +- .../weekly/weekly/ui/writer/SystemWriter.java | 2 +- .../voucher/JdbcVoucherRepositoryTest.java | 82 ++++++++++++++----- 4 files changed, 67 insertions(+), 25 deletions(-) diff --git a/src/main/java/org/weekly/weekly/VoucherManagementController.java b/src/main/java/org/weekly/weekly/VoucherManagementController.java index 6826e35cef..2e6c6385b5 100644 --- a/src/main/java/org/weekly/weekly/VoucherManagementController.java +++ b/src/main/java/org/weekly/weekly/VoucherManagementController.java @@ -31,12 +31,12 @@ public VoucherManagementController(CommandLineApplication commandLineApplication } public void start() { - boolean isExit = false; + boolean isRunning = true; - while(!isExit) { + while(isRunning) { try { ManageMenu manageMenu = commandLineApplication.readManageMenu(); - isExit = processManageMenuSelection(manageMenu); + isRunning = processManageMenuSelection(manageMenu); } catch (RuntimeException runtimeException) { commandLineApplication.printErrorMsg(runtimeException.getMessage()); } diff --git a/src/main/java/org/weekly/weekly/ui/CommandLineApplication.java b/src/main/java/org/weekly/weekly/ui/CommandLineApplication.java index 967ab428ed..6a14cd104a 100644 --- a/src/main/java/org/weekly/weekly/ui/CommandLineApplication.java +++ b/src/main/java/org/weekly/weekly/ui/CommandLineApplication.java @@ -102,7 +102,7 @@ public void printErrorMsg(String errorMsg) { } public void printResult(Response response) { - commandWriter.printReuslt(response.result()); + commandWriter.printResult(response.result()); } public void printDeleteMessage() { diff --git a/src/main/java/org/weekly/weekly/ui/writer/SystemWriter.java b/src/main/java/org/weekly/weekly/ui/writer/SystemWriter.java index 241130f9f4..ba9f6939a0 100644 --- a/src/main/java/org/weekly/weekly/ui/writer/SystemWriter.java +++ b/src/main/java/org/weekly/weekly/ui/writer/SystemWriter.java @@ -61,7 +61,7 @@ public void printNameInputMessage() { println(PrintMessageType.NAME_INPUT.getMessage()); } - public void printReuslt(String result) { + public void printResult(String result) { println(PrintMessageType.EMPTY.getMessage()); println(result); } diff --git a/src/test/java/org/weekly/weekly/voucher/JdbcVoucherRepositoryTest.java b/src/test/java/org/weekly/weekly/voucher/JdbcVoucherRepositoryTest.java index 6a47bcc496..35feae6e3e 100644 --- a/src/test/java/org/weekly/weekly/voucher/JdbcVoucherRepositoryTest.java +++ b/src/test/java/org/weekly/weekly/voucher/JdbcVoucherRepositoryTest.java @@ -1,11 +1,15 @@ package org.weekly.weekly.voucher; -import org.junit.jupiter.api.*; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.jdbc.JdbcTestUtils; import org.testcontainers.junit.jupiter.Testcontainers; import org.weekly.weekly.voucher.domain.DiscountType; import org.weekly.weekly.voucher.domain.Voucher; @@ -20,7 +24,7 @@ import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.samePropertyValuesAs; -@TestMethodOrder(MethodOrderer.OrderAnnotation.class) + @ActiveProfiles("test") @Testcontainers @SpringBootTest @@ -28,6 +32,10 @@ class JdbcVoucherRepositoryTest{ @Autowired private JdbcVoucherRepository jdbcVoucherRepository; + @Autowired + private JdbcTemplate jdbcTemplate; + + Voucher fixedVoucher; Voucher percentVoucher; @@ -37,64 +45,97 @@ void setUp() { percentVoucher = Voucher.of(UUID.randomUUID(), 50, LocalDate.now(), 7, DiscountType.PERCENT); } + @AfterEach + void initDB() { + JdbcTestUtils.deleteFromTables(jdbcTemplate, "vouchers"); + } + @Test - @Order(1) void 전체_바우처_검색_테스트() { + // Given + jdbcVoucherRepository.insert(fixedVoucher); + jdbcVoucherRepository.insert(percentVoucher); + + // When List vouchers = jdbcVoucherRepository.findAll(); + + // Then assertThat(vouchers.isEmpty(), is(false)); } @Test - @Order(1) void 아이디를_통한_검색_실패_테스트() { + // When Optional voucher = jdbcVoucherRepository.findById(fixedVoucher.getVoucherId()); + + // Then assertThat(voucher.isEmpty(), is(true)); } @Test - @Order(1) void 아이디를_통한_검색_성공_테스트() { + // Given + jdbcVoucherRepository.insert(fixedVoucher); + + // When Optional voucher = jdbcVoucherRepository.findById(fixedVoucher.getVoucherId()); - assertThat(voucher.isPresent(), is(false)); + + // Then + assertThat(voucher.isPresent(), is(true)); } @Test - @Order(1) - void 할인정책을_통한_검색_테스트() { - List vouchers = jdbcVoucherRepository.findByDiscountType(percentVoucher.getDiscountType()); + void 고정_할인정책을_검색_테스트() { + // Given + jdbcVoucherRepository.insert(fixedVoucher); + + // When + List vouchers = jdbcVoucherRepository.findByDiscountType(DiscountType.FIXED); + // Then assertThat(vouchers.isEmpty(), is(false)); + } - vouchers.stream() - .forEach(voucher -> assertThat(voucher.getDiscountType(), is(DiscountType.PERCENT))); + @Test + void 퍼센트_할인정책을_검색_테스트() { + // Given + jdbcVoucherRepository.insert(percentVoucher); + + // When + List vouchers = jdbcVoucherRepository.findByDiscountType(DiscountType.PERCENT); + + // Then + assertThat(vouchers.isEmpty(), is(false)); } @Test - @Order(2) void 할인바우처_등록성공_테스트() { + // Given Voucher voucher = jdbcVoucherRepository.insert(percentVoucher); + // When Optional findVoucher = jdbcVoucherRepository.findById(percentVoucher.getVoucherId()); + // Then assertThat(findVoucher.isEmpty(), is(false)); assertThat(findVoucher.get(), samePropertyValuesAs(voucher)); } @Test - @Order(2) void 고정바우처_등록성공_테스트() { + // Given Voucher voucher = jdbcVoucherRepository.insert(fixedVoucher); + // When Optional findVoucher = jdbcVoucherRepository.findById(fixedVoucher.getVoucherId()); + // Then assertThat(findVoucher.isEmpty(), is(false)); assertThat(findVoucher.get(), samePropertyValuesAs(voucher)); } - @ParameterizedTest @CsvSource({"5000, 0", "15000, 5000"}) - @Order(3) void 고정바우처_정보_업데이트_테스트(int amount, long reaminExpected) { // Given jdbcVoucherRepository.insert(fixedVoucher); @@ -112,7 +153,6 @@ void setUp() { @ParameterizedTest @CsvSource({"3000, 1500", "1000, 500"}) - @Order(3) void 퍼센트바우처_정보_업데이트_테스트(int amount, long reaminExpected) { // Given jdbcVoucherRepository.insert(percentVoucher); @@ -129,7 +169,6 @@ void setUp() { } @Test - @Order(4) void 바우처_삭제_테스트() { // Given Voucher voucher = jdbcVoucherRepository.insert(percentVoucher); @@ -145,13 +184,16 @@ void setUp() { } @Test - @Order(5) void 전체_바우처_삭제_테스트() { // Given - jdbcVoucherRepository.deleteAll(); + jdbcVoucherRepository.insert(percentVoucher); + jdbcVoucherRepository.insert(fixedVoucher); - // when + // When + jdbcVoucherRepository.deleteAll(); List vouchers = jdbcVoucherRepository.findAll(); + + // Then assertThat(vouchers.isEmpty(), is(true)); } } From aca8a39a8936355bee47380eadf756e0ffcd67ff Mon Sep 17 00:00:00 2001 From: parksey Date: Fri, 14 Jul 2023 18:23:20 +0900 Subject: [PATCH 13/28] =?UTF-8?q?refactor:=20voucherManagementController?= =?UTF-8?q?=EC=97=90=EC=84=9C=20if=EB=AC=B8=EC=9D=84=20swtich=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weekly/VoucherManagementController.java | 85 ++++++------------- 1 file changed, 25 insertions(+), 60 deletions(-) diff --git a/src/main/java/org/weekly/weekly/VoucherManagementController.java b/src/main/java/org/weekly/weekly/VoucherManagementController.java index 2e6c6385b5..1762c958d2 100644 --- a/src/main/java/org/weekly/weekly/VoucherManagementController.java +++ b/src/main/java/org/weekly/weekly/VoucherManagementController.java @@ -44,38 +44,26 @@ public void start() { } private boolean processManageMenuSelection(ManageMenu manageMenu) { - if (ManageMenu.EXIT.equals(manageMenu)) { - return true; - } - - if (ManageMenu.VOUCHER.equals(manageMenu)) { - VoucherMenu voucherMenu = commandLineApplication.readVoucherMenu(); - processVoucherMenuSelection(voucherMenu); - return false; - } - - if (ManageMenu.CUSTOMER.equals(manageMenu)){ - CustomerMenu customerMenu = commandLineApplication.readCustomerMenu(); - processCustomerMenuSelection(customerMenu); - return false; - } - - return true; + return switch(manageMenu) { + case VOUCHER -> { + VoucherMenu voucherMenu = commandLineApplication.readVoucherMenu(); + processVoucherMenuSelection(voucherMenu); + yield false; + } + case CUSTOMER -> { + CustomerMenu customerMenu = commandLineApplication.readCustomerMenu(); + processCustomerMenuSelection(customerMenu); + yield false; + } + default -> true; + }; } - private boolean processVoucherMenuSelection(VoucherMenu selectMenu) { - if (VoucherMenu.CREATE.equals(selectMenu)) { - handleVoucherCreation(); - return false; - } - - if (VoucherMenu.LIST.equals(selectMenu)) { - handleVoucherSearch(); - return false; + private void processVoucherMenuSelection(VoucherMenu selectMenu) { + switch (selectMenu) { + case CREATE -> handleVoucherCreation(); + case LIST -> handleVoucherSearch(); } - - - return true; } private void handleVoucherCreation() { @@ -91,38 +79,15 @@ private void handleVoucherSearch() { commandLineApplication.printResult(response); } - private boolean processCustomerMenuSelection(CustomerMenu selectMenu) { - if (CustomerMenu.CREATE.equals(selectMenu)) { - handleCustomerCreation(); - return false; + private void processCustomerMenuSelection(CustomerMenu selectMenu) { + switch(selectMenu) { + case CREATE -> handleCustomerCreation(); + case DELETE -> handleCustomerDelete(); + case DELETE_ALL -> handleCustomerDeleteAll(); + case FIND_ALL -> handleCustomerFindAll(); + case FIND_DETAIL -> handleFindDetail(); + case UPDATE -> handleUpdateCustomer(); } - - if (CustomerMenu.DELETE.equals(selectMenu)) { - handleCustomerDelete(); - return false; - } - - if (CustomerMenu.DELETE_ALL.equals(selectMenu)) { - handleCustomerDeleteAll(); - return false; - } - - if (CustomerMenu.FIND_ALL.equals(selectMenu)) { - handleCustomerFindAll(); - return false; - } - - if (CustomerMenu.FIND_DETAIL.equals(selectMenu)) { - handleFindDetail(); - return false; - } - - if (CustomerMenu.UPDATE.equals(selectMenu)) { - handleUpdateCustomer(); - return false; - } - - return true; } private void handleCustomerCreation() { From 9c78b8311d9feeaf8af39ae0f5b01eb47e3e5227 Mon Sep 17 00:00:00 2001 From: parksey Date: Fri, 14 Jul 2023 18:35:16 +0900 Subject: [PATCH 14/28] =?UTF-8?q?feat:=20=EC=98=A4=ED=95=B4=EC=9D=98=20?= =?UTF-8?q?=EC=97=AC=EC=A7=80=EA=B0=80=20=EC=9E=88=EB=8A=94=20response=20?= =?UTF-8?q?=EC=9D=B8=ED=84=B0=ED=8E=98=EC=9D=B4=EC=8A=A4=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weekly/VoucherManagementController.java | 7 +-- .../dto/response/CustomerResponse.java | 4 +- .../dto/response/CustomersResponse.java | 4 +- .../weekly/ui/CommandLineApplication.java | 46 ++++++++++++------- .../weekly/ui/exception/InputException.java | 2 +- .../weekly/ui/exception/InputValidator.java | 4 +- .../weekly/ui/reader/BufferedReaderWrap.java | 6 +-- .../weekly/weekly/ui/reader/ConsoleWrap.java | 6 +-- .../weekly/weekly/ui/reader/ScannerWrap.java | 4 +- .../weekly/ui/writer/CommandWriter.java | 4 ++ .../weekly/weekly/ui/writer/SystemWriter.java | 8 +++- .../voucher/controller/VoucherController.java | 9 ++-- .../weekly/weekly/voucher/dto/Response.java | 8 ---- .../dto/response/VoucherCreationResponse.java | 4 +- .../dto/response/VouchersResponse.java | 4 +- .../web/customer/CustomerWebController.java | 17 +++---- .../weekly/web/exception/WebExceptionDto.java | 3 +- .../web/voucher/VoucherWebController.java | 4 +- 18 files changed, 76 insertions(+), 68 deletions(-) delete mode 100644 src/main/java/org/weekly/weekly/voucher/dto/Response.java diff --git a/src/main/java/org/weekly/weekly/VoucherManagementController.java b/src/main/java/org/weekly/weekly/VoucherManagementController.java index 1762c958d2..0587022c5d 100644 --- a/src/main/java/org/weekly/weekly/VoucherManagementController.java +++ b/src/main/java/org/weekly/weekly/VoucherManagementController.java @@ -14,8 +14,9 @@ import org.weekly.weekly.util.PrintMessageType; import org.weekly.weekly.util.VoucherMenu; import org.weekly.weekly.voucher.controller.VoucherController; -import org.weekly.weekly.voucher.dto.Response; import org.weekly.weekly.voucher.dto.request.VoucherCreationRequest; +import org.weekly.weekly.voucher.dto.response.VoucherCreationResponse; +import org.weekly.weekly.voucher.dto.response.VouchersResponse; @Component public class VoucherManagementController { @@ -68,13 +69,13 @@ private void processVoucherMenuSelection(VoucherMenu selectMenu) { private void handleVoucherCreation() { VoucherCreationRequest voucherCreationRequest = commandLineApplication.createVoucherFromInput(); - Response response = voucherController.createVoucher(voucherCreationRequest); + VoucherCreationResponse response = voucherController.createVoucher(voucherCreationRequest); logger.info("{}{}", PrintMessageType.CREATE_VOUCHER_SUCCESS.getMessage(),response.result()); commandLineApplication.printResult(response); } private void handleVoucherSearch() { - Response response = voucherController.getVouchers(); + VouchersResponse response = voucherController.getVouchers(); logger.info("{}{}", PrintMessageType.FIND_ALL_VOUCHER_SUCCESS.getMessage(), response.result()); commandLineApplication.printResult(response); } diff --git a/src/main/java/org/weekly/weekly/customer/dto/response/CustomerResponse.java b/src/main/java/org/weekly/weekly/customer/dto/response/CustomerResponse.java index 7435b4170c..776867b8f3 100644 --- a/src/main/java/org/weekly/weekly/customer/dto/response/CustomerResponse.java +++ b/src/main/java/org/weekly/weekly/customer/dto/response/CustomerResponse.java @@ -1,12 +1,11 @@ package org.weekly.weekly.customer.dto.response; import org.weekly.weekly.customer.domain.Customer; -import org.weekly.weekly.voucher.dto.Response; import java.text.MessageFormat; import java.time.LocalDateTime; -public class CustomerResponse implements Response { +public class CustomerResponse { String name; String email; LocalDateTime createAt; @@ -33,7 +32,6 @@ public String getName() { return name; } - @Override public String result() { return MessageFormat.format("[이름: {0}, 이메일: {1}, 생성 시기: {2}]", name, email, createAt); } diff --git a/src/main/java/org/weekly/weekly/customer/dto/response/CustomersResponse.java b/src/main/java/org/weekly/weekly/customer/dto/response/CustomersResponse.java index 6b1d966266..f27c47c326 100644 --- a/src/main/java/org/weekly/weekly/customer/dto/response/CustomersResponse.java +++ b/src/main/java/org/weekly/weekly/customer/dto/response/CustomersResponse.java @@ -2,11 +2,10 @@ import org.weekly.weekly.customer.domain.Customer; import org.weekly.weekly.util.PrintMessageType; -import org.weekly.weekly.voucher.dto.Response; import java.util.List; -public class CustomersResponse implements Response { +public class CustomersResponse { List result; public CustomersResponse(List customers) { @@ -15,7 +14,6 @@ public CustomersResponse(List customers) { .toList(); } - @Override public String result() { if (result.isEmpty()) { return PrintMessageType.NO_VOUCHER_DATAS.getMessage(); diff --git a/src/main/java/org/weekly/weekly/ui/CommandLineApplication.java b/src/main/java/org/weekly/weekly/ui/CommandLineApplication.java index 6a14cd104a..e08f80b5c2 100644 --- a/src/main/java/org/weekly/weekly/ui/CommandLineApplication.java +++ b/src/main/java/org/weekly/weekly/ui/CommandLineApplication.java @@ -4,17 +4,20 @@ import org.springframework.stereotype.Component; import org.weekly.weekly.customer.dto.request.CustomerCreationRequest; import org.weekly.weekly.customer.dto.request.CustomerUpdateRequest; +import org.weekly.weekly.customer.dto.response.CustomerResponse; +import org.weekly.weekly.customer.dto.response.CustomersResponse; import org.weekly.weekly.ui.exception.InputValidator; import org.weekly.weekly.ui.reader.CommandReader; import org.weekly.weekly.ui.writer.SystemWriter; import org.weekly.weekly.util.CustomerMenu; import org.weekly.weekly.util.ManageMenu; import org.weekly.weekly.util.Menu; -import org.weekly.weekly.voucher.domain.DiscountType; import org.weekly.weekly.util.VoucherMenu; -import org.weekly.weekly.voucher.dto.Response; -import org.weekly.weekly.voucher.dto.request.VoucherInfoRequest; +import org.weekly.weekly.voucher.domain.DiscountType; import org.weekly.weekly.voucher.dto.request.VoucherCreationRequest; +import org.weekly.weekly.voucher.dto.request.VoucherInfoRequest; +import org.weekly.weekly.voucher.dto.response.VoucherCreationResponse; +import org.weekly.weekly.voucher.dto.response.VouchersResponse; import java.util.function.Supplier; @@ -30,28 +33,28 @@ public CommandLineApplication(CommandReader commandReader, SystemWriter commandW } public ManageMenu readManageMenu() { - return readMenu(()-> { + return readMenu(() -> { commandWriter.printMangeProgram(); return ManageMenu.getMenu(readMenuInput()); }); } public VoucherMenu readVoucherMenu() { - return readMenu(()-> { + return readMenu(() -> { commandWriter.printVoucherProgram(); return VoucherMenu.getMenu(readMenuInput()); }); } public CustomerMenu readCustomerMenu() { - return readMenu(()-> { + return readMenu(() -> { commandWriter.printCustomerProgram(); return CustomerMenu.getMenu(readMenuInput()); }); } public VoucherCreationRequest createVoucherFromInput() { - while(true) { + while (true) { try { DiscountType discountType = readDiscountType(); VoucherInfoRequest voucherInfoRequest = readVoucherInfo(discountType); @@ -63,7 +66,7 @@ public VoucherCreationRequest createVoucherFromInput() { } public CustomerCreationRequest createCustomerFromInput() { - while(true) { + while (true) { try { String email = processEmail(); String name = processName(); @@ -75,7 +78,7 @@ public CustomerCreationRequest createCustomerFromInput() { } public CustomerUpdateRequest customerDetailFromInput() { - while(true) { + while (true) { try { String email = processEmail(); return CustomerUpdateRequest.of(email); @@ -85,8 +88,8 @@ public CustomerUpdateRequest customerDetailFromInput() { } } - public CustomerUpdateRequest customerUpdateRequest(){ - while(true) { + public CustomerUpdateRequest customerUpdateRequest() { + while (true) { try { String email = processEmail(); String newEmail = processNewEmail(); @@ -101,15 +104,26 @@ public void printErrorMsg(String errorMsg) { commandWriter.printErrorMessage(errorMsg); } - public void printResult(Response response) { - commandWriter.printResult(response.result()); + public void printResult(VoucherCreationResponse voucherCreationResponse) { + commandWriter.printResult(voucherCreationResponse.result()); + } + + public void printResult(VouchersResponse vouchersResponse) { + commandWriter.printResult(vouchersResponse.result()); + } + + public void printResult(CustomerResponse customerResponse) { + commandWriter.printResult(customerResponse.result()); + } + + public void printResult(CustomersResponse customerResponse) { + commandWriter.printResult(customerResponse.result()); } public void printDeleteMessage() { commandWriter.printDeleteMessage(); } - private String readMenuInput() { String userInput = commandReader.readLine(); InputValidator.isEmpty(userInput); @@ -123,7 +137,7 @@ private String readUserInput() { } private T readMenu(Supplier menuSupplier) { - while(true) { + while (true) { try { return menuSupplier.get(); } catch (Exception exception) { @@ -138,7 +152,7 @@ private DiscountType readDiscountType() { return DiscountType.getDiscountTypeByNumber(no); } - private VoucherInfoRequest readVoucherInfo(DiscountType discountType){ + private VoucherInfoRequest readVoucherInfo(DiscountType discountType) { commandWriter.printCreateVoucher(discountType); String voucherInfo = readUserInput(); return VoucherInfoRequest.of(voucherInfo); diff --git a/src/main/java/org/weekly/weekly/ui/exception/InputException.java b/src/main/java/org/weekly/weekly/ui/exception/InputException.java index 6eb0516cfb..942215bf0c 100644 --- a/src/main/java/org/weekly/weekly/ui/exception/InputException.java +++ b/src/main/java/org/weekly/weekly/ui/exception/InputException.java @@ -2,7 +2,7 @@ import org.weekly.weekly.util.ExceptionMsg; -public class InputException extends RuntimeException{ +public class InputException extends RuntimeException { public InputException(ExceptionMsg exception) { super(exception.getMsg()); diff --git a/src/main/java/org/weekly/weekly/ui/exception/InputValidator.java b/src/main/java/org/weekly/weekly/ui/exception/InputValidator.java index 865303e990..7c0bcef72a 100644 --- a/src/main/java/org/weekly/weekly/ui/exception/InputValidator.java +++ b/src/main/java/org/weekly/weekly/ui/exception/InputValidator.java @@ -1,7 +1,6 @@ package org.weekly.weekly.ui.exception; import org.weekly.weekly.util.ExceptionMsg; -import org.weekly.weekly.voucher.exception.VoucherException; import java.util.Arrays; @@ -12,6 +11,7 @@ private InputValidator() { } private static final int VOUCHER_INPUT_SIZE = 2; + public static void isEmpty(String userInput) { if (userInput == null || userInput.isBlank()) { throw new InputException(ExceptionMsg.EMPTY); @@ -23,7 +23,7 @@ public static void notVoucherInputSize(String[] userInputs) { throw new InputException(ExceptionMsg.NOT_SAME_PARAM_SIZE); } } - + public static void notNumber(String[] userInputs) { try { Arrays.stream(userInputs) diff --git a/src/main/java/org/weekly/weekly/ui/reader/BufferedReaderWrap.java b/src/main/java/org/weekly/weekly/ui/reader/BufferedReaderWrap.java index 6542b3dc7c..a95ecd5298 100644 --- a/src/main/java/org/weekly/weekly/ui/reader/BufferedReaderWrap.java +++ b/src/main/java/org/weekly/weekly/ui/reader/BufferedReaderWrap.java @@ -10,16 +10,16 @@ import java.io.InputStreamReader; @Component -@ConditionalOnProperty(value="command.read", havingValue = "buffer") +@ConditionalOnProperty(value = "command.read", havingValue = "buffer") public class BufferedReaderWrap implements CommandReader { private final BufferedReader bufferedReader; public BufferedReaderWrap() { - bufferedReader = new BufferedReader(new InputStreamReader(System.in)); + bufferedReader = new BufferedReader(new InputStreamReader(System.in)); } @Override - public String readLine(){ + public String readLine() { try { return bufferedReader.readLine(); } catch (IOException exception) { diff --git a/src/main/java/org/weekly/weekly/ui/reader/ConsoleWrap.java b/src/main/java/org/weekly/weekly/ui/reader/ConsoleWrap.java index 6ef24823ab..a66925d245 100644 --- a/src/main/java/org/weekly/weekly/ui/reader/ConsoleWrap.java +++ b/src/main/java/org/weekly/weekly/ui/reader/ConsoleWrap.java @@ -6,8 +6,8 @@ import java.io.Console; @Component -@ConditionalOnProperty(value="command.read", havingValue = "console") -public class ConsoleWrap implements CommandReader{ +@ConditionalOnProperty(value = "command.read", havingValue = "console") +public class ConsoleWrap implements CommandReader { private final Console console; public ConsoleWrap() { @@ -15,7 +15,7 @@ public ConsoleWrap() { } @Override - public String readLine() { + public String readLine() { return console.readLine(); } } diff --git a/src/main/java/org/weekly/weekly/ui/reader/ScannerWrap.java b/src/main/java/org/weekly/weekly/ui/reader/ScannerWrap.java index 35fb98e407..4a127dfc61 100644 --- a/src/main/java/org/weekly/weekly/ui/reader/ScannerWrap.java +++ b/src/main/java/org/weekly/weekly/ui/reader/ScannerWrap.java @@ -7,8 +7,8 @@ import java.util.Scanner; @Component -@ConditionalOnProperty(value="command.read", havingValue = "scanner") -public class ScannerWrap implements CommandReader{ +@ConditionalOnProperty(value = "command.read", havingValue = "scanner") +public class ScannerWrap implements CommandReader { private final Scanner scanner; public ScannerWrap() { diff --git a/src/main/java/org/weekly/weekly/ui/writer/CommandWriter.java b/src/main/java/org/weekly/weekly/ui/writer/CommandWriter.java index f26b91797c..295abf0d76 100644 --- a/src/main/java/org/weekly/weekly/ui/writer/CommandWriter.java +++ b/src/main/java/org/weekly/weekly/ui/writer/CommandWriter.java @@ -4,8 +4,12 @@ public interface CommandWriter { void printVoucherProgram(); + void printErrorMsg(String message); + void printCreateVoucher(DiscountType discountType); + void printSelectDiscount(); + void printReuslt(String result); } diff --git a/src/main/java/org/weekly/weekly/ui/writer/SystemWriter.java b/src/main/java/org/weekly/weekly/ui/writer/SystemWriter.java index ba9f6939a0..065586e85d 100644 --- a/src/main/java/org/weekly/weekly/ui/writer/SystemWriter.java +++ b/src/main/java/org/weekly/weekly/ui/writer/SystemWriter.java @@ -10,13 +10,17 @@ import java.util.Arrays; @Component -@ConditionalOnProperty(value="command.write", havingValue = "system") +@ConditionalOnProperty(value = "command.write", havingValue = "system") public class SystemWriter { private final Logger logger = LoggerFactory.getLogger(SystemWriter.class); + private void println(String msg) { System.out.println(msg); } - private void print(String msg) {System.out.print(msg);} + + private void print(String msg) { + System.out.print(msg); + } public void printMangeProgram() { printMenu(ManageMenu.values(), PrintMessageType.MANAGE_PROGRAM); diff --git a/src/main/java/org/weekly/weekly/voucher/controller/VoucherController.java b/src/main/java/org/weekly/weekly/voucher/controller/VoucherController.java index e1b25c0f9e..7dae861767 100644 --- a/src/main/java/org/weekly/weekly/voucher/controller/VoucherController.java +++ b/src/main/java/org/weekly/weekly/voucher/controller/VoucherController.java @@ -1,10 +1,9 @@ package org.weekly.weekly.voucher.controller; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.stereotype.Controller; -import org.weekly.weekly.voucher.dto.Response; import org.weekly.weekly.voucher.dto.request.VoucherCreationRequest; +import org.weekly.weekly.voucher.dto.response.VoucherCreationResponse; +import org.weekly.weekly.voucher.dto.response.VouchersResponse; import org.weekly.weekly.voucher.service.VoucherService; @Controller @@ -15,11 +14,11 @@ public VoucherController(VoucherService voucherService) { this.voucherService = voucherService; } - public Response createVoucher(VoucherCreationRequest voucherCreationRequest) { + public VoucherCreationResponse createVoucher(VoucherCreationRequest voucherCreationRequest) { return voucherService.insertVoucher(voucherCreationRequest); } - public Response getVouchers() { + public VouchersResponse getVouchers() { return voucherService.getVouchers(); } } diff --git a/src/main/java/org/weekly/weekly/voucher/dto/Response.java b/src/main/java/org/weekly/weekly/voucher/dto/Response.java deleted file mode 100644 index 991e1271d8..0000000000 --- a/src/main/java/org/weekly/weekly/voucher/dto/Response.java +++ /dev/null @@ -1,8 +0,0 @@ -package org.weekly.weekly.voucher.dto; - -/** - * 모든 반환 값에 대해 동일한 동작을 적용시키고 싶어서 이렇게 했습니다. - */ -public interface Response { - String result(); -} diff --git a/src/main/java/org/weekly/weekly/voucher/dto/response/VoucherCreationResponse.java b/src/main/java/org/weekly/weekly/voucher/dto/response/VoucherCreationResponse.java index 1be8a5f583..b9a6469b3f 100644 --- a/src/main/java/org/weekly/weekly/voucher/dto/response/VoucherCreationResponse.java +++ b/src/main/java/org/weekly/weekly/voucher/dto/response/VoucherCreationResponse.java @@ -1,13 +1,12 @@ package org.weekly.weekly.voucher.dto.response; import org.weekly.weekly.voucher.domain.Voucher; -import org.weekly.weekly.voucher.dto.Response; import java.text.MessageFormat; import java.time.LocalDate; import java.util.UUID; -public class VoucherCreationResponse implements Response { +public class VoucherCreationResponse { private final UUID id; private final LocalDate registrationDate; private final LocalDate expirationDate; @@ -42,7 +41,6 @@ public String getVoucherType() { return voucherType; } - @Override public String result() { return MessageFormat.format("[ID: {0}, 금액: {1}, 등록일자: {2}, 유효기간: {3}]", id, amount, registrationDate, expirationDate); } diff --git a/src/main/java/org/weekly/weekly/voucher/dto/response/VouchersResponse.java b/src/main/java/org/weekly/weekly/voucher/dto/response/VouchersResponse.java index c3e8b4cb3d..abeca21d9a 100644 --- a/src/main/java/org/weekly/weekly/voucher/dto/response/VouchersResponse.java +++ b/src/main/java/org/weekly/weekly/voucher/dto/response/VouchersResponse.java @@ -2,11 +2,10 @@ import org.weekly.weekly.util.PrintMessageType; import org.weekly.weekly.voucher.domain.Voucher; -import org.weekly.weekly.voucher.dto.Response; import java.util.List; -public class VouchersResponse implements Response { +public class VouchersResponse { private final List result; public VouchersResponse(List vouchers) { @@ -24,7 +23,6 @@ public String result() { return PrintMessageType.NO_VOUCHER_DATAS.getMessage(); } - StringBuilder resultBuilder = new StringBuilder(); result.forEach(voucherResponse-> resultBuilder.append(voucherResponse.result()).append('\n')); return resultBuilder.toString(); diff --git a/src/main/java/org/weekly/weekly/web/customer/CustomerWebController.java b/src/main/java/org/weekly/weekly/web/customer/CustomerWebController.java index dc7cf9a60e..10f0fe23ba 100644 --- a/src/main/java/org/weekly/weekly/web/customer/CustomerWebController.java +++ b/src/main/java/org/weekly/weekly/web/customer/CustomerWebController.java @@ -5,8 +5,9 @@ import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; -import org.springframework.web.bind.annotation.*; -import org.weekly.weekly.customer.domain.Customer; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; import org.weekly.weekly.customer.dto.request.CustomerCreationRequest; import org.weekly.weekly.customer.dto.request.CustomerUpdateRequest; import org.weekly.weekly.customer.dto.response.CustomerResponse; @@ -17,7 +18,7 @@ @Controller @RequestMapping("/customer") -public class CustomerWebController { +public class CustomerWebController { private final Logger logger = LoggerFactory.getLogger(CustomerWebController.class); private final CustomerService customerService; @@ -43,7 +44,7 @@ public String createCustomer() { } @PostMapping("/create") - public String createCustomer( CustomerCreationRequest creationRequest, Model model) { + public String createCustomer(CustomerCreationRequest creationRequest, Model model) { try { CustomerResponse customerResponse = customerService.createCustomer(creationRequest); model.addAttribute("customer", customerResponse); @@ -65,7 +66,7 @@ public String findCustomer(CustomerUpdateRequest updateRequest, Model model) { try { CustomerResponse customerResponse = customerService.findDetailCustomer(updateRequest); model.addAttribute("customer", customerResponse); - } catch(CustomerException | EmptyResultDataAccessException exception) { + } catch (CustomerException | EmptyResultDataAccessException exception) { model.addAttribute("exception", new WebExceptionDto(exception)); return "exception/exception"; } @@ -81,7 +82,7 @@ public String deleteCustomer() { public String deleteCustomer(CustomerUpdateRequest updateRequest, Model model) { try { customerService.deleteCustomer(updateRequest); - } catch(CustomerException | EmptyResultDataAccessException exception) { + } catch (CustomerException | EmptyResultDataAccessException exception) { model.addAttribute("exception", new WebExceptionDto(exception)); return "exception/exception"; } @@ -97,7 +98,7 @@ public String deleteAllCustomer() { public String deleteAllCustomers(Model model) { try { customerService.deleteAllCustomers(); - } catch(CustomerException | EmptyResultDataAccessException exception) { + } catch (CustomerException | EmptyResultDataAccessException exception) { model.addAttribute("exception", new WebExceptionDto(exception)); return "exception/exception"; } @@ -114,7 +115,7 @@ public String updateCustomer(CustomerUpdateRequest updateRequest, Model model) { try { CustomerResponse customerResponse = customerService.updateCustomer(updateRequest); model.addAttribute("customer", customerResponse); - } catch(CustomerException | EmptyResultDataAccessException exception) { + } catch (CustomerException | EmptyResultDataAccessException exception) { model.addAttribute("exception", new WebExceptionDto(exception)); return "exception/exception"; } diff --git a/src/main/java/org/weekly/weekly/web/exception/WebExceptionDto.java b/src/main/java/org/weekly/weekly/web/exception/WebExceptionDto.java index 079463b752..c70bcdb6db 100644 --- a/src/main/java/org/weekly/weekly/web/exception/WebExceptionDto.java +++ b/src/main/java/org/weekly/weekly/web/exception/WebExceptionDto.java @@ -1,7 +1,8 @@ package org.weekly.weekly.web.exception; public class WebExceptionDto { - private String message; + private final String message; + public WebExceptionDto(RuntimeException error) { this.message = error.getMessage(); } diff --git a/src/main/java/org/weekly/weekly/web/voucher/VoucherWebController.java b/src/main/java/org/weekly/weekly/web/voucher/VoucherWebController.java index 65ae4c466b..61574a00cb 100644 --- a/src/main/java/org/weekly/weekly/web/voucher/VoucherWebController.java +++ b/src/main/java/org/weekly/weekly/web/voucher/VoucherWebController.java @@ -33,7 +33,7 @@ public String createVoucher(@ModelAttribute VoucherCreationRequest voucherCreati try { VoucherCreationResponse voucherCreationResponse = voucherService.insertVoucher(voucherCreationRequest); model.addAttribute("voucher", voucherCreationResponse); - } catch( VoucherException voucherException) { + } catch (VoucherException voucherException) { model.addAttribute("exception", new WebExceptionDto(voucherException)); return "exception/exception"; } @@ -51,7 +51,7 @@ public String getVouchers(Model model) { try { VouchersResponse vouchersResponse = voucherService.getVouchers(); model.addAttribute("vouchers", vouchersResponse); - } catch( VoucherException voucherException) { + } catch (VoucherException voucherException) { model.addAttribute("exception", new WebExceptionDto(voucherException)); return "exception/exception"; } From e33500ed309ad0868600c1e0ed9b59326061b8b9 Mon Sep 17 00:00:00 2001 From: parksey Date: Fri, 14 Jul 2023 18:37:20 +0900 Subject: [PATCH 15/28] =?UTF-8?q?refactor:=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20=EC=BD=94=EB=93=9C=20=EA=B3=B5=EB=B0=B1=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weekly/VoucherManageApplication.java | 9 +- .../weekly/VoucherManagementController.java | 13 ++- .../dto/request/CustomerUpdateRequest.java | 7 +- .../dto/response/CustomersResponse.java | 2 +- .../customer/exception/CustomerException.java | 2 +- .../repository/CustomerRepository.java | 5 ++ .../repository/JdbcCustomerRepository.java | 4 +- .../org/weekly/weekly/util/CustomerMenu.java | 1 + .../org/weekly/weekly/util/ExceptionMsg.java | 2 +- .../org/weekly/weekly/util/VoucherMenu.java | 1 + .../weekly/voucher/domain/Discount.java | 1 + .../weekly/voucher/domain/DiscountType.java | 3 +- .../weekly/voucher/domain/FixedDiscount.java | 2 +- .../voucher/domain/PercentDiscount.java | 3 +- .../dto/request/VoucherCreationRequest.java | 2 +- .../dto/request/VoucherInfoRequest.java | 3 +- .../dto/response/VouchersResponse.java | 4 +- .../voucher/exception/VoucherException.java | 2 +- .../voucher/exception/VoucherValidator.java | 1 + .../repository/JdbcVoucherRepository.java | 6 +- .../repository/MemoryVoucherRepository.java | 2 +- .../voucher/repository/VoucherRepository.java | 6 ++ src/main/resources/logback.xml | 4 +- src/main/resources/schema.sql | 26 +++--- src/main/resources/static/form.css | 86 ++++++++++++------- .../templates/customer/createCustomer.html | 14 +-- .../templates/customer/customerInfo.html | 24 +++--- .../templates/customer/deleteAll.html | 2 +- .../templates/customer/deleteCustomer.html | 2 +- .../templates/customer/findCustomer.html | 14 +-- .../templates/customer/findCustomers.html | 30 +++---- .../templates/customer/updateCustomer.html | 2 +- .../templates/exception/exception.html | 4 +- src/main/resources/templates/global/form.html | 7 +- src/main/resources/templates/global/head.html | 3 +- src/main/resources/templates/index.html | 30 +++---- .../weekly/VoucherManageApplicationTests.java | 1 - .../weekly/weekly/customer/CustomerTest.java | 6 +- .../customer/JdbcCustomerRepositoryTest.java | 3 +- .../weekly/weekly/ui/ReadExceptionTest.java | 2 +- .../weekly/weekly/util/DiscountMapTest.java | 2 +- .../weekly/weekly/util/VoucherMenuTest.java | 4 +- .../voucher/JdbcVoucherRepositoryTest.java | 2 +- .../weekly/weekly/voucher/VoucherTest.java | 13 +-- 44 files changed, 202 insertions(+), 160 deletions(-) diff --git a/src/main/java/org/weekly/weekly/VoucherManageApplication.java b/src/main/java/org/weekly/weekly/VoucherManageApplication.java index 081a262e55..5cfe257fa5 100644 --- a/src/main/java/org/weekly/weekly/VoucherManageApplication.java +++ b/src/main/java/org/weekly/weekly/VoucherManageApplication.java @@ -2,14 +2,13 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; import org.springframework.context.ApplicationContext; @SpringBootApplication public class VoucherManageApplication { - public static void main(String[] args) { + public static void main(String[] args) { - ApplicationContext context = SpringApplication.run(VoucherManageApplication.class, args); - context.getBean(VoucherManagementController.class).start(); - } + ApplicationContext context = SpringApplication.run(VoucherManageApplication.class, args); + context.getBean(VoucherManagementController.class).start(); + } } \ No newline at end of file diff --git a/src/main/java/org/weekly/weekly/VoucherManagementController.java b/src/main/java/org/weekly/weekly/VoucherManagementController.java index 0587022c5d..a63fe8ed39 100644 --- a/src/main/java/org/weekly/weekly/VoucherManagementController.java +++ b/src/main/java/org/weekly/weekly/VoucherManagementController.java @@ -34,7 +34,7 @@ public VoucherManagementController(CommandLineApplication commandLineApplication public void start() { boolean isRunning = true; - while(isRunning) { + while (isRunning) { try { ManageMenu manageMenu = commandLineApplication.readManageMenu(); isRunning = processManageMenuSelection(manageMenu); @@ -45,16 +45,16 @@ public void start() { } private boolean processManageMenuSelection(ManageMenu manageMenu) { - return switch(manageMenu) { + return switch (manageMenu) { case VOUCHER -> { VoucherMenu voucherMenu = commandLineApplication.readVoucherMenu(); processVoucherMenuSelection(voucherMenu); - yield false; + yield false; } case CUSTOMER -> { CustomerMenu customerMenu = commandLineApplication.readCustomerMenu(); processCustomerMenuSelection(customerMenu); - yield false; + yield false; } default -> true; }; @@ -70,7 +70,7 @@ private void processVoucherMenuSelection(VoucherMenu selectMenu) { private void handleVoucherCreation() { VoucherCreationRequest voucherCreationRequest = commandLineApplication.createVoucherFromInput(); VoucherCreationResponse response = voucherController.createVoucher(voucherCreationRequest); - logger.info("{}{}", PrintMessageType.CREATE_VOUCHER_SUCCESS.getMessage(),response.result()); + logger.info("{}{}", PrintMessageType.CREATE_VOUCHER_SUCCESS.getMessage(), response.result()); commandLineApplication.printResult(response); } @@ -81,7 +81,7 @@ private void handleVoucherSearch() { } private void processCustomerMenuSelection(CustomerMenu selectMenu) { - switch(selectMenu) { + switch (selectMenu) { case CREATE -> handleCustomerCreation(); case DELETE -> handleCustomerDelete(); case DELETE_ALL -> handleCustomerDeleteAll(); @@ -124,5 +124,4 @@ private void handleUpdateCustomer() { CustomerResponse customerResponse = customerController.updateCustomer(customerUpdateRequest); commandLineApplication.printResult(customerResponse); } - } diff --git a/src/main/java/org/weekly/weekly/customer/dto/request/CustomerUpdateRequest.java b/src/main/java/org/weekly/weekly/customer/dto/request/CustomerUpdateRequest.java index 7fecabbebf..b50e78f5c7 100644 --- a/src/main/java/org/weekly/weekly/customer/dto/request/CustomerUpdateRequest.java +++ b/src/main/java/org/weekly/weekly/customer/dto/request/CustomerUpdateRequest.java @@ -6,7 +6,8 @@ public class CustomerUpdateRequest { private String email; private String newEmail; - private CustomerUpdateRequest(){} + private CustomerUpdateRequest() { + } private CustomerUpdateRequest(String email, String afterEmail) { this.email = email; @@ -32,7 +33,9 @@ public String email() { return email; } - public String newEmail() {return newEmail;} + public String newEmail() { + return newEmail; + } public void setEmail(String email) { this.email = email; diff --git a/src/main/java/org/weekly/weekly/customer/dto/response/CustomersResponse.java b/src/main/java/org/weekly/weekly/customer/dto/response/CustomersResponse.java index f27c47c326..66f3fde88c 100644 --- a/src/main/java/org/weekly/weekly/customer/dto/response/CustomersResponse.java +++ b/src/main/java/org/weekly/weekly/customer/dto/response/CustomersResponse.java @@ -20,7 +20,7 @@ public String result() { } StringBuilder resultBuilder = new StringBuilder(); - result.forEach(customerResponse-> resultBuilder.append(customerResponse.result()).append('\n')); + result.forEach(customerResponse -> resultBuilder.append(customerResponse.result()).append('\n')); return resultBuilder.toString(); } diff --git a/src/main/java/org/weekly/weekly/customer/exception/CustomerException.java b/src/main/java/org/weekly/weekly/customer/exception/CustomerException.java index cfda9e7fa5..c27d38c0bd 100644 --- a/src/main/java/org/weekly/weekly/customer/exception/CustomerException.java +++ b/src/main/java/org/weekly/weekly/customer/exception/CustomerException.java @@ -2,7 +2,7 @@ import org.weekly.weekly.util.ExceptionMsg; -public class CustomerException extends RuntimeException{ +public class CustomerException extends RuntimeException { public CustomerException(ExceptionMsg exceptionMsg) { super(exceptionMsg.getMsg()); } diff --git a/src/main/java/org/weekly/weekly/customer/repository/CustomerRepository.java b/src/main/java/org/weekly/weekly/customer/repository/CustomerRepository.java index 788543ce38..fe994e1fc8 100644 --- a/src/main/java/org/weekly/weekly/customer/repository/CustomerRepository.java +++ b/src/main/java/org/weekly/weekly/customer/repository/CustomerRepository.java @@ -7,10 +7,15 @@ public interface CustomerRepository { Customer insert(Customer customer); + void deleteByEmail(String email); + void deleteAll(); + Optional findByEmail(String email); + List findAll(); + Customer update(Customer customer, String newEmail); } diff --git a/src/main/java/org/weekly/weekly/customer/repository/JdbcCustomerRepository.java b/src/main/java/org/weekly/weekly/customer/repository/JdbcCustomerRepository.java index dfa9152808..3afd981ee2 100644 --- a/src/main/java/org/weekly/weekly/customer/repository/JdbcCustomerRepository.java +++ b/src/main/java/org/weekly/weekly/customer/repository/JdbcCustomerRepository.java @@ -20,7 +20,7 @@ @Profile("!dev") @Repository -public class JdbcCustomerRepository implements CustomerRepository{ +public class JdbcCustomerRepository implements CustomerRepository { private final JdbcTemplate jdbcTemplate; public JdbcCustomerRepository(DataSource dataSource) { @@ -97,7 +97,7 @@ private Customer mapToCustomer(ResultSet resultSet) throws SQLException { UUID customerId = toUUID(resultSet.getBytes("customer_id")); String name = resultSet.getString("name"); String email = resultSet.getString("email"); - LocalDateTime createAt = resultSet.getTimestamp("create_at") == null? null : resultSet.getTimestamp("create_at").toLocalDateTime(); + LocalDateTime createAt = resultSet.getTimestamp("create_at") == null ? null : resultSet.getTimestamp("create_at").toLocalDateTime(); return new Customer(customerId, name, email, createAt); } diff --git a/src/main/java/org/weekly/weekly/util/CustomerMenu.java b/src/main/java/org/weekly/weekly/util/CustomerMenu.java index f8ad92b79f..9b40a257a1 100644 --- a/src/main/java/org/weekly/weekly/util/CustomerMenu.java +++ b/src/main/java/org/weekly/weekly/util/CustomerMenu.java @@ -17,6 +17,7 @@ public enum CustomerMenu implements Menu { private final String printMessage; private static final Map CUSTOMER_MENU_MAP; + static { CUSTOMER_MENU_MAP = new ConcurrentHashMap<>(); Arrays.stream(CustomerMenu.values()) diff --git a/src/main/java/org/weekly/weekly/util/ExceptionMsg.java b/src/main/java/org/weekly/weekly/util/ExceptionMsg.java index c77ec9ab02..472bffd19e 100644 --- a/src/main/java/org/weekly/weekly/util/ExceptionMsg.java +++ b/src/main/java/org/weekly/weekly/util/ExceptionMsg.java @@ -26,6 +26,6 @@ public enum ExceptionMsg { } public String getMsg() { - return ERROR.msg+msg; + return ERROR.msg + msg; } } diff --git a/src/main/java/org/weekly/weekly/util/VoucherMenu.java b/src/main/java/org/weekly/weekly/util/VoucherMenu.java index 738d71afb1..27d415def8 100644 --- a/src/main/java/org/weekly/weekly/util/VoucherMenu.java +++ b/src/main/java/org/weekly/weekly/util/VoucherMenu.java @@ -13,6 +13,7 @@ public enum VoucherMenu implements Menu { private final String printMessage; private final static Map VOUCHER_MENU_MAP; + static { VOUCHER_MENU_MAP = new ConcurrentHashMap<>(); Arrays.stream(VoucherMenu.values()) diff --git a/src/main/java/org/weekly/weekly/voucher/domain/Discount.java b/src/main/java/org/weekly/weekly/voucher/domain/Discount.java index c7dc3708a2..48c68a54fe 100644 --- a/src/main/java/org/weekly/weekly/voucher/domain/Discount.java +++ b/src/main/java/org/weekly/weekly/voucher/domain/Discount.java @@ -2,5 +2,6 @@ public interface Discount { long applyDiscount(long beforeAmount, long discountAmount); + DiscountType discountType(); } diff --git a/src/main/java/org/weekly/weekly/voucher/domain/DiscountType.java b/src/main/java/org/weekly/weekly/voucher/domain/DiscountType.java index c3e765c6d0..a48bb94485 100644 --- a/src/main/java/org/weekly/weekly/voucher/domain/DiscountType.java +++ b/src/main/java/org/weekly/weekly/voucher/domain/DiscountType.java @@ -53,7 +53,8 @@ public static DiscountType getDiscountTypeByName(String name) { public Discount getNewInstance() { try { return this.cls.getDeclaredConstructor().newInstance(); - } catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException exception) { + } catch (NoSuchMethodException | InstantiationException | IllegalAccessException | + InvocationTargetException exception) { throw new VoucherException(ExceptionMsg.NOT_FOUND); } } diff --git a/src/main/java/org/weekly/weekly/voucher/domain/FixedDiscount.java b/src/main/java/org/weekly/weekly/voucher/domain/FixedDiscount.java index b8621eb46f..1c50be7ec0 100644 --- a/src/main/java/org/weekly/weekly/voucher/domain/FixedDiscount.java +++ b/src/main/java/org/weekly/weekly/voucher/domain/FixedDiscount.java @@ -1,6 +1,6 @@ package org.weekly.weekly.voucher.domain; -public class FixedDiscount implements Discount{ +public class FixedDiscount implements Discount { @Override public long applyDiscount(long beforeAmount, long discountAmount) { return beforeAmount - discountAmount; diff --git a/src/main/java/org/weekly/weekly/voucher/domain/PercentDiscount.java b/src/main/java/org/weekly/weekly/voucher/domain/PercentDiscount.java index 0ff80bba02..e7ffad108e 100644 --- a/src/main/java/org/weekly/weekly/voucher/domain/PercentDiscount.java +++ b/src/main/java/org/weekly/weekly/voucher/domain/PercentDiscount.java @@ -1,7 +1,8 @@ package org.weekly.weekly.voucher.domain; -public class PercentDiscount implements Discount{ +public class PercentDiscount implements Discount { private static final int PERCENT = 100; + @Override public long applyDiscount(long beforeAmount, long discountAmount) { return beforeAmount - beforeAmount * discountAmount / PERCENT; diff --git a/src/main/java/org/weekly/weekly/voucher/dto/request/VoucherCreationRequest.java b/src/main/java/org/weekly/weekly/voucher/dto/request/VoucherCreationRequest.java index b1ea728e75..4beb52aced 100644 --- a/src/main/java/org/weekly/weekly/voucher/dto/request/VoucherCreationRequest.java +++ b/src/main/java/org/weekly/weekly/voucher/dto/request/VoucherCreationRequest.java @@ -27,7 +27,7 @@ public DiscountType getDiscountType() { return discountType; } - public Voucher toVoucher() { + public Voucher toVoucher() { UUID id = UUID.randomUUID(); long amount = voucherInfoRequest.getAmount(); LocalDate now = LocalDate.now(); diff --git a/src/main/java/org/weekly/weekly/voucher/dto/request/VoucherInfoRequest.java b/src/main/java/org/weekly/weekly/voucher/dto/request/VoucherInfoRequest.java index dadcc98e2d..13915f5e09 100644 --- a/src/main/java/org/weekly/weekly/voucher/dto/request/VoucherInfoRequest.java +++ b/src/main/java/org/weekly/weekly/voucher/dto/request/VoucherInfoRequest.java @@ -10,7 +10,8 @@ public class VoucherInfoRequest { private long amount; private long expiration; - public VoucherInfoRequest() {} + public VoucherInfoRequest() { + } public VoucherInfoRequest(long amount, long expiration) { this.amount = amount; diff --git a/src/main/java/org/weekly/weekly/voucher/dto/response/VouchersResponse.java b/src/main/java/org/weekly/weekly/voucher/dto/response/VouchersResponse.java index abeca21d9a..07f9bb514b 100644 --- a/src/main/java/org/weekly/weekly/voucher/dto/response/VouchersResponse.java +++ b/src/main/java/org/weekly/weekly/voucher/dto/response/VouchersResponse.java @@ -5,7 +5,7 @@ import java.util.List; -public class VouchersResponse { +public class VouchersResponse { private final List result; public VouchersResponse(List vouchers) { @@ -24,7 +24,7 @@ public String result() { } StringBuilder resultBuilder = new StringBuilder(); - result.forEach(voucherResponse-> resultBuilder.append(voucherResponse.result()).append('\n')); + result.forEach(voucherResponse -> resultBuilder.append(voucherResponse.result()).append('\n')); return resultBuilder.toString(); } } diff --git a/src/main/java/org/weekly/weekly/voucher/exception/VoucherException.java b/src/main/java/org/weekly/weekly/voucher/exception/VoucherException.java index a9743019c0..af4e344daa 100644 --- a/src/main/java/org/weekly/weekly/voucher/exception/VoucherException.java +++ b/src/main/java/org/weekly/weekly/voucher/exception/VoucherException.java @@ -2,7 +2,7 @@ import org.weekly.weekly.util.ExceptionMsg; -public class VoucherException extends RuntimeException{ +public class VoucherException extends RuntimeException { public VoucherException(ExceptionMsg exceptionMsg) { super(exceptionMsg.getMsg()); } diff --git a/src/main/java/org/weekly/weekly/voucher/exception/VoucherValidator.java b/src/main/java/org/weekly/weekly/voucher/exception/VoucherValidator.java index 0dc6518d71..6b7df0dcfd 100644 --- a/src/main/java/org/weekly/weekly/voucher/exception/VoucherValidator.java +++ b/src/main/java/org/weekly/weekly/voucher/exception/VoucherValidator.java @@ -21,6 +21,7 @@ public static void validateExpiration(LocalDate registrationDate, long expiratio throw new VoucherException(ExceptionMsg.EXPIRATION_ERROR); } } + public static void validateAmount(DiscountType discountType, long amount) { if (DiscountType.FIXED.equals(discountType)) { notRange(amount, input -> input < RANGE_START); diff --git a/src/main/java/org/weekly/weekly/voucher/repository/JdbcVoucherRepository.java b/src/main/java/org/weekly/weekly/voucher/repository/JdbcVoucherRepository.java index c5b138a1aa..22abe80ef8 100644 --- a/src/main/java/org/weekly/weekly/voucher/repository/JdbcVoucherRepository.java +++ b/src/main/java/org/weekly/weekly/voucher/repository/JdbcVoucherRepository.java @@ -22,7 +22,7 @@ @Profile("!dev") @Repository -public class JdbcVoucherRepository implements VoucherRepository{ +public class JdbcVoucherRepository implements VoucherRepository { private final JdbcTemplate jdbcTemplate; public JdbcVoucherRepository(DataSource dataSource) { @@ -71,7 +71,7 @@ public Voucher insert(Voucher voucher) { voucher.getDiscountType().name(), Timestamp.valueOf(voucher.getRegistrationDate().atStartOfDay()), Timestamp.valueOf(voucher.getExpirationDate().atStartOfDay())); - } catch(DataAccessException dataAccessException) { + } catch (DataAccessException dataAccessException) { throw new VoucherException(ExceptionMsg.SQL_INSERT_ERROR); } @@ -115,6 +115,6 @@ private Voucher mapToVoucher(ResultSet resultSet) throws SQLException { LocalDate registrationDate = resultSet.getTimestamp("registration_date") == null ? null : resultSet.getTimestamp("registration_date").toLocalDateTime().toLocalDate(); LocalDate expirationDate = resultSet.getTimestamp("expiration_date") == null ? null : resultSet.getTimestamp("expiration_date").toLocalDateTime().toLocalDate(); - return new Voucher(voucherId,amount, registrationDate, expirationDate, discountType.getNewInstance()); + return new Voucher(voucherId, amount, registrationDate, expirationDate, discountType.getNewInstance()); } } diff --git a/src/main/java/org/weekly/weekly/voucher/repository/MemoryVoucherRepository.java b/src/main/java/org/weekly/weekly/voucher/repository/MemoryVoucherRepository.java index e1b8d1bc70..f3fc811034 100644 --- a/src/main/java/org/weekly/weekly/voucher/repository/MemoryVoucherRepository.java +++ b/src/main/java/org/weekly/weekly/voucher/repository/MemoryVoucherRepository.java @@ -15,7 +15,7 @@ @Profile("dev") @Repository -public class MemoryVoucherRepository implements VoucherRepository{ +public class MemoryVoucherRepository implements VoucherRepository { private final Map storages = new ConcurrentHashMap<>(); public Voucher insert(Voucher voucher) { diff --git a/src/main/java/org/weekly/weekly/voucher/repository/VoucherRepository.java b/src/main/java/org/weekly/weekly/voucher/repository/VoucherRepository.java index e9734beaef..0bc962c767 100644 --- a/src/main/java/org/weekly/weekly/voucher/repository/VoucherRepository.java +++ b/src/main/java/org/weekly/weekly/voucher/repository/VoucherRepository.java @@ -9,10 +9,16 @@ public interface VoucherRepository { Voucher insert(Voucher voucher); + Optional findById(UUID voucherId); + List findAll(); + List findByDiscountType(DiscountType discountType); + Voucher update(Voucher voucher); + void deleteById(UUID voucherId); + void deleteAll(); } diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml index 41b5312d80..b59a5e22ad 100644 --- a/src/main/resources/logback.xml +++ b/src/main/resources/logback.xml @@ -12,10 +12,10 @@ - + - + diff --git a/src/main/resources/schema.sql b/src/main/resources/schema.sql index 0b88d26b44..883bbe234c 100644 --- a/src/main/resources/schema.sql +++ b/src/main/resources/schema.sql @@ -1,10 +1,11 @@ DROP TABLE IF EXISTS customers; -CREATE TABLE customers ( - customer_id BINARY(16) PRIMARY KEY, - name varchar(20) NOT NULL, - email varchar(50) NOT NULL, - create_at datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), - CONSTRAINT unq_user_email UNIQUE (email) +CREATE TABLE customers +( + customer_id BINARY(16) PRIMARY KEY, + name varchar(20) NOT NULL, + email varchar(50) NOT NULL, + create_at datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP (6), + CONSTRAINT unq_user_email UNIQUE (email) ); INSERT INTO customers(customer_id, name, email) @@ -15,12 +16,13 @@ VALUES (uuid_to_bin(UUID()), 'tester00', 'test00@gmail.com'), DROP TABLE IF EXISTS vouchers; -CREATE TABLE vouchers ( - voucher_id BINARY(16) PRIMARY KEY, - amount bigint NOT NULL, - discount enum('FIXED', 'PERCENT') NOT NULL, - registration_date datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), - expiration_date datetime(6) NOT NULL +CREATE TABLE vouchers +( + voucher_id BINARY(16) PRIMARY KEY, + amount bigint NOT NULL, + discount enum('FIXED', 'PERCENT') NOT NULL, + registration_date datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP (6), + expiration_date datetime(6) NOT NULL ); INSERT INTO vouchers (voucher_id, amount, discount, expiration_date) diff --git a/src/main/resources/static/form.css b/src/main/resources/static/form.css index 02fee27c9f..21a1259fd4 100644 --- a/src/main/resources/static/form.css +++ b/src/main/resources/static/form.css @@ -1,11 +1,12 @@ -*{ +* { margin: 0; padding: 0; outline: none; box-sizing: border-box; font-family: 'Poppins', sans-serif; } -body{ + +body { display: flex; align-items: center; justify-content: center; @@ -13,78 +14,91 @@ body{ padding: 10px; font-family: 'Poppins', sans-serif; } -.container{ + +.container { max-width: 800px; background: #fff; width: 800px; padding: 25px 40px 10px 40px; - box-shadow: 0px 0px 10px rgba(0,0,0,0.1); + box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1); } .text { color: #3498db; } -.container .text{ + +.container .text { text-align: center; font-size: 41px; font-weight: 600; font-family: 'Poppins', sans-serif; } -.container form{ + +.container form { padding: 30px 0 0 0; } -.container form .form-row{ + +.container form .form-row { display: flex; margin: 32px 0; } -form .form-row .input-data{ + +form .form-row .input-data { width: 100%; height: 40px; margin: 0 20px; position: relative; } -form .form-row .textarea{ + +form .form-row .textarea { height: 70px; } + .input-data input, -.textarea textarea{ +.textarea textarea { display: block; width: 100%; height: 100%; border: none; font-size: 17px; - border-bottom: 2px solid rgba(0,0,0, 0.12); + border-bottom: 2px solid rgba(0, 0, 0, 0.12); } + .input-data input:focus ~ label, .textarea textarea:focus ~ label, -.input-data input:valid ~ label, .textarea textarea:valid ~ label{ +.input-data input:valid ~ label, .textarea textarea:valid ~ label { transform: translateY(-20px); font-size: 14px; color: #3498db; } -.textarea textarea{ + +.textarea textarea { resize: none; padding-top: 10px; } -.input-data label{ + +.input-data label { position: absolute; pointer-events: none; bottom: 10px; font-size: 16px; transition: all 0.3s ease; } -.textarea label{ + +.textarea label { width: 100%; bottom: 40px; background: #fff; } -.input-data .underline{ + +.input-data .underline { position: absolute; bottom: 0; height: 2px; width: 100%; background: #3498db; } -.input-data .underline:before{ + +.input-data .underline:before { position: absolute; content: ""; height: 2px; @@ -94,18 +108,21 @@ form .form-row .textarea{ transform-origin: center; transition: transform 0.3s ease; } + .input-data input:focus ~ .underline:before, .input-data input:valid ~ .underline:before, .textarea textarea:focus ~ .underline:before, -.textarea textarea:valid ~ .underline:before{ +.textarea textarea:valid ~ .underline:before { transform: scale(1); } -.submit-btn .input-data{ + +.submit-btn .input-data { overflow: hidden; - height: 45px!important; - width: 25%!important; + height: 45px !important; + width: 25% !important; } -.submit-btn .input-data .inner{ + +.submit-btn .input-data .inner { height: 100%; width: 300%; position: absolute; @@ -113,10 +130,12 @@ form .form-row .textarea{ transition: all 0.4s; background-color: #56d8e4; } -.submit-btn .input-data:hover .inner{ + +.submit-btn .input-data:hover .inner { left: 0; } -.submit-btn .input-data input{ + +.submit-btn .input-data input { background: none; border: none; color: #fff; @@ -128,20 +147,25 @@ form .form-row .textarea{ position: relative; z-index: 2; } + @media (max-width: 700px) { - .container .text{ + .container .text { font-size: 30px; } - .container form{ + + .container form { padding: 10px 0 0 0; } - .container form .form-row{ + + .container form .form-row { display: block; } - form .form-row .input-data{ - margin: 35px 0!important; + + form .form-row .input-data { + margin: 35px 0 !important; } - .submit-btn .input-data{ - width: 40%!important; + + .submit-btn .input-data { + width: 40% !important; } } \ No newline at end of file diff --git a/src/main/resources/templates/customer/createCustomer.html b/src/main/resources/templates/customer/createCustomer.html index 45f3f09d92..2417195ea8 100644 --- a/src/main/resources/templates/customer/createCustomer.html +++ b/src/main/resources/templates/customer/createCustomer.html @@ -4,14 +4,14 @@ Document -
    -
    -

    고객 생성

    - Home -
    - -
    +
    +
    +

    고객 생성

    + Home
    +
    +
    + diff --git a/src/main/resources/templates/customer/customerInfo.html b/src/main/resources/templates/customer/customerInfo.html index 33f25a18bc..e32bf436a9 100644 --- a/src/main/resources/templates/customer/customerInfo.html +++ b/src/main/resources/templates/customer/customerInfo.html @@ -4,19 +4,19 @@ Customer Info -
    -
    -

    고객 정보

    - Home -
    -
    - - - - -
    -
    +
    +
    +

    고객 정보

    + Home
    +
    + + + + +
    +
    +
    diff --git a/src/main/resources/templates/customer/deleteAll.html b/src/main/resources/templates/customer/deleteAll.html index aaa4a9fe94..187962b4e4 100644 --- a/src/main/resources/templates/customer/deleteAll.html +++ b/src/main/resources/templates/customer/deleteAll.html @@ -7,7 +7,7 @@
    -

    고객 전체 삭제

    +

    고객 전체 삭제

    Home
    diff --git a/src/main/resources/templates/customer/deleteCustomer.html b/src/main/resources/templates/customer/deleteCustomer.html index 8551c68a48..a8994eed04 100644 --- a/src/main/resources/templates/customer/deleteCustomer.html +++ b/src/main/resources/templates/customer/deleteCustomer.html @@ -6,7 +6,7 @@
    -

    고객 삭제

    +

    고객 삭제

    Home
    diff --git a/src/main/resources/templates/customer/findCustomer.html b/src/main/resources/templates/customer/findCustomer.html index 24fc8bc237..6acdac3019 100644 --- a/src/main/resources/templates/customer/findCustomer.html +++ b/src/main/resources/templates/customer/findCustomer.html @@ -5,13 +5,13 @@ Title -
    -
    -

    고객 정보 찾기

    - Home -
    - -
    +
    +
    +

    고객 정보 찾기

    + Home
    + +
    +
    \ No newline at end of file diff --git a/src/main/resources/templates/customer/findCustomers.html b/src/main/resources/templates/customer/findCustomers.html index 67cca75501..e8ef39e5b4 100644 --- a/src/main/resources/templates/customer/findCustomers.html +++ b/src/main/resources/templates/customer/findCustomers.html @@ -5,21 +5,21 @@ Document -
    -
    -

    고객 리스트

    - Home -
    -
    - - - - - - - -
    -
    +
    +
    +

    고객 리스트

    + Home
    +
    + + + + + + + +
    +
    +
    \ No newline at end of file diff --git a/src/main/resources/templates/customer/updateCustomer.html b/src/main/resources/templates/customer/updateCustomer.html index 2f2e305744..9a869dc5f9 100644 --- a/src/main/resources/templates/customer/updateCustomer.html +++ b/src/main/resources/templates/customer/updateCustomer.html @@ -7,7 +7,7 @@
    -

    고객 정보 업데이트

    +

    고객 정보 업데이트

    Home
    diff --git a/src/main/resources/templates/exception/exception.html b/src/main/resources/templates/exception/exception.html index 7d9d5d8fce..210b00ce64 100644 --- a/src/main/resources/templates/exception/exception.html +++ b/src/main/resources/templates/exception/exception.html @@ -8,7 +8,7 @@ Document -

    Error Page

    -

    +

    Error Page

    +

    \ No newline at end of file diff --git a/src/main/resources/templates/global/form.html b/src/main/resources/templates/global/form.html index 50e8762f08..6beb0e0d09 100644 --- a/src/main/resources/templates/global/form.html +++ b/src/main/resources/templates/global/form.html @@ -1,6 +1,5 @@ -
    -
    +
    @@ -57,7 +56,7 @@
    - +
    @@ -69,7 +68,7 @@
    - +
    diff --git a/src/main/resources/templates/global/head.html b/src/main/resources/templates/global/head.html index ed86195cba..388ec75fa8 100644 --- a/src/main/resources/templates/global/head.html +++ b/src/main/resources/templates/global/head.html @@ -3,7 +3,8 @@ - + diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html index 415d3d96c8..2f603203a6 100644 --- a/src/main/resources/templates/index.html +++ b/src/main/resources/templates/index.html @@ -7,22 +7,22 @@
    1
    -
    -

    메인 페이지

    - -
    - -
    +
    +

    메인 페이지

    +
    +
    + +
    \ No newline at end of file diff --git a/src/test/java/org/weekly/weekly/VoucherManageApplicationTests.java b/src/test/java/org/weekly/weekly/VoucherManageApplicationTests.java index d70e8574cd..c7dd265580 100644 --- a/src/test/java/org/weekly/weekly/VoucherManageApplicationTests.java +++ b/src/test/java/org/weekly/weekly/VoucherManageApplicationTests.java @@ -1,6 +1,5 @@ package org.weekly.weekly; -import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; @SpringBootTest diff --git a/src/test/java/org/weekly/weekly/customer/CustomerTest.java b/src/test/java/org/weekly/weekly/customer/CustomerTest.java index a809768083..ba244eb902 100644 --- a/src/test/java/org/weekly/weekly/customer/CustomerTest.java +++ b/src/test/java/org/weekly/weekly/customer/CustomerTest.java @@ -8,9 +8,9 @@ import java.util.UUID; -import static org.hamcrest.MatcherAssert.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.hamcrest.Matchers.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.instanceOf; public class CustomerTest { @@ -22,6 +22,6 @@ public class CustomerTest { @ParameterizedTest @ValueSource(strings = {"123", "123@", "213@n", "abc@naver.", "abc@naver.c", "abc@naver.comc"}) void 회원생성_실패_테스트(String email) { - assertThatThrownBy(()-> Customer.of(UUID.randomUUID(), "hello", email)).isInstanceOf(CustomerException.class); + assertThatThrownBy(() -> Customer.of(UUID.randomUUID(), "hello", email)).isInstanceOf(CustomerException.class); } } diff --git a/src/test/java/org/weekly/weekly/customer/JdbcCustomerRepositoryTest.java b/src/test/java/org/weekly/weekly/customer/JdbcCustomerRepositoryTest.java index f7ad68a255..527d675c2e 100644 --- a/src/test/java/org/weekly/weekly/customer/JdbcCustomerRepositoryTest.java +++ b/src/test/java/org/weekly/weekly/customer/JdbcCustomerRepositoryTest.java @@ -4,7 +4,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.ActiveProfiles; -import org.testcontainers.junit.jupiter.Testcontainers; import org.weekly.weekly.customer.domain.Customer; import org.weekly.weekly.customer.repository.JdbcCustomerRepository; @@ -116,7 +115,7 @@ void deleteCustomer() { Customer insertCusomter = jdbcCustomerRepository.insert(customer); // When - jdbcCustomerRepository.update(insertCusomter,newName); + jdbcCustomerRepository.update(insertCusomter, newName); // Then Optional updateCustomer = jdbcCustomerRepository.findByEmail(newName); diff --git a/src/test/java/org/weekly/weekly/ui/ReadExceptionTest.java b/src/test/java/org/weekly/weekly/ui/ReadExceptionTest.java index ec1ee12655..f83fc0555e 100644 --- a/src/test/java/org/weekly/weekly/ui/ReadExceptionTest.java +++ b/src/test/java/org/weekly/weekly/ui/ReadExceptionTest.java @@ -10,7 +10,7 @@ public class ReadExceptionTest { @ParameterizedTest @ValueSource(strings = {"", " "}) void 사용자가_빈값이나_입력오류났을때_예외발생(String userInput) { - assertThatThrownBy(()-> InputValidator.isEmpty(userInput)) + assertThatThrownBy(() -> InputValidator.isEmpty(userInput)) .isInstanceOf(RuntimeException.class); } } diff --git a/src/test/java/org/weekly/weekly/util/DiscountMapTest.java b/src/test/java/org/weekly/weekly/util/DiscountMapTest.java index 3443ee7c77..90755b1595 100644 --- a/src/test/java/org/weekly/weekly/util/DiscountMapTest.java +++ b/src/test/java/org/weekly/weekly/util/DiscountMapTest.java @@ -18,7 +18,7 @@ public class DiscountMapTest { }) void 사용자_입력이_할인_맵에_없으면_예외발생(String userInput) { // when + then - assertThatThrownBy(()-> DiscountType.getDiscountTypeByNumber(userInput)) + assertThatThrownBy(() -> DiscountType.getDiscountTypeByNumber(userInput)) .isInstanceOf(RuntimeException.class); } diff --git a/src/test/java/org/weekly/weekly/util/VoucherMenuTest.java b/src/test/java/org/weekly/weekly/util/VoucherMenuTest.java index 1eeaaa95d1..a49bc0d129 100644 --- a/src/test/java/org/weekly/weekly/util/VoucherMenuTest.java +++ b/src/test/java/org/weekly/weekly/util/VoucherMenuTest.java @@ -1,10 +1,8 @@ package org.weekly.weekly.util; -import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; -import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; public class VoucherMenuTest { @@ -17,7 +15,7 @@ public class VoucherMenuTest { // then - assertThatThrownBy(()->VoucherMenu.getMenu(testValue)) + assertThatThrownBy(() -> VoucherMenu.getMenu(testValue)) .isInstanceOf(RuntimeException.class); } } diff --git a/src/test/java/org/weekly/weekly/voucher/JdbcVoucherRepositoryTest.java b/src/test/java/org/weekly/weekly/voucher/JdbcVoucherRepositoryTest.java index 35feae6e3e..fff85f7737 100644 --- a/src/test/java/org/weekly/weekly/voucher/JdbcVoucherRepositoryTest.java +++ b/src/test/java/org/weekly/weekly/voucher/JdbcVoucherRepositoryTest.java @@ -28,7 +28,7 @@ @ActiveProfiles("test") @Testcontainers @SpringBootTest -class JdbcVoucherRepositoryTest{ +class JdbcVoucherRepositoryTest { @Autowired private JdbcVoucherRepository jdbcVoucherRepository; diff --git a/src/test/java/org/weekly/weekly/voucher/VoucherTest.java b/src/test/java/org/weekly/weekly/voucher/VoucherTest.java index d786525500..7b1c4ab167 100644 --- a/src/test/java/org/weekly/weekly/voucher/VoucherTest.java +++ b/src/test/java/org/weekly/weekly/voucher/VoucherTest.java @@ -14,7 +14,8 @@ import java.time.LocalDate; import java.util.UUID; -import static org.assertj.core.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; public class VoucherTest { private MemoryVoucherRepository voucherRepository; @@ -29,7 +30,7 @@ void setVoucherRepository() { "100000,12: 1", "10,1: 1" }, delimiter = ':') - void 바우처가_이미_존재하면_예외발생(String userInput, String no) { + void 바우처가_이미_존재하면_예외발생(String userInput, String no) { // Given UUID voucherId = UUID.randomUUID(); VoucherInfoRequest voucherInfo = VoucherInfoRequest.of(userInput); @@ -60,7 +61,7 @@ void setVoucherRepository() { VoucherCreationRequest request = new VoucherCreationRequest(voucherInfo, discount); // when + then - assertThatThrownBy(()->request.toVoucher()) + assertThatThrownBy(() -> request.toVoucher()) .isInstanceOf(RuntimeException.class); } @@ -75,13 +76,13 @@ class 고정바우처_테스트 { // Given DiscountType discountType = DiscountType.FIXED; - VoucherInfoRequest voucherInfoRequest = VoucherInfoRequest.of(userInput); + VoucherInfoRequest voucherInfoRequest = VoucherInfoRequest.of(userInput); // when VoucherCreationRequest request = new VoucherCreationRequest(voucherInfoRequest, discountType); // then - assertThatThrownBy(()-> request.toVoucher()) + assertThatThrownBy(() -> request.toVoucher()) .isInstanceOf(RuntimeException.class); } @@ -118,7 +119,7 @@ class 퍼센트바우처_테스트 { // when + then - assertThatThrownBy(()->Voucher.of(voucherId, voucherInfo.getAmount(), now, 1, DiscountType.PERCENT)) + assertThatThrownBy(() -> Voucher.of(voucherId, voucherInfo.getAmount(), now, 1, DiscountType.PERCENT)) .isInstanceOf(RuntimeException.class); } From e4c42e8a9192a7a2c622c4945b405ba4bcc0f85c Mon Sep 17 00:00:00 2001 From: parksey Date: Fri, 14 Jul 2023 18:43:28 +0900 Subject: [PATCH 16/28] =?UTF-8?q?feat:=20SystemWriter=20implement=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/org/weekly/weekly/VoucherManageApplication.java | 2 +- src/main/java/org/weekly/weekly/ui/writer/CommandWriter.java | 4 +--- src/main/java/org/weekly/weekly/ui/writer/SystemWriter.java | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/weekly/weekly/VoucherManageApplication.java b/src/main/java/org/weekly/weekly/VoucherManageApplication.java index 5cfe257fa5..0f683a86d2 100644 --- a/src/main/java/org/weekly/weekly/VoucherManageApplication.java +++ b/src/main/java/org/weekly/weekly/VoucherManageApplication.java @@ -6,8 +6,8 @@ @SpringBootApplication public class VoucherManageApplication { - public static void main(String[] args) { + public static void main(String[] args) { ApplicationContext context = SpringApplication.run(VoucherManageApplication.class, args); context.getBean(VoucherManagementController.class).start(); } diff --git a/src/main/java/org/weekly/weekly/ui/writer/CommandWriter.java b/src/main/java/org/weekly/weekly/ui/writer/CommandWriter.java index 295abf0d76..69770ff1a3 100644 --- a/src/main/java/org/weekly/weekly/ui/writer/CommandWriter.java +++ b/src/main/java/org/weekly/weekly/ui/writer/CommandWriter.java @@ -5,11 +5,9 @@ public interface CommandWriter { void printVoucherProgram(); - void printErrorMsg(String message); + void printErrorMessage(String message); void printCreateVoucher(DiscountType discountType); void printSelectDiscount(); - - void printReuslt(String result); } diff --git a/src/main/java/org/weekly/weekly/ui/writer/SystemWriter.java b/src/main/java/org/weekly/weekly/ui/writer/SystemWriter.java index 065586e85d..1d56634c89 100644 --- a/src/main/java/org/weekly/weekly/ui/writer/SystemWriter.java +++ b/src/main/java/org/weekly/weekly/ui/writer/SystemWriter.java @@ -11,7 +11,7 @@ @Component @ConditionalOnProperty(value = "command.write", havingValue = "system") -public class SystemWriter { +public class SystemWriter implements CommandWriter{ private final Logger logger = LoggerFactory.getLogger(SystemWriter.class); private void println(String msg) { From a14465acfc32b5bd42a5747e861d7c3bba7147a8 Mon Sep 17 00:00:00 2001 From: parksey Date: Fri, 14 Jul 2023 22:12:35 +0900 Subject: [PATCH 17/28] =?UTF-8?q?feat:=20=EA=B0=9D=EC=B2=B4=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20=EB=B0=8F=20=EC=98=88=EC=99=B8=EC=B2=98=EB=A6=AC=20?= =?UTF-8?q?=ED=95=98=EB=8A=94=20of=EB=A9=94=EC=84=9C=EB=93=9C=20->=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=EC=9E=90=20=EB=82=B4=EB=B6=80=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EC=98=88=EC=99=B8=20=EC=B2=98=EB=A6=AC=20=ED=95=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/request/CustomerUpdateRequest.java | 18 +++++------------- .../customer/service/CustomerService.java | 1 + .../weekly/ui/CommandLineApplication.java | 4 ++-- .../customer/JdbcCustomerRepositoryTest.java | 7 ++++++- 4 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/main/java/org/weekly/weekly/customer/dto/request/CustomerUpdateRequest.java b/src/main/java/org/weekly/weekly/customer/dto/request/CustomerUpdateRequest.java index b50e78f5c7..c242402da4 100644 --- a/src/main/java/org/weekly/weekly/customer/dto/request/CustomerUpdateRequest.java +++ b/src/main/java/org/weekly/weekly/customer/dto/request/CustomerUpdateRequest.java @@ -9,24 +9,16 @@ public class CustomerUpdateRequest { private CustomerUpdateRequest() { } - private CustomerUpdateRequest(String email, String afterEmail) { + public CustomerUpdateRequest(String email, String afterEmail) { + InputValidator.isEmpty(email); + InputValidator.isEmpty(afterEmail); this.email = email; this.newEmail = afterEmail; } - private CustomerUpdateRequest(String email) { - this.email = email; - } - - public static CustomerUpdateRequest of(String email) { + public CustomerUpdateRequest(String email) { InputValidator.isEmpty(email); - return new CustomerUpdateRequest(email); - } - - public static CustomerUpdateRequest of(String email, String afterEmail) { - InputValidator.isEmpty(email); - InputValidator.isEmpty(afterEmail); - return new CustomerUpdateRequest(email, afterEmail); + this.email = email; } public String email() { diff --git a/src/main/java/org/weekly/weekly/customer/service/CustomerService.java b/src/main/java/org/weekly/weekly/customer/service/CustomerService.java index 73cb0c03e9..3330ba08ab 100644 --- a/src/main/java/org/weekly/weekly/customer/service/CustomerService.java +++ b/src/main/java/org/weekly/weekly/customer/service/CustomerService.java @@ -44,6 +44,7 @@ public void deleteAllCustomers() { customerRepository.deleteAll(); } + @Transactional(readOnly = true) public CustomerResponse findDetailCustomer(CustomerUpdateRequest updateRequest) { return findDetailCustomer(updateRequest.email()); } diff --git a/src/main/java/org/weekly/weekly/ui/CommandLineApplication.java b/src/main/java/org/weekly/weekly/ui/CommandLineApplication.java index e08f80b5c2..1c8f593850 100644 --- a/src/main/java/org/weekly/weekly/ui/CommandLineApplication.java +++ b/src/main/java/org/weekly/weekly/ui/CommandLineApplication.java @@ -81,7 +81,7 @@ public CustomerUpdateRequest customerDetailFromInput() { while (true) { try { String email = processEmail(); - return CustomerUpdateRequest.of(email); + return new CustomerUpdateRequest(email); } catch (Exception exception) { printErrorMsg(exception.getMessage()); } @@ -93,7 +93,7 @@ public CustomerUpdateRequest customerUpdateRequest() { try { String email = processEmail(); String newEmail = processNewEmail(); - return CustomerUpdateRequest.of(email, newEmail); + return new CustomerUpdateRequest(email, newEmail); } catch (Exception exception) { printErrorMsg(exception.getMessage()); } diff --git a/src/test/java/org/weekly/weekly/customer/JdbcCustomerRepositoryTest.java b/src/test/java/org/weekly/weekly/customer/JdbcCustomerRepositoryTest.java index 527d675c2e..09a8cc664f 100644 --- a/src/test/java/org/weekly/weekly/customer/JdbcCustomerRepositoryTest.java +++ b/src/test/java/org/weekly/weekly/customer/JdbcCustomerRepositoryTest.java @@ -3,7 +3,9 @@ import org.junit.jupiter.api.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.jdbc.JdbcTestUtils; import org.weekly.weekly.customer.domain.Customer; import org.weekly.weekly.customer.repository.JdbcCustomerRepository; @@ -22,6 +24,9 @@ class JdbcCustomerRepositoryTest { @Autowired private JdbcCustomerRepository jdbcCustomerRepository; + @Autowired + private JdbcTemplate jdbcTemplate; + Customer customer; @BeforeEach @@ -31,7 +36,7 @@ void setUp() { @AfterEach void deleteCustomer() { - assertThatCode(() -> jdbcCustomerRepository.deleteByEmail(customer.getEmail())); + JdbcTestUtils.deleteFromTables(jdbcTemplate, "customers"); } @Test From 3ebef707e597d1a21a2a98f738662f5f41acdcc7 Mon Sep 17 00:00:00 2001 From: parksey Date: Fri, 14 Jul 2023 22:19:52 +0900 Subject: [PATCH 18/28] =?UTF-8?q?feat:=20JDBC=20customer=20=EC=A0=80?= =?UTF-8?q?=EC=9E=A5=EC=86=8C=20row=EA=B0=92=EB=93=A4=20=EC=A7=80=EC=9A=B0?= =?UTF-8?q?=EB=8A=94=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/org/weekly/weekly/VoucherManageApplication.java | 2 +- src/main/java/org/weekly/weekly/ui/writer/SystemWriter.java | 3 +-- .../org/weekly/weekly/customer/JdbcCustomerRepositoryTest.java | 1 - 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/weekly/weekly/VoucherManageApplication.java b/src/main/java/org/weekly/weekly/VoucherManageApplication.java index 0f683a86d2..a176e6079e 100644 --- a/src/main/java/org/weekly/weekly/VoucherManageApplication.java +++ b/src/main/java/org/weekly/weekly/VoucherManageApplication.java @@ -11,4 +11,4 @@ public static void main(String[] args) { ApplicationContext context = SpringApplication.run(VoucherManageApplication.class, args); context.getBean(VoucherManagementController.class).start(); } -} \ No newline at end of file +} diff --git a/src/main/java/org/weekly/weekly/ui/writer/SystemWriter.java b/src/main/java/org/weekly/weekly/ui/writer/SystemWriter.java index 1d56634c89..e90184b18e 100644 --- a/src/main/java/org/weekly/weekly/ui/writer/SystemWriter.java +++ b/src/main/java/org/weekly/weekly/ui/writer/SystemWriter.java @@ -11,7 +11,7 @@ @Component @ConditionalOnProperty(value = "command.write", havingValue = "system") -public class SystemWriter implements CommandWriter{ +public class SystemWriter implements CommandWriter { private final Logger logger = LoggerFactory.getLogger(SystemWriter.class); private void println(String msg) { @@ -74,7 +74,6 @@ public void printDeleteMessage() { println(PrintMessageType.DELETE.getMessage()); } - private void printMenu(Menu[] menus, PrintMessageType programMessage) { println(PrintMessageType.EMPTY.getMessage()); println(programMessage.getMessage()); diff --git a/src/test/java/org/weekly/weekly/customer/JdbcCustomerRepositoryTest.java b/src/test/java/org/weekly/weekly/customer/JdbcCustomerRepositoryTest.java index 09a8cc664f..f13b0ded8d 100644 --- a/src/test/java/org/weekly/weekly/customer/JdbcCustomerRepositoryTest.java +++ b/src/test/java/org/weekly/weekly/customer/JdbcCustomerRepositoryTest.java @@ -13,7 +13,6 @@ import java.util.Optional; import java.util.UUID; -import static org.assertj.core.api.Assertions.assertThatCode; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; From 4a0f1be3290d35b5daa70bc558b40603b66cd01f Mon Sep 17 00:00:00 2001 From: parksey Date: Sat, 15 Jul 2023 01:04:27 +0900 Subject: [PATCH 19/28] =?UTF-8?q?refactor:=20db=20schema=EC=9C=84=EC=B9=98?= =?UTF-8?q?=20=EB=B3=80=EA=B2=BD=20=EB=B0=8F=20docker-compose=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 ++ docker/db-init/data.sql | 9 ++++++++ docker/db-init/schema.sql | 22 ++++++++++++++++++ docker/docker-compose.yaml | 23 +++++++++++++++++++ src/main/resources/application.yaml | 10 +++++++- src/main/resources/db-init/data.sql | 9 ++++++++ src/main/resources/db-init/schema.sql | 22 ++++++++++++++++++ src/main/resources/schema.sql | 9 -------- .../voucher/JdbcVoucherRepositoryTest.java | 1 - 9 files changed, 96 insertions(+), 11 deletions(-) create mode 100644 docker/db-init/data.sql create mode 100644 docker/db-init/schema.sql create mode 100644 docker/docker-compose.yaml create mode 100644 src/main/resources/db-init/data.sql create mode 100644 src/main/resources/db-init/schema.sql diff --git a/.gitignore b/.gitignore index 3cf37560c8..693673eff0 100644 --- a/.gitignore +++ b/.gitignore @@ -135,3 +135,5 @@ buildNumber.properties .classpath # End of https://www.toptal.com/developers/gitignore/api/java,intellij+all,maven + +docker/db \ No newline at end of file diff --git a/docker/db-init/data.sql b/docker/db-init/data.sql new file mode 100644 index 0000000000..119716bc80 --- /dev/null +++ b/docker/db-init/data.sql @@ -0,0 +1,9 @@ +INSERT INTO customers(customer_id, name, email) +VALUES (uuid_to_bin(UUID()), 'tester00', 'test00@gmail.com'), + (uuid_to_bin(UUID()), 'tester01', 'test01@gmail.com'), + (uuid_to_bin(UUID()), 'tester02', 'test02@gmail.com'); + +INSERT INTO vouchers (voucher_id, amount, discount, expiration_date) +VALUES (uuid_to_bin(UUID()), 50, 'PERCENT', DATE_ADD(CURRENT_TIMESTAMP(6), INTERVAL 7 DAY)), + (uuid_to_bin(UUID()), 100000, 'FIXED', DATE_ADD(CURRENT_TIMESTAMP(6), INTERVAL 7 DAY)), + (uuid_to_bin(UUID()), 80, 'PERCENT', DATE_ADD(CURRENT_TIMESTAMP(6), INTERVAL 7 DAY)); \ No newline at end of file diff --git a/docker/db-init/schema.sql b/docker/db-init/schema.sql new file mode 100644 index 0000000000..7ccc163507 --- /dev/null +++ b/docker/db-init/schema.sql @@ -0,0 +1,22 @@ +DROP TABLE IF EXISTS customers; +CREATE TABLE customers +( + customer_id BINARY(16) PRIMARY KEY, + name varchar(20) NOT NULL, + email varchar(50) NOT NULL, + create_at datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP (6), + CONSTRAINT unq_user_email UNIQUE (email) +); + + + +DROP TABLE IF EXISTS vouchers; +CREATE TABLE vouchers +( + voucher_id BINARY(16) PRIMARY KEY, + amount bigint NOT NULL, + discount enum('FIXED', 'PERCENT') NOT NULL, + registration_date datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP (6), + expiration_date datetime(6) NOT NULL +); + diff --git a/docker/docker-compose.yaml b/docker/docker-compose.yaml new file mode 100644 index 0000000000..af9c67f942 --- /dev/null +++ b/docker/docker-compose.yaml @@ -0,0 +1,23 @@ +version: "3.7" + +services: + voucher-db: + image: mysql + restart: always + environment: + MYSQL_ROOT_PASSWORD: "qwe123" + MYSQL_DATABASE: "voucher_mgmt" + MYSQL_USER: "test" + MYSQL_PASSWORD: "test" + TZ: Asia/Seoul + + command: + - --character-set-server=utf8mb4 + - --collation-server=utf8mb4_unicode_ci + + volumes: + - .db-init:/docker-entrypoint-initdb.d + - ./db/datadir/:/var/lib/mysql + + ports: + - 3306:3306 diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index 90244d6551..e0316ef90e 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -13,6 +13,10 @@ spring: sql: init: mode: always + schema-locations: + - classpath:db-init/schema.sql + data-locations: + - classpath:db-init/data.sql --- @@ -39,8 +43,12 @@ spring: datasource: url: jdbc:tc:mysql:8://test + sql: init: mode: always - + schema-locations: + - classpath:db-init/schema.sql + data-locations: + - classpath:db-init/data.sql diff --git a/src/main/resources/db-init/data.sql b/src/main/resources/db-init/data.sql new file mode 100644 index 0000000000..119716bc80 --- /dev/null +++ b/src/main/resources/db-init/data.sql @@ -0,0 +1,9 @@ +INSERT INTO customers(customer_id, name, email) +VALUES (uuid_to_bin(UUID()), 'tester00', 'test00@gmail.com'), + (uuid_to_bin(UUID()), 'tester01', 'test01@gmail.com'), + (uuid_to_bin(UUID()), 'tester02', 'test02@gmail.com'); + +INSERT INTO vouchers (voucher_id, amount, discount, expiration_date) +VALUES (uuid_to_bin(UUID()), 50, 'PERCENT', DATE_ADD(CURRENT_TIMESTAMP(6), INTERVAL 7 DAY)), + (uuid_to_bin(UUID()), 100000, 'FIXED', DATE_ADD(CURRENT_TIMESTAMP(6), INTERVAL 7 DAY)), + (uuid_to_bin(UUID()), 80, 'PERCENT', DATE_ADD(CURRENT_TIMESTAMP(6), INTERVAL 7 DAY)); \ No newline at end of file diff --git a/src/main/resources/db-init/schema.sql b/src/main/resources/db-init/schema.sql new file mode 100644 index 0000000000..7ccc163507 --- /dev/null +++ b/src/main/resources/db-init/schema.sql @@ -0,0 +1,22 @@ +DROP TABLE IF EXISTS customers; +CREATE TABLE customers +( + customer_id BINARY(16) PRIMARY KEY, + name varchar(20) NOT NULL, + email varchar(50) NOT NULL, + create_at datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP (6), + CONSTRAINT unq_user_email UNIQUE (email) +); + + + +DROP TABLE IF EXISTS vouchers; +CREATE TABLE vouchers +( + voucher_id BINARY(16) PRIMARY KEY, + amount bigint NOT NULL, + discount enum('FIXED', 'PERCENT') NOT NULL, + registration_date datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP (6), + expiration_date datetime(6) NOT NULL +); + diff --git a/src/main/resources/schema.sql b/src/main/resources/schema.sql index 883bbe234c..7ccc163507 100644 --- a/src/main/resources/schema.sql +++ b/src/main/resources/schema.sql @@ -8,11 +8,6 @@ CREATE TABLE customers CONSTRAINT unq_user_email UNIQUE (email) ); -INSERT INTO customers(customer_id, name, email) -VALUES (uuid_to_bin(UUID()), 'tester00', 'test00@gmail.com'), - (uuid_to_bin(UUID()), 'tester01', 'test01@gmail.com'), - (uuid_to_bin(UUID()), 'tester02', 'test02@gmail.com'); - DROP TABLE IF EXISTS vouchers; @@ -25,7 +20,3 @@ CREATE TABLE vouchers expiration_date datetime(6) NOT NULL ); -INSERT INTO vouchers (voucher_id, amount, discount, expiration_date) -VALUES (uuid_to_bin(UUID()), 50, 'PERCENT', DATE_ADD(CURRENT_TIMESTAMP(6), INTERVAL 7 DAY)), - (uuid_to_bin(UUID()), 100000, 'FIXED', DATE_ADD(CURRENT_TIMESTAMP(6), INTERVAL 7 DAY)), - (uuid_to_bin(UUID()), 80, 'PERCENT', DATE_ADD(CURRENT_TIMESTAMP(6), INTERVAL 7 DAY)); \ No newline at end of file diff --git a/src/test/java/org/weekly/weekly/voucher/JdbcVoucherRepositoryTest.java b/src/test/java/org/weekly/weekly/voucher/JdbcVoucherRepositoryTest.java index fff85f7737..105cbbf52b 100644 --- a/src/test/java/org/weekly/weekly/voucher/JdbcVoucherRepositoryTest.java +++ b/src/test/java/org/weekly/weekly/voucher/JdbcVoucherRepositoryTest.java @@ -35,7 +35,6 @@ class JdbcVoucherRepositoryTest { @Autowired private JdbcTemplate jdbcTemplate; - Voucher fixedVoucher; Voucher percentVoucher; From e5b4db1aae6e534566ef38c5bd4f3d747b526e53 Mon Sep 17 00:00:00 2001 From: parksey Date: Sat, 15 Jul 2023 03:01:30 +0900 Subject: [PATCH 20/28] =?UTF-8?q?feat:=20docker-compose=20=EC=8A=A4?= =?UTF-8?q?=ED=82=A4=EB=A7=88=20=ED=8C=8C=EC=9D=BC=EA=B3=BC=20=EB=8D=B0?= =?UTF-8?q?=EC=9D=B4=ED=84=B0=20=ED=8C=8C=EC=9D=BC=20=EB=B3=91=ED=95=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 +- docker/db-init/data.sql | 9 --------- docker/db-init/schema.sql | 9 +++++++++ docker/{docker-compose.yaml => docker-compose.yml} | 12 +++++------- 4 files changed, 15 insertions(+), 17 deletions(-) delete mode 100644 docker/db-init/data.sql rename docker/{docker-compose.yaml => docker-compose.yml} (70%) diff --git a/.gitignore b/.gitignore index 693673eff0..408f4ecce5 100644 --- a/.gitignore +++ b/.gitignore @@ -136,4 +136,4 @@ buildNumber.properties # End of https://www.toptal.com/developers/gitignore/api/java,intellij+all,maven -docker/db \ No newline at end of file +docker/database \ No newline at end of file diff --git a/docker/db-init/data.sql b/docker/db-init/data.sql deleted file mode 100644 index 119716bc80..0000000000 --- a/docker/db-init/data.sql +++ /dev/null @@ -1,9 +0,0 @@ -INSERT INTO customers(customer_id, name, email) -VALUES (uuid_to_bin(UUID()), 'tester00', 'test00@gmail.com'), - (uuid_to_bin(UUID()), 'tester01', 'test01@gmail.com'), - (uuid_to_bin(UUID()), 'tester02', 'test02@gmail.com'); - -INSERT INTO vouchers (voucher_id, amount, discount, expiration_date) -VALUES (uuid_to_bin(UUID()), 50, 'PERCENT', DATE_ADD(CURRENT_TIMESTAMP(6), INTERVAL 7 DAY)), - (uuid_to_bin(UUID()), 100000, 'FIXED', DATE_ADD(CURRENT_TIMESTAMP(6), INTERVAL 7 DAY)), - (uuid_to_bin(UUID()), 80, 'PERCENT', DATE_ADD(CURRENT_TIMESTAMP(6), INTERVAL 7 DAY)); \ No newline at end of file diff --git a/docker/db-init/schema.sql b/docker/db-init/schema.sql index 7ccc163507..108cf4a39b 100644 --- a/docker/db-init/schema.sql +++ b/docker/db-init/schema.sql @@ -8,6 +8,11 @@ CREATE TABLE customers CONSTRAINT unq_user_email UNIQUE (email) ); +INSERT INTO customers(customer_id, name, email) +VALUES (uuid_to_bin(UUID()), 'tester00', 'test00@gmail.com'), + (uuid_to_bin(UUID()), 'tester01', 'test01@gmail.com'), + (uuid_to_bin(UUID()), 'tester02', 'test02@gmail.com'); + DROP TABLE IF EXISTS vouchers; @@ -20,3 +25,7 @@ CREATE TABLE vouchers expiration_date datetime(6) NOT NULL ); +INSERT INTO vouchers (voucher_id, amount, discount, expiration_date) +VALUES (uuid_to_bin(UUID()), 50, 'PERCENT', DATE_ADD(CURRENT_TIMESTAMP(6), INTERVAL 7 DAY)), + (uuid_to_bin(UUID()), 100000, 'FIXED', DATE_ADD(CURRENT_TIMESTAMP(6), INTERVAL 7 DAY)), + (uuid_to_bin(UUID()), 80, 'PERCENT', DATE_ADD(CURRENT_TIMESTAMP(6), INTERVAL 7 DAY)); diff --git a/docker/docker-compose.yaml b/docker/docker-compose.yml similarity index 70% rename from docker/docker-compose.yaml rename to docker/docker-compose.yml index af9c67f942..6528d5e609 100644 --- a/docker/docker-compose.yaml +++ b/docker/docker-compose.yml @@ -1,7 +1,7 @@ version: "3.7" services: - voucher-db: + vacation-db: image: mysql restart: always environment: @@ -10,14 +10,12 @@ services: MYSQL_USER: "test" MYSQL_PASSWORD: "test" TZ: Asia/Seoul - command: - --character-set-server=utf8mb4 - --collation-server=utf8mb4_unicode_ci - volumes: - - .db-init:/docker-entrypoint-initdb.d - - ./db/datadir/:/var/lib/mysql - + - ./db-init:/docker-entrypoint-initdb.d + - ./database/datadir/:/var/lib/mysql + platform: linux/x86_64 ports: - - 3306:3306 + - 3306:3306 \ No newline at end of file From 065a19b6b319356b17ac204b0b103b082d827b3b Mon Sep 17 00:00:00 2001 From: parksey Date: Sat, 15 Jul 2023 05:36:50 +0900 Subject: [PATCH 21/28] =?UTF-8?q?feat:=20ExceptionMessage=20enum=20?= =?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A4=20->=20ExceptionCode=EB=A1=9C=20?= =?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A4=EB=AA=85=20=EB=B3=80=EA=B2=BD=20?= =?UTF-8?q?=EB=B0=8F=20=EC=83=81=ED=83=9C=EC=BD=94=EB=93=9C=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80,=20=EC=98=88=EC=99=B8=20=EC=B2=98=EB=A6=AC=ED=95=98?= =?UTF-8?q?=EB=8A=94=20ApiAdvisor=ED=81=B4=EB=9E=98=EC=8A=A4=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weekly/weekly/api/advice/ApiAdvisor.java | 51 +++++++++++++++++++ .../weekly/weekly/api/dto/ErrorResponse.java | 19 +++++++ .../customer/exception/CustomerException.java | 13 +++-- .../customer/exception/CustomerValidator.java | 6 +-- .../repository/JdbcCustomerRepository.java | 6 +-- .../customer/service/CustomerService.java | 6 +-- .../weekly/ui/exception/InputException.java | 6 +-- .../weekly/ui/exception/InputValidator.java | 10 ++-- .../weekly/ui/reader/BufferedReaderWrap.java | 4 +- .../org/weekly/weekly/util/CustomerMenu.java | 2 +- .../org/weekly/weekly/util/ExceptionCode.java | 40 +++++++++++++++ .../org/weekly/weekly/util/ExceptionMsg.java | 31 ----------- .../org/weekly/weekly/util/ManageMenu.java | 2 +- .../org/weekly/weekly/util/VoucherMenu.java | 2 +- .../weekly/voucher/domain/DiscountType.java | 8 +-- .../voucher/exception/VoucherException.java | 13 +++-- .../voucher/exception/VoucherValidator.java | 8 +-- .../repository/JdbcVoucherRepository.java | 8 +-- .../repository/MemoryVoucherRepository.java | 4 +- src/main/resources/schema.sql | 22 -------- 20 files changed, 166 insertions(+), 95 deletions(-) create mode 100644 src/main/java/org/weekly/weekly/api/advice/ApiAdvisor.java create mode 100644 src/main/java/org/weekly/weekly/api/dto/ErrorResponse.java create mode 100644 src/main/java/org/weekly/weekly/util/ExceptionCode.java delete mode 100644 src/main/java/org/weekly/weekly/util/ExceptionMsg.java delete mode 100644 src/main/resources/schema.sql diff --git a/src/main/java/org/weekly/weekly/api/advice/ApiAdvisor.java b/src/main/java/org/weekly/weekly/api/advice/ApiAdvisor.java new file mode 100644 index 0000000000..f2af24e9da --- /dev/null +++ b/src/main/java/org/weekly/weekly/api/advice/ApiAdvisor.java @@ -0,0 +1,51 @@ +package org.weekly.weekly.api.advice; + +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatusCode; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; +import org.springframework.web.context.request.WebRequest; +import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; +import org.weekly.weekly.api.dto.ErrorResponse; +import org.weekly.weekly.customer.exception.CustomerException; +import org.weekly.weekly.util.ExceptionCode; +import org.weekly.weekly.voucher.exception.VoucherException; + +@RestControllerAdvice +public class ApiAdvisor extends ResponseEntityExceptionHandler { + + @ExceptionHandler({VoucherException.class}) + public ResponseEntity handleVoucherException(VoucherException exception) { + return handleExceptionInternal(exception.getExceptionCode()); + } + + @ExceptionHandler({CustomerException.class}) + public ResponseEntity handleCustomerException(CustomerException customerException) { + return handleExceptionInternal(customerException.getExceptionCode()); + } + + @ExceptionHandler({RuntimeException.class}) + public ResponseEntity handleGlobalExcpetion(RuntimeException runtimeException) { + return handleExceptionInternal(ExceptionCode.NOT_ACCESS, runtimeException.getMessage()); + } + + private ResponseEntity handleExceptionInternal(ExceptionCode exceptionCode) { + return ResponseEntity.status(exceptionCode.getHttpStatus()) + .body(errorResponse(exceptionCode.name(), exceptionCode.getMessage())); + } + + private ResponseEntity handleExceptionInternal(ExceptionCode exceptionCode, String message) { + return ResponseEntity.status(exceptionCode.getHttpStatus()) + .body(errorResponse(exceptionCode.name(), message)); + } + + private ErrorResponse errorResponse(String code, String message) { + return new ErrorResponse(code, message); + } + + @Override + protected ResponseEntity handleExceptionInternal(Exception ex, Object body, HttpHeaders headers, HttpStatusCode statusCode, WebRequest request) { + return super.handleExceptionInternal(ex, body, headers, statusCode, request); + } +} diff --git a/src/main/java/org/weekly/weekly/api/dto/ErrorResponse.java b/src/main/java/org/weekly/weekly/api/dto/ErrorResponse.java new file mode 100644 index 0000000000..a68dc4ada8 --- /dev/null +++ b/src/main/java/org/weekly/weekly/api/dto/ErrorResponse.java @@ -0,0 +1,19 @@ +package org.weekly.weekly.api.dto; + +public class ErrorResponse { + private String code; + private String message; + + public ErrorResponse(String code, String message) { + this.code = code; + this.message = message; + } + + public String getMessage() { + return message; + } + + public String getCode() { + return code; + } +} diff --git a/src/main/java/org/weekly/weekly/customer/exception/CustomerException.java b/src/main/java/org/weekly/weekly/customer/exception/CustomerException.java index c27d38c0bd..24fedce726 100644 --- a/src/main/java/org/weekly/weekly/customer/exception/CustomerException.java +++ b/src/main/java/org/weekly/weekly/customer/exception/CustomerException.java @@ -1,9 +1,16 @@ package org.weekly.weekly.customer.exception; -import org.weekly.weekly.util.ExceptionMsg; +import org.weekly.weekly.util.ExceptionCode; public class CustomerException extends RuntimeException { - public CustomerException(ExceptionMsg exceptionMsg) { - super(exceptionMsg.getMsg()); + private final ExceptionCode exceptionCode; + + public CustomerException(ExceptionCode exceptionMsg) { + super(exceptionMsg.getMessage()); + this.exceptionCode = exceptionMsg; + } + + public ExceptionCode getExceptionCode() { + return exceptionCode; } } diff --git a/src/main/java/org/weekly/weekly/customer/exception/CustomerValidator.java b/src/main/java/org/weekly/weekly/customer/exception/CustomerValidator.java index 8a11a8f573..0c28fa5149 100644 --- a/src/main/java/org/weekly/weekly/customer/exception/CustomerValidator.java +++ b/src/main/java/org/weekly/weekly/customer/exception/CustomerValidator.java @@ -1,6 +1,6 @@ package org.weekly.weekly.customer.exception; -import org.weekly.weekly.util.ExceptionMsg; +import org.weekly.weekly.util.ExceptionCode; import java.util.regex.Pattern; @@ -8,12 +8,12 @@ public class CustomerValidator { private static final String EMAIL_FORMAT = "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,3}$"; private CustomerValidator() { - throw new CustomerException(ExceptionMsg.UTIL_CLASS); + throw new CustomerException(ExceptionCode.UTIL_CLASS); } public static void validateEmailFormat(String email) { if (!Pattern.matches(EMAIL_FORMAT, email)) { - throw new CustomerException(ExceptionMsg.NOT_EMAIL_FORMAT); + throw new CustomerException(ExceptionCode.NOT_EMAIL_FORMAT); } } } diff --git a/src/main/java/org/weekly/weekly/customer/repository/JdbcCustomerRepository.java b/src/main/java/org/weekly/weekly/customer/repository/JdbcCustomerRepository.java index 3afd981ee2..7e374682bc 100644 --- a/src/main/java/org/weekly/weekly/customer/repository/JdbcCustomerRepository.java +++ b/src/main/java/org/weekly/weekly/customer/repository/JdbcCustomerRepository.java @@ -6,7 +6,7 @@ import org.springframework.stereotype.Repository; import org.weekly.weekly.customer.domain.Customer; import org.weekly.weekly.customer.exception.CustomerException; -import org.weekly.weekly.util.ExceptionMsg; +import org.weekly.weekly.util.ExceptionCode; import javax.sql.DataSource; import java.nio.ByteBuffer; @@ -42,7 +42,7 @@ public Customer insert(Customer customer) { Timestamp.valueOf(customer.getCreateAt())); if (insert != 1) { - throw new CustomerException(ExceptionMsg.SQL_INSERT_ERROR); + throw new CustomerException(ExceptionCode.SQL_INSERT_ERROR); } return customer; } @@ -88,7 +88,7 @@ public Customer update(Customer customer, String newEmail) { beforeEmail); if (update != 1) { - throw new CustomerException(ExceptionMsg.SQL_ERROR); + throw new CustomerException(ExceptionCode.SQL_ERROR); } return customer; } diff --git a/src/main/java/org/weekly/weekly/customer/service/CustomerService.java b/src/main/java/org/weekly/weekly/customer/service/CustomerService.java index 3330ba08ab..43ac44e252 100644 --- a/src/main/java/org/weekly/weekly/customer/service/CustomerService.java +++ b/src/main/java/org/weekly/weekly/customer/service/CustomerService.java @@ -9,7 +9,7 @@ import org.weekly.weekly.customer.dto.response.CustomersResponse; import org.weekly.weekly.customer.exception.CustomerException; import org.weekly.weekly.customer.repository.CustomerRepository; -import org.weekly.weekly.util.ExceptionMsg; +import org.weekly.weekly.util.ExceptionCode; import java.util.List; import java.util.Optional; @@ -73,14 +73,14 @@ public CustomerResponse updateCustomer(CustomerUpdateRequest updateRequest) { private void validateCustomerNotExist(String email) { Optional findCustomer = customerRepository.findByEmail(email); if (findCustomer.isPresent()) { - throw new CustomerException(ExceptionMsg.SQL_EXIST); + throw new CustomerException(ExceptionCode.SQL_EXIST); } } private Customer validateCustomerExistAndGet(String email) { Optional customer = customerRepository.findByEmail(email); if (customer.isEmpty()) { - throw new CustomerException(ExceptionMsg.SQL_ERROR); + throw new CustomerException(ExceptionCode.SQL_ERROR); } return customer.get(); } diff --git a/src/main/java/org/weekly/weekly/ui/exception/InputException.java b/src/main/java/org/weekly/weekly/ui/exception/InputException.java index 942215bf0c..dae1f441ff 100644 --- a/src/main/java/org/weekly/weekly/ui/exception/InputException.java +++ b/src/main/java/org/weekly/weekly/ui/exception/InputException.java @@ -1,10 +1,10 @@ package org.weekly.weekly.ui.exception; -import org.weekly.weekly.util.ExceptionMsg; +import org.weekly.weekly.util.ExceptionCode; public class InputException extends RuntimeException { - public InputException(ExceptionMsg exception) { - super(exception.getMsg()); + public InputException(ExceptionCode exception) { + super(exception.getMessage()); } } diff --git a/src/main/java/org/weekly/weekly/ui/exception/InputValidator.java b/src/main/java/org/weekly/weekly/ui/exception/InputValidator.java index 7c0bcef72a..55c5251322 100644 --- a/src/main/java/org/weekly/weekly/ui/exception/InputValidator.java +++ b/src/main/java/org/weekly/weekly/ui/exception/InputValidator.java @@ -1,26 +1,26 @@ package org.weekly.weekly.ui.exception; -import org.weekly.weekly.util.ExceptionMsg; +import org.weekly.weekly.util.ExceptionCode; import java.util.Arrays; public class InputValidator { private InputValidator() { - throw new InputException(ExceptionMsg.UTIL_CLASS); + throw new InputException(ExceptionCode.UTIL_CLASS); } private static final int VOUCHER_INPUT_SIZE = 2; public static void isEmpty(String userInput) { if (userInput == null || userInput.isBlank()) { - throw new InputException(ExceptionMsg.EMPTY); + throw new InputException(ExceptionCode.EMPTY); } } public static void notVoucherInputSize(String[] userInputs) { if (userInputs.length != VOUCHER_INPUT_SIZE) { - throw new InputException(ExceptionMsg.NOT_SAME_PARAM_SIZE); + throw new InputException(ExceptionCode.NOT_SAME_PARAM_SIZE); } } @@ -29,7 +29,7 @@ public static void notNumber(String[] userInputs) { Arrays.stream(userInputs) .peek(Long::parseLong); } catch (NumberFormatException exception) { - throw new InputException(ExceptionMsg.NOT_INPUT_FORMAT); + throw new InputException(ExceptionCode.NOT_INPUT_FORMAT); } } } diff --git a/src/main/java/org/weekly/weekly/ui/reader/BufferedReaderWrap.java b/src/main/java/org/weekly/weekly/ui/reader/BufferedReaderWrap.java index a95ecd5298..1b49b51592 100644 --- a/src/main/java/org/weekly/weekly/ui/reader/BufferedReaderWrap.java +++ b/src/main/java/org/weekly/weekly/ui/reader/BufferedReaderWrap.java @@ -3,7 +3,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.stereotype.Component; import org.weekly.weekly.ui.exception.InputException; -import org.weekly.weekly.util.ExceptionMsg; +import org.weekly.weekly.util.ExceptionCode; import java.io.BufferedReader; import java.io.IOException; @@ -23,7 +23,7 @@ public String readLine() { try { return bufferedReader.readLine(); } catch (IOException exception) { - throw new InputException(ExceptionMsg.NOT_INPUT_FORMAT); + throw new InputException(ExceptionCode.NOT_INPUT_FORMAT); } } } diff --git a/src/main/java/org/weekly/weekly/util/CustomerMenu.java b/src/main/java/org/weekly/weekly/util/CustomerMenu.java index 9b40a257a1..2a1f4603f4 100644 --- a/src/main/java/org/weekly/weekly/util/CustomerMenu.java +++ b/src/main/java/org/weekly/weekly/util/CustomerMenu.java @@ -32,7 +32,7 @@ public static CustomerMenu getMenu(String userInput) { if (CUSTOMER_MENU_MAP.containsKey(userInput)) { return CUSTOMER_MENU_MAP.get(userInput); } - throw new CustomerException(ExceptionMsg.NOT_MENU); + throw new CustomerException(ExceptionCode.NOT_MENU); } @Override diff --git a/src/main/java/org/weekly/weekly/util/ExceptionCode.java b/src/main/java/org/weekly/weekly/util/ExceptionCode.java new file mode 100644 index 0000000000..3b1ffbefc1 --- /dev/null +++ b/src/main/java/org/weekly/weekly/util/ExceptionCode.java @@ -0,0 +1,40 @@ +package org.weekly.weekly.util; + +import org.springframework.http.HttpStatus; + +public enum ExceptionCode { + ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "[ERROR]: "), + NOT_ACCESS(HttpStatus.FORBIDDEN, "잘못된 접근"), + UTIL_CLASS(HttpStatus.BAD_REQUEST, "유틸 클래스입니다."), + EMPTY(HttpStatus.BAD_REQUEST, "사용자가 아무 값도 입력하지 않았습니다."), + NOT_INPUT_FORMAT(HttpStatus.BAD_REQUEST, "입력 형식에 맞지 않습니다."), + NOT_MENU(HttpStatus.NOT_FOUND, "해당 메뉴는 존재하지 않습니다."), + NOT_NUMBER_FORMAT(HttpStatus.BAD_REQUEST, "허용되지 않는 값입니다."), + NOT_NATURAL_NUMBER(HttpStatus.BAD_REQUEST, "자연수가 아닙니다."), + NOT_DISCOUNT(HttpStatus.BAD_REQUEST, "할인 종류가 아닙니다."), + EXPIRATION_ERROR(HttpStatus.BAD_REQUEST, "유효기간이 등록기간보다 빠릅니다."), + VOUCHER_EXIST(HttpStatus.CONFLICT, "이미 존재하는 바우처입니다."), + NOT_FOUND(HttpStatus.BAD_REQUEST, "해당 종류의 할인정보를 찾을 수 없습니다."), + NOT_SAME_PARAM_SIZE(HttpStatus.BAD_REQUEST,"입력 파라미터 개수가 맞지 않습니다."), + NOT_EMAIL_FORMAT(HttpStatus.BAD_REQUEST, "이메일형식이 아닙니다."), + SQL_ERROR(HttpStatus.INTERNAL_SERVER_ERROR,"값을 가져오기 실패"), + SQL_INSERT_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "값 추가 실패"), + SQL_EXIST(HttpStatus.CONFLICT, "이미 존재합니다."), + SQL_DELETE_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "삭제 실패"); + + private final String message; + private final HttpStatus httpStatus; + + ExceptionCode(HttpStatus httpStatus, String message) { + this.httpStatus = httpStatus; + this.message = message; + } + + public String getMessage() { + return ERROR.message + message; + } + + public HttpStatus getHttpStatus() { + return httpStatus; + } +} diff --git a/src/main/java/org/weekly/weekly/util/ExceptionMsg.java b/src/main/java/org/weekly/weekly/util/ExceptionMsg.java deleted file mode 100644 index 472bffd19e..0000000000 --- a/src/main/java/org/weekly/weekly/util/ExceptionMsg.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.weekly.weekly.util; - -public enum ExceptionMsg { - ERROR("[ERROR]: "), - UTIL_CLASS("유틸 클래스입니다."), - EMPTY("사용자가 아무 값도 입력하지 않았습니다."), - NOT_INPUT_FORMAT("입력 형식에 맞지 않습니다."), - NOT_MENU("해당 메뉴는 존재하지 않습니다."), - NOT_NUMBER_FORMAT("허용되지 않는 값입니다."), - NOT_NATURAL_NUMBER("자연수가 아닙니다."), - NOT_DISCOUNT("할인 종류가 아닙니다."), - EXPIRATION_ERROR("유효기간이 등록기간보다 빠릅니다."), - VOUCHER_EXIST("이미 존재하는 바우처입니다."), - NOT_FOUND("해당 종류의 할인정보를 찾을 수 없습니다."), - NOT_SAME_PARAM_SIZE("입력 파라미터 개수가 맞지 않습니다."), - NOT_EMAIL_FORMAT("이메일형식이 아닙니다."), - SQL_ERROR("값을 가져오기 실패"), - SQL_INSERT_ERROR("값 추가 실패"), - SQL_EXIST("이미 존재합니다."), - SQL_DELETE_ERROR("삭제 실패"); - - private final String msg; - - ExceptionMsg(String msg) { - this.msg = msg; - } - - public String getMsg() { - return ERROR.msg + msg; - } -} diff --git a/src/main/java/org/weekly/weekly/util/ManageMenu.java b/src/main/java/org/weekly/weekly/util/ManageMenu.java index fcd829a672..4637ebaf24 100644 --- a/src/main/java/org/weekly/weekly/util/ManageMenu.java +++ b/src/main/java/org/weekly/weekly/util/ManageMenu.java @@ -26,7 +26,7 @@ public static ManageMenu getMenu(String userInput) { if (MANAGE_MENU_MAP.containsKey(userInput)) { return MANAGE_MENU_MAP.get(userInput); } - throw new RuntimeException(ExceptionMsg.NOT_MENU.getMsg()); + throw new RuntimeException(ExceptionCode.NOT_MENU.getMessage()); } @Override diff --git a/src/main/java/org/weekly/weekly/util/VoucherMenu.java b/src/main/java/org/weekly/weekly/util/VoucherMenu.java index 27d415def8..0b61669037 100644 --- a/src/main/java/org/weekly/weekly/util/VoucherMenu.java +++ b/src/main/java/org/weekly/weekly/util/VoucherMenu.java @@ -28,7 +28,7 @@ public static VoucherMenu getMenu(String userInput) { if (VOUCHER_MENU_MAP.containsKey(userInput)) { return VOUCHER_MENU_MAP.get(userInput); } - throw new VoucherException(ExceptionMsg.NOT_MENU); + throw new VoucherException(ExceptionCode.NOT_MENU); } @Override diff --git a/src/main/java/org/weekly/weekly/voucher/domain/DiscountType.java b/src/main/java/org/weekly/weekly/voucher/domain/DiscountType.java index a48bb94485..4bff10995a 100644 --- a/src/main/java/org/weekly/weekly/voucher/domain/DiscountType.java +++ b/src/main/java/org/weekly/weekly/voucher/domain/DiscountType.java @@ -1,6 +1,6 @@ package org.weekly.weekly.voucher.domain; -import org.weekly.weekly.util.ExceptionMsg; +import org.weekly.weekly.util.ExceptionCode; import org.weekly.weekly.voucher.exception.VoucherException; import java.lang.reflect.InvocationTargetException; @@ -38,7 +38,7 @@ public static DiscountType getDiscountTypeByNumber(String no) { if (discuontTypeMap.containsKey(no)) { return discuontTypeMap.get(no); } - throw new VoucherException(ExceptionMsg.NOT_DISCOUNT); + throw new VoucherException(ExceptionCode.NOT_DISCOUNT); } public static DiscountType getDiscountTypeByName(String name) { @@ -47,7 +47,7 @@ public static DiscountType getDiscountTypeByName(String name) { return discount; } } - throw new VoucherException(ExceptionMsg.NOT_DISCOUNT); + throw new VoucherException(ExceptionCode.NOT_DISCOUNT); } public Discount getNewInstance() { @@ -55,7 +55,7 @@ public Discount getNewInstance() { return this.cls.getDeclaredConstructor().newInstance(); } catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException exception) { - throw new VoucherException(ExceptionMsg.NOT_FOUND); + throw new VoucherException(ExceptionCode.NOT_FOUND); } } diff --git a/src/main/java/org/weekly/weekly/voucher/exception/VoucherException.java b/src/main/java/org/weekly/weekly/voucher/exception/VoucherException.java index af4e344daa..c2968fb684 100644 --- a/src/main/java/org/weekly/weekly/voucher/exception/VoucherException.java +++ b/src/main/java/org/weekly/weekly/voucher/exception/VoucherException.java @@ -1,9 +1,16 @@ package org.weekly.weekly.voucher.exception; -import org.weekly.weekly.util.ExceptionMsg; +import org.weekly.weekly.util.ExceptionCode; public class VoucherException extends RuntimeException { - public VoucherException(ExceptionMsg exceptionMsg) { - super(exceptionMsg.getMsg()); + private final ExceptionCode exceptionCode; + + public VoucherException(ExceptionCode exceptionMsg) { + super(exceptionMsg.getMessage()); + this.exceptionCode = exceptionMsg; + } + + public ExceptionCode getExceptionCode() { + return exceptionCode; } } diff --git a/src/main/java/org/weekly/weekly/voucher/exception/VoucherValidator.java b/src/main/java/org/weekly/weekly/voucher/exception/VoucherValidator.java index 6b7df0dcfd..d4508b9eaf 100644 --- a/src/main/java/org/weekly/weekly/voucher/exception/VoucherValidator.java +++ b/src/main/java/org/weekly/weekly/voucher/exception/VoucherValidator.java @@ -1,6 +1,6 @@ package org.weekly.weekly.voucher.exception; -import org.weekly.weekly.util.ExceptionMsg; +import org.weekly.weekly.util.ExceptionCode; import org.weekly.weekly.voucher.domain.DiscountType; import java.time.LocalDate; @@ -11,14 +11,14 @@ public class VoucherValidator { private static final int RANGE_END = 100; private VoucherValidator() { - throw new VoucherException(ExceptionMsg.UTIL_CLASS); + throw new VoucherException(ExceptionCode.UTIL_CLASS); } public static void validateExpiration(LocalDate registrationDate, long expirationMonth) { LocalDate expirationDate = registrationDate.plusMonths(expirationMonth); if (registrationDate.isEqual(expirationDate) || registrationDate.isAfter(expirationDate)) { - throw new VoucherException(ExceptionMsg.EXPIRATION_ERROR); + throw new VoucherException(ExceptionCode.EXPIRATION_ERROR); } } @@ -33,7 +33,7 @@ public static void validateAmount(DiscountType discountType, long amount) { private static void notRange(long userInput, LongPredicate ifCase) { if (ifCase.test(userInput)) { - throw new VoucherException(ExceptionMsg.NOT_NUMBER_FORMAT); + throw new VoucherException(ExceptionCode.NOT_NUMBER_FORMAT); } } } diff --git a/src/main/java/org/weekly/weekly/voucher/repository/JdbcVoucherRepository.java b/src/main/java/org/weekly/weekly/voucher/repository/JdbcVoucherRepository.java index 22abe80ef8..02ff443f38 100644 --- a/src/main/java/org/weekly/weekly/voucher/repository/JdbcVoucherRepository.java +++ b/src/main/java/org/weekly/weekly/voucher/repository/JdbcVoucherRepository.java @@ -5,7 +5,7 @@ import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Repository; -import org.weekly.weekly.util.ExceptionMsg; +import org.weekly.weekly.util.ExceptionCode; import org.weekly.weekly.voucher.domain.DiscountType; import org.weekly.weekly.voucher.domain.Voucher; import org.weekly.weekly.voucher.exception.VoucherException; @@ -72,11 +72,11 @@ public Voucher insert(Voucher voucher) { Timestamp.valueOf(voucher.getRegistrationDate().atStartOfDay()), Timestamp.valueOf(voucher.getExpirationDate().atStartOfDay())); } catch (DataAccessException dataAccessException) { - throw new VoucherException(ExceptionMsg.SQL_INSERT_ERROR); + throw new VoucherException(ExceptionCode.SQL_INSERT_ERROR); } if (update != 1) { - throw new VoucherException(ExceptionMsg.SQL_ERROR); + throw new VoucherException(ExceptionCode.SQL_ERROR); } return voucher; } @@ -91,7 +91,7 @@ public Voucher update(Voucher voucher) { Timestamp.valueOf(voucher.getExpirationDate().atStartOfDay()), uuidToBytes(voucher.getVoucherId())); if (update != 1) { - throw new VoucherException(ExceptionMsg.SQL_ERROR); + throw new VoucherException(ExceptionCode.SQL_ERROR); } return voucher; } diff --git a/src/main/java/org/weekly/weekly/voucher/repository/MemoryVoucherRepository.java b/src/main/java/org/weekly/weekly/voucher/repository/MemoryVoucherRepository.java index f3fc811034..21e9bd721e 100644 --- a/src/main/java/org/weekly/weekly/voucher/repository/MemoryVoucherRepository.java +++ b/src/main/java/org/weekly/weekly/voucher/repository/MemoryVoucherRepository.java @@ -2,7 +2,7 @@ import org.springframework.context.annotation.Profile; import org.springframework.stereotype.Repository; -import org.weekly.weekly.util.ExceptionMsg; +import org.weekly.weekly.util.ExceptionCode; import org.weekly.weekly.voucher.domain.DiscountType; import org.weekly.weekly.voucher.domain.Voucher; import org.weekly.weekly.voucher.exception.VoucherException; @@ -56,7 +56,7 @@ public void deleteAll() { private void validateUUID(UUID uuid) { Optional voucherOptional = findById(uuid); if (voucherOptional.isPresent()) { - throw new VoucherException(ExceptionMsg.VOUCHER_EXIST); + throw new VoucherException(ExceptionCode.VOUCHER_EXIST); } } } diff --git a/src/main/resources/schema.sql b/src/main/resources/schema.sql deleted file mode 100644 index 7ccc163507..0000000000 --- a/src/main/resources/schema.sql +++ /dev/null @@ -1,22 +0,0 @@ -DROP TABLE IF EXISTS customers; -CREATE TABLE customers -( - customer_id BINARY(16) PRIMARY KEY, - name varchar(20) NOT NULL, - email varchar(50) NOT NULL, - create_at datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP (6), - CONSTRAINT unq_user_email UNIQUE (email) -); - - - -DROP TABLE IF EXISTS vouchers; -CREATE TABLE vouchers -( - voucher_id BINARY(16) PRIMARY KEY, - amount bigint NOT NULL, - discount enum('FIXED', 'PERCENT') NOT NULL, - registration_date datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP (6), - expiration_date datetime(6) NOT NULL -); - From 26ab28db3a01b69d500ccb99f1dc8ada93bda9c2 Mon Sep 17 00:00:00 2001 From: parksey Date: Sat, 15 Jul 2023 05:52:30 +0900 Subject: [PATCH 22/28] =?UTF-8?q?refactor:=20ApiAdvisor=20->=20APIExceptio?= =?UTF-8?q?nHandler=EB=A1=9C=20=ED=81=B4=EB=9E=98=EC=8A=A4=EB=AA=85=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD,=20=EC=9E=98=EB=AA=BB=EB=90=9C=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=EB=AA=85=20=EB=B3=80=EA=B2=BD,=20=EB=B0=98?= =?UTF-8?q?=ED=99=98=20=ED=83=80=EC=9E=85=20=EB=AA=85=EC=8B=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...iAdvisor.java => APIExceptionHandler.java} | 22 ++++++------------- .../weekly/weekly/api/dto/ErrorResponse.java | 4 ++-- .../org/weekly/weekly/util/ExceptionCode.java | 4 ++-- .../org/weekly/weekly/util/VoucherMenu.java | 1 + 4 files changed, 12 insertions(+), 19 deletions(-) rename src/main/java/org/weekly/weekly/api/advice/{ApiAdvisor.java => APIExceptionHandler.java} (59%) diff --git a/src/main/java/org/weekly/weekly/api/advice/ApiAdvisor.java b/src/main/java/org/weekly/weekly/api/advice/APIExceptionHandler.java similarity index 59% rename from src/main/java/org/weekly/weekly/api/advice/ApiAdvisor.java rename to src/main/java/org/weekly/weekly/api/advice/APIExceptionHandler.java index f2af24e9da..28ca1447c9 100644 --- a/src/main/java/org/weekly/weekly/api/advice/ApiAdvisor.java +++ b/src/main/java/org/weekly/weekly/api/advice/APIExceptionHandler.java @@ -1,41 +1,38 @@ package org.weekly.weekly.api.advice; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpStatusCode; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; -import org.springframework.web.context.request.WebRequest; import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; import org.weekly.weekly.api.dto.ErrorResponse; import org.weekly.weekly.customer.exception.CustomerException; import org.weekly.weekly.util.ExceptionCode; import org.weekly.weekly.voucher.exception.VoucherException; -@RestControllerAdvice -public class ApiAdvisor extends ResponseEntityExceptionHandler { +@RestControllerAdvice(basePackages = {"org.weekly.weekly.api"}) +public class APIExceptionHandler extends ResponseEntityExceptionHandler { @ExceptionHandler({VoucherException.class}) - public ResponseEntity handleVoucherException(VoucherException exception) { + public ResponseEntity handleVoucherException(VoucherException exception) { return handleExceptionInternal(exception.getExceptionCode()); } @ExceptionHandler({CustomerException.class}) - public ResponseEntity handleCustomerException(CustomerException customerException) { + public ResponseEntity handleCustomerException(CustomerException customerException) { return handleExceptionInternal(customerException.getExceptionCode()); } @ExceptionHandler({RuntimeException.class}) - public ResponseEntity handleGlobalExcpetion(RuntimeException runtimeException) { + public ResponseEntity handleGlobalException(RuntimeException runtimeException) { return handleExceptionInternal(ExceptionCode.NOT_ACCESS, runtimeException.getMessage()); } - private ResponseEntity handleExceptionInternal(ExceptionCode exceptionCode) { + private ResponseEntity handleExceptionInternal(ExceptionCode exceptionCode) { return ResponseEntity.status(exceptionCode.getHttpStatus()) .body(errorResponse(exceptionCode.name(), exceptionCode.getMessage())); } - private ResponseEntity handleExceptionInternal(ExceptionCode exceptionCode, String message) { + private ResponseEntity handleExceptionInternal(ExceptionCode exceptionCode, String message) { return ResponseEntity.status(exceptionCode.getHttpStatus()) .body(errorResponse(exceptionCode.name(), message)); } @@ -43,9 +40,4 @@ private ResponseEntity handleExceptionInternal(ExceptionCode exceptionCode, Stri private ErrorResponse errorResponse(String code, String message) { return new ErrorResponse(code, message); } - - @Override - protected ResponseEntity handleExceptionInternal(Exception ex, Object body, HttpHeaders headers, HttpStatusCode statusCode, WebRequest request) { - return super.handleExceptionInternal(ex, body, headers, statusCode, request); - } } diff --git a/src/main/java/org/weekly/weekly/api/dto/ErrorResponse.java b/src/main/java/org/weekly/weekly/api/dto/ErrorResponse.java index a68dc4ada8..39f8e3197a 100644 --- a/src/main/java/org/weekly/weekly/api/dto/ErrorResponse.java +++ b/src/main/java/org/weekly/weekly/api/dto/ErrorResponse.java @@ -1,8 +1,8 @@ package org.weekly.weekly.api.dto; public class ErrorResponse { - private String code; - private String message; + private final String code; + private final String message; public ErrorResponse(String code, String message) { this.code = code; diff --git a/src/main/java/org/weekly/weekly/util/ExceptionCode.java b/src/main/java/org/weekly/weekly/util/ExceptionCode.java index 3b1ffbefc1..46c052122c 100644 --- a/src/main/java/org/weekly/weekly/util/ExceptionCode.java +++ b/src/main/java/org/weekly/weekly/util/ExceptionCode.java @@ -15,9 +15,9 @@ public enum ExceptionCode { EXPIRATION_ERROR(HttpStatus.BAD_REQUEST, "유효기간이 등록기간보다 빠릅니다."), VOUCHER_EXIST(HttpStatus.CONFLICT, "이미 존재하는 바우처입니다."), NOT_FOUND(HttpStatus.BAD_REQUEST, "해당 종류의 할인정보를 찾을 수 없습니다."), - NOT_SAME_PARAM_SIZE(HttpStatus.BAD_REQUEST,"입력 파라미터 개수가 맞지 않습니다."), + NOT_SAME_PARAM_SIZE(HttpStatus.BAD_REQUEST, "입력 파라미터 개수가 맞지 않습니다."), NOT_EMAIL_FORMAT(HttpStatus.BAD_REQUEST, "이메일형식이 아닙니다."), - SQL_ERROR(HttpStatus.INTERNAL_SERVER_ERROR,"값을 가져오기 실패"), + SQL_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "값을 가져오기 실패"), SQL_INSERT_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "값 추가 실패"), SQL_EXIST(HttpStatus.CONFLICT, "이미 존재합니다."), SQL_DELETE_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "삭제 실패"); diff --git a/src/main/java/org/weekly/weekly/util/VoucherMenu.java b/src/main/java/org/weekly/weekly/util/VoucherMenu.java index 0b61669037..a81bc60df0 100644 --- a/src/main/java/org/weekly/weekly/util/VoucherMenu.java +++ b/src/main/java/org/weekly/weekly/util/VoucherMenu.java @@ -10,6 +10,7 @@ public enum VoucherMenu implements Menu { EXIT("Type exit to exit the program."), CREATE("Type create to create a new voucher."), LIST("Type list to list all vouchers."); + private final String printMessage; private final static Map VOUCHER_MENU_MAP; From b2029495410cee581a569f130e3c1b880f384e5a Mon Sep 17 00:00:00 2001 From: parksey Date: Sat, 15 Jul 2023 13:34:53 +0900 Subject: [PATCH 23/28] =?UTF-8?q?refactor:=20=ED=81=B4=EB=9E=98=EC=8A=A4?= =?UTF-8?q?=20=EC=BB=A8=EB=B2=A4=EC=85=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/weekly/weekly/VoucherManagementController.java | 1 + .../org/weekly/weekly/api/customer/CustomerAPIController.java | 1 + src/main/java/org/weekly/weekly/api/dto/ErrorResponse.java | 1 + .../org/weekly/weekly/api/voucher/VoucherAPIController.java | 1 + src/main/java/org/weekly/weekly/customer/domain/Customer.java | 1 + .../weekly/customer/dto/request/CustomerCreationRequest.java | 1 + .../weekly/customer/dto/request/CustomerUpdateRequest.java | 1 + .../weekly/weekly/customer/dto/response/CustomerResponse.java | 1 + .../weekly/weekly/customer/dto/response/CustomersResponse.java | 1 + .../org/weekly/weekly/customer/exception/CustomerException.java | 1 + .../org/weekly/weekly/customer/exception/CustomerValidator.java | 1 + .../weekly/customer/repository/JdbcCustomerRepository.java | 1 + .../org/weekly/weekly/customer/service/CustomerService.java | 1 + src/main/java/org/weekly/weekly/ui/CommandLineApplication.java | 1 + .../java/org/weekly/weekly/ui/exception/InputValidator.java | 2 +- .../java/org/weekly/weekly/ui/reader/BufferedReaderWrap.java | 1 + src/main/java/org/weekly/weekly/ui/reader/ConsoleWrap.java | 1 + src/main/java/org/weekly/weekly/ui/reader/ScannerWrap.java | 1 + .../org/weekly/weekly/voucher/controller/VoucherController.java | 1 + .../java/org/weekly/weekly/voucher/domain/FixedDiscount.java | 1 + .../java/org/weekly/weekly/voucher/domain/PercentDiscount.java | 1 + .../weekly/voucher/dto/request/VoucherCreationRequest.java | 1 + .../weekly/weekly/voucher/dto/request/VoucherInfoRequest.java | 1 + .../weekly/voucher/dto/response/VoucherCreationResponse.java | 1 + .../weekly/weekly/voucher/dto/response/VouchersResponse.java | 1 + .../org/weekly/weekly/voucher/exception/VoucherException.java | 1 + .../org/weekly/weekly/voucher/exception/VoucherValidator.java | 1 + .../weekly/weekly/voucher/repository/JdbcVoucherRepository.java | 1 + .../weekly/voucher/repository/MemoryVoucherRepository.java | 1 + .../java/org/weekly/weekly/voucher/service/VoucherService.java | 1 + .../org/weekly/weekly/web/customer/CustomerWebController.java | 2 +- .../java/org/weekly/weekly/web/exception/WebExceptionDto.java | 1 + .../org/weekly/weekly/web/voucher/VoucherWebController.java | 2 +- 33 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/weekly/weekly/VoucherManagementController.java b/src/main/java/org/weekly/weekly/VoucherManagementController.java index a63fe8ed39..fa884d9029 100644 --- a/src/main/java/org/weekly/weekly/VoucherManagementController.java +++ b/src/main/java/org/weekly/weekly/VoucherManagementController.java @@ -20,6 +20,7 @@ @Component public class VoucherManagementController { + private final Logger logger = LoggerFactory.getLogger(VoucherManagementController.class); private final CommandLineApplication commandLineApplication; private final VoucherController voucherController; diff --git a/src/main/java/org/weekly/weekly/api/customer/CustomerAPIController.java b/src/main/java/org/weekly/weekly/api/customer/CustomerAPIController.java index c590965309..362490db88 100644 --- a/src/main/java/org/weekly/weekly/api/customer/CustomerAPIController.java +++ b/src/main/java/org/weekly/weekly/api/customer/CustomerAPIController.java @@ -14,6 +14,7 @@ @RestController @RequestMapping("/api/v1") public class CustomerAPIController { + private final CustomerService customerService; public CustomerAPIController(CustomerService customerService) { diff --git a/src/main/java/org/weekly/weekly/api/dto/ErrorResponse.java b/src/main/java/org/weekly/weekly/api/dto/ErrorResponse.java index 39f8e3197a..363c8c4ef8 100644 --- a/src/main/java/org/weekly/weekly/api/dto/ErrorResponse.java +++ b/src/main/java/org/weekly/weekly/api/dto/ErrorResponse.java @@ -1,6 +1,7 @@ package org.weekly.weekly.api.dto; public class ErrorResponse { + private final String code; private final String message; diff --git a/src/main/java/org/weekly/weekly/api/voucher/VoucherAPIController.java b/src/main/java/org/weekly/weekly/api/voucher/VoucherAPIController.java index ebcad66ea4..e51aaa41d0 100644 --- a/src/main/java/org/weekly/weekly/api/voucher/VoucherAPIController.java +++ b/src/main/java/org/weekly/weekly/api/voucher/VoucherAPIController.java @@ -13,6 +13,7 @@ @RestController @RequestMapping("/api/v1") public class VoucherAPIController { + private final VoucherService voucherService; public VoucherAPIController(VoucherService voucherService) { diff --git a/src/main/java/org/weekly/weekly/customer/domain/Customer.java b/src/main/java/org/weekly/weekly/customer/domain/Customer.java index b6cdb8d6fb..b912ea3463 100644 --- a/src/main/java/org/weekly/weekly/customer/domain/Customer.java +++ b/src/main/java/org/weekly/weekly/customer/domain/Customer.java @@ -6,6 +6,7 @@ import java.util.UUID; public class Customer { + UUID customerId; String name; String email; diff --git a/src/main/java/org/weekly/weekly/customer/dto/request/CustomerCreationRequest.java b/src/main/java/org/weekly/weekly/customer/dto/request/CustomerCreationRequest.java index 4b8fb368fc..5292b3dd80 100644 --- a/src/main/java/org/weekly/weekly/customer/dto/request/CustomerCreationRequest.java +++ b/src/main/java/org/weekly/weekly/customer/dto/request/CustomerCreationRequest.java @@ -6,6 +6,7 @@ import java.util.UUID; public class CustomerCreationRequest { + private String email; private String name; diff --git a/src/main/java/org/weekly/weekly/customer/dto/request/CustomerUpdateRequest.java b/src/main/java/org/weekly/weekly/customer/dto/request/CustomerUpdateRequest.java index c242402da4..a87c7dd51d 100644 --- a/src/main/java/org/weekly/weekly/customer/dto/request/CustomerUpdateRequest.java +++ b/src/main/java/org/weekly/weekly/customer/dto/request/CustomerUpdateRequest.java @@ -3,6 +3,7 @@ import org.weekly.weekly.ui.exception.InputValidator; public class CustomerUpdateRequest { + private String email; private String newEmail; diff --git a/src/main/java/org/weekly/weekly/customer/dto/response/CustomerResponse.java b/src/main/java/org/weekly/weekly/customer/dto/response/CustomerResponse.java index 776867b8f3..773dc92829 100644 --- a/src/main/java/org/weekly/weekly/customer/dto/response/CustomerResponse.java +++ b/src/main/java/org/weekly/weekly/customer/dto/response/CustomerResponse.java @@ -6,6 +6,7 @@ import java.time.LocalDateTime; public class CustomerResponse { + String name; String email; LocalDateTime createAt; diff --git a/src/main/java/org/weekly/weekly/customer/dto/response/CustomersResponse.java b/src/main/java/org/weekly/weekly/customer/dto/response/CustomersResponse.java index 66f3fde88c..294e0ba9d0 100644 --- a/src/main/java/org/weekly/weekly/customer/dto/response/CustomersResponse.java +++ b/src/main/java/org/weekly/weekly/customer/dto/response/CustomersResponse.java @@ -6,6 +6,7 @@ import java.util.List; public class CustomersResponse { + List result; public CustomersResponse(List customers) { diff --git a/src/main/java/org/weekly/weekly/customer/exception/CustomerException.java b/src/main/java/org/weekly/weekly/customer/exception/CustomerException.java index 24fedce726..52f3382577 100644 --- a/src/main/java/org/weekly/weekly/customer/exception/CustomerException.java +++ b/src/main/java/org/weekly/weekly/customer/exception/CustomerException.java @@ -3,6 +3,7 @@ import org.weekly.weekly.util.ExceptionCode; public class CustomerException extends RuntimeException { + private final ExceptionCode exceptionCode; public CustomerException(ExceptionCode exceptionMsg) { diff --git a/src/main/java/org/weekly/weekly/customer/exception/CustomerValidator.java b/src/main/java/org/weekly/weekly/customer/exception/CustomerValidator.java index 0c28fa5149..9b921bc59c 100644 --- a/src/main/java/org/weekly/weekly/customer/exception/CustomerValidator.java +++ b/src/main/java/org/weekly/weekly/customer/exception/CustomerValidator.java @@ -5,6 +5,7 @@ import java.util.regex.Pattern; public class CustomerValidator { + private static final String EMAIL_FORMAT = "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,3}$"; private CustomerValidator() { diff --git a/src/main/java/org/weekly/weekly/customer/repository/JdbcCustomerRepository.java b/src/main/java/org/weekly/weekly/customer/repository/JdbcCustomerRepository.java index 7e374682bc..58342bfd34 100644 --- a/src/main/java/org/weekly/weekly/customer/repository/JdbcCustomerRepository.java +++ b/src/main/java/org/weekly/weekly/customer/repository/JdbcCustomerRepository.java @@ -21,6 +21,7 @@ @Profile("!dev") @Repository public class JdbcCustomerRepository implements CustomerRepository { + private final JdbcTemplate jdbcTemplate; public JdbcCustomerRepository(DataSource dataSource) { diff --git a/src/main/java/org/weekly/weekly/customer/service/CustomerService.java b/src/main/java/org/weekly/weekly/customer/service/CustomerService.java index 43ac44e252..1b1332af51 100644 --- a/src/main/java/org/weekly/weekly/customer/service/CustomerService.java +++ b/src/main/java/org/weekly/weekly/customer/service/CustomerService.java @@ -16,6 +16,7 @@ @Service public class CustomerService { + private final CustomerRepository customerRepository; public CustomerService(CustomerRepository customerRepository) { diff --git a/src/main/java/org/weekly/weekly/ui/CommandLineApplication.java b/src/main/java/org/weekly/weekly/ui/CommandLineApplication.java index 1c8f593850..a08044f247 100644 --- a/src/main/java/org/weekly/weekly/ui/CommandLineApplication.java +++ b/src/main/java/org/weekly/weekly/ui/CommandLineApplication.java @@ -23,6 +23,7 @@ @Component public class CommandLineApplication { + private final CommandReader commandReader; private final SystemWriter commandWriter; diff --git a/src/main/java/org/weekly/weekly/ui/exception/InputValidator.java b/src/main/java/org/weekly/weekly/ui/exception/InputValidator.java index 55c5251322..f50f6a481f 100644 --- a/src/main/java/org/weekly/weekly/ui/exception/InputValidator.java +++ b/src/main/java/org/weekly/weekly/ui/exception/InputValidator.java @@ -27,7 +27,7 @@ public static void notVoucherInputSize(String[] userInputs) { public static void notNumber(String[] userInputs) { try { Arrays.stream(userInputs) - .peek(Long::parseLong); + .forEach(Long::parseLong); } catch (NumberFormatException exception) { throw new InputException(ExceptionCode.NOT_INPUT_FORMAT); } diff --git a/src/main/java/org/weekly/weekly/ui/reader/BufferedReaderWrap.java b/src/main/java/org/weekly/weekly/ui/reader/BufferedReaderWrap.java index 1b49b51592..4c9263603e 100644 --- a/src/main/java/org/weekly/weekly/ui/reader/BufferedReaderWrap.java +++ b/src/main/java/org/weekly/weekly/ui/reader/BufferedReaderWrap.java @@ -12,6 +12,7 @@ @Component @ConditionalOnProperty(value = "command.read", havingValue = "buffer") public class BufferedReaderWrap implements CommandReader { + private final BufferedReader bufferedReader; public BufferedReaderWrap() { diff --git a/src/main/java/org/weekly/weekly/ui/reader/ConsoleWrap.java b/src/main/java/org/weekly/weekly/ui/reader/ConsoleWrap.java index a66925d245..c77ca7ada1 100644 --- a/src/main/java/org/weekly/weekly/ui/reader/ConsoleWrap.java +++ b/src/main/java/org/weekly/weekly/ui/reader/ConsoleWrap.java @@ -8,6 +8,7 @@ @Component @ConditionalOnProperty(value = "command.read", havingValue = "console") public class ConsoleWrap implements CommandReader { + private final Console console; public ConsoleWrap() { diff --git a/src/main/java/org/weekly/weekly/ui/reader/ScannerWrap.java b/src/main/java/org/weekly/weekly/ui/reader/ScannerWrap.java index 4a127dfc61..54346046fe 100644 --- a/src/main/java/org/weekly/weekly/ui/reader/ScannerWrap.java +++ b/src/main/java/org/weekly/weekly/ui/reader/ScannerWrap.java @@ -9,6 +9,7 @@ @Component @ConditionalOnProperty(value = "command.read", havingValue = "scanner") public class ScannerWrap implements CommandReader { + private final Scanner scanner; public ScannerWrap() { diff --git a/src/main/java/org/weekly/weekly/voucher/controller/VoucherController.java b/src/main/java/org/weekly/weekly/voucher/controller/VoucherController.java index 7dae861767..c23a9a59b6 100644 --- a/src/main/java/org/weekly/weekly/voucher/controller/VoucherController.java +++ b/src/main/java/org/weekly/weekly/voucher/controller/VoucherController.java @@ -8,6 +8,7 @@ @Controller public class VoucherController { + private final VoucherService voucherService; public VoucherController(VoucherService voucherService) { diff --git a/src/main/java/org/weekly/weekly/voucher/domain/FixedDiscount.java b/src/main/java/org/weekly/weekly/voucher/domain/FixedDiscount.java index 1c50be7ec0..d0d8b4ed6a 100644 --- a/src/main/java/org/weekly/weekly/voucher/domain/FixedDiscount.java +++ b/src/main/java/org/weekly/weekly/voucher/domain/FixedDiscount.java @@ -1,6 +1,7 @@ package org.weekly.weekly.voucher.domain; public class FixedDiscount implements Discount { + @Override public long applyDiscount(long beforeAmount, long discountAmount) { return beforeAmount - discountAmount; diff --git a/src/main/java/org/weekly/weekly/voucher/domain/PercentDiscount.java b/src/main/java/org/weekly/weekly/voucher/domain/PercentDiscount.java index e7ffad108e..c2b9485f63 100644 --- a/src/main/java/org/weekly/weekly/voucher/domain/PercentDiscount.java +++ b/src/main/java/org/weekly/weekly/voucher/domain/PercentDiscount.java @@ -1,6 +1,7 @@ package org.weekly.weekly.voucher.domain; public class PercentDiscount implements Discount { + private static final int PERCENT = 100; @Override diff --git a/src/main/java/org/weekly/weekly/voucher/dto/request/VoucherCreationRequest.java b/src/main/java/org/weekly/weekly/voucher/dto/request/VoucherCreationRequest.java index 4beb52aced..e6527ae758 100644 --- a/src/main/java/org/weekly/weekly/voucher/dto/request/VoucherCreationRequest.java +++ b/src/main/java/org/weekly/weekly/voucher/dto/request/VoucherCreationRequest.java @@ -7,6 +7,7 @@ import java.util.UUID; public class VoucherCreationRequest { + private VoucherInfoRequest voucherInfoRequest; private final DiscountType discountType; diff --git a/src/main/java/org/weekly/weekly/voucher/dto/request/VoucherInfoRequest.java b/src/main/java/org/weekly/weekly/voucher/dto/request/VoucherInfoRequest.java index 13915f5e09..04f7658ac5 100644 --- a/src/main/java/org/weekly/weekly/voucher/dto/request/VoucherInfoRequest.java +++ b/src/main/java/org/weekly/weekly/voucher/dto/request/VoucherInfoRequest.java @@ -3,6 +3,7 @@ import org.weekly.weekly.ui.exception.InputValidator; public class VoucherInfoRequest { + private static final String SPLIT_FORMAT = ","; private static final int AMOUNT_NO = 0; private static final int EXPIRATION = 1; diff --git a/src/main/java/org/weekly/weekly/voucher/dto/response/VoucherCreationResponse.java b/src/main/java/org/weekly/weekly/voucher/dto/response/VoucherCreationResponse.java index b9a6469b3f..1071e374c9 100644 --- a/src/main/java/org/weekly/weekly/voucher/dto/response/VoucherCreationResponse.java +++ b/src/main/java/org/weekly/weekly/voucher/dto/response/VoucherCreationResponse.java @@ -7,6 +7,7 @@ import java.util.UUID; public class VoucherCreationResponse { + private final UUID id; private final LocalDate registrationDate; private final LocalDate expirationDate; diff --git a/src/main/java/org/weekly/weekly/voucher/dto/response/VouchersResponse.java b/src/main/java/org/weekly/weekly/voucher/dto/response/VouchersResponse.java index 07f9bb514b..9d60e60232 100644 --- a/src/main/java/org/weekly/weekly/voucher/dto/response/VouchersResponse.java +++ b/src/main/java/org/weekly/weekly/voucher/dto/response/VouchersResponse.java @@ -6,6 +6,7 @@ import java.util.List; public class VouchersResponse { + private final List result; public VouchersResponse(List vouchers) { diff --git a/src/main/java/org/weekly/weekly/voucher/exception/VoucherException.java b/src/main/java/org/weekly/weekly/voucher/exception/VoucherException.java index c2968fb684..e878f3cd7a 100644 --- a/src/main/java/org/weekly/weekly/voucher/exception/VoucherException.java +++ b/src/main/java/org/weekly/weekly/voucher/exception/VoucherException.java @@ -3,6 +3,7 @@ import org.weekly.weekly.util.ExceptionCode; public class VoucherException extends RuntimeException { + private final ExceptionCode exceptionCode; public VoucherException(ExceptionCode exceptionMsg) { diff --git a/src/main/java/org/weekly/weekly/voucher/exception/VoucherValidator.java b/src/main/java/org/weekly/weekly/voucher/exception/VoucherValidator.java index d4508b9eaf..ad4ce18ac6 100644 --- a/src/main/java/org/weekly/weekly/voucher/exception/VoucherValidator.java +++ b/src/main/java/org/weekly/weekly/voucher/exception/VoucherValidator.java @@ -7,6 +7,7 @@ import java.util.function.LongPredicate; public class VoucherValidator { + private static final int RANGE_START = 0; private static final int RANGE_END = 100; diff --git a/src/main/java/org/weekly/weekly/voucher/repository/JdbcVoucherRepository.java b/src/main/java/org/weekly/weekly/voucher/repository/JdbcVoucherRepository.java index 02ff443f38..48c4709397 100644 --- a/src/main/java/org/weekly/weekly/voucher/repository/JdbcVoucherRepository.java +++ b/src/main/java/org/weekly/weekly/voucher/repository/JdbcVoucherRepository.java @@ -23,6 +23,7 @@ @Profile("!dev") @Repository public class JdbcVoucherRepository implements VoucherRepository { + private final JdbcTemplate jdbcTemplate; public JdbcVoucherRepository(DataSource dataSource) { diff --git a/src/main/java/org/weekly/weekly/voucher/repository/MemoryVoucherRepository.java b/src/main/java/org/weekly/weekly/voucher/repository/MemoryVoucherRepository.java index 21e9bd721e..b1197d4924 100644 --- a/src/main/java/org/weekly/weekly/voucher/repository/MemoryVoucherRepository.java +++ b/src/main/java/org/weekly/weekly/voucher/repository/MemoryVoucherRepository.java @@ -16,6 +16,7 @@ @Profile("dev") @Repository public class MemoryVoucherRepository implements VoucherRepository { + private final Map storages = new ConcurrentHashMap<>(); public Voucher insert(Voucher voucher) { diff --git a/src/main/java/org/weekly/weekly/voucher/service/VoucherService.java b/src/main/java/org/weekly/weekly/voucher/service/VoucherService.java index f5ba6270e1..e1120a3e40 100644 --- a/src/main/java/org/weekly/weekly/voucher/service/VoucherService.java +++ b/src/main/java/org/weekly/weekly/voucher/service/VoucherService.java @@ -11,6 +11,7 @@ @Service public class VoucherService { + private final VoucherRepository voucherRepository; public VoucherService(VoucherRepository voucherRepository) { diff --git a/src/main/java/org/weekly/weekly/web/customer/CustomerWebController.java b/src/main/java/org/weekly/weekly/web/customer/CustomerWebController.java index 10f0fe23ba..8d5efd257d 100644 --- a/src/main/java/org/weekly/weekly/web/customer/CustomerWebController.java +++ b/src/main/java/org/weekly/weekly/web/customer/CustomerWebController.java @@ -19,7 +19,7 @@ @Controller @RequestMapping("/customer") public class CustomerWebController { - private final Logger logger = LoggerFactory.getLogger(CustomerWebController.class); + private final CustomerService customerService; public CustomerWebController(CustomerService customerService) { diff --git a/src/main/java/org/weekly/weekly/web/exception/WebExceptionDto.java b/src/main/java/org/weekly/weekly/web/exception/WebExceptionDto.java index c70bcdb6db..f5cd14bcd4 100644 --- a/src/main/java/org/weekly/weekly/web/exception/WebExceptionDto.java +++ b/src/main/java/org/weekly/weekly/web/exception/WebExceptionDto.java @@ -1,6 +1,7 @@ package org.weekly.weekly.web.exception; public class WebExceptionDto { + private final String message; public WebExceptionDto(RuntimeException error) { diff --git a/src/main/java/org/weekly/weekly/web/voucher/VoucherWebController.java b/src/main/java/org/weekly/weekly/web/voucher/VoucherWebController.java index 61574a00cb..c93a342f9b 100644 --- a/src/main/java/org/weekly/weekly/web/voucher/VoucherWebController.java +++ b/src/main/java/org/weekly/weekly/web/voucher/VoucherWebController.java @@ -16,8 +16,8 @@ @Controller @RequestMapping("/voucher") public class VoucherWebController { - private final VoucherService voucherService; + private final VoucherService voucherService; public VoucherWebController(VoucherService voucherService) { this.voucherService = voucherService; From 0422b7ef5082f431f86957090f28eeb0bf7c720d Mon Sep 17 00:00:00 2001 From: parksey Date: Thu, 20 Jul 2023 14:35:25 +0900 Subject: [PATCH 24/28] =?UTF-8?q?refactor:=20=EB=A9=94=EC=84=9C=EB=93=9C?= =?UTF-8?q?=EB=AA=85=20=EC=98=A4=ED=83=80=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/weekly/weekly/api/customer/CustomerAPIController.java | 2 +- src/main/resources/db-init/schema.sql | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/org/weekly/weekly/api/customer/CustomerAPIController.java b/src/main/java/org/weekly/weekly/api/customer/CustomerAPIController.java index 362490db88..77a0eb6bca 100644 --- a/src/main/java/org/weekly/weekly/api/customer/CustomerAPIController.java +++ b/src/main/java/org/weekly/weekly/api/customer/CustomerAPIController.java @@ -46,7 +46,7 @@ public ResponseEntity updateCustomer(@RequestBody CustomerUpda } @DeleteMapping("/delete/{customerEmail}") - public ResponseEntity deleteCustomerr(@PathVariable String customerEmail) { + public ResponseEntity deleteCustomer(@PathVariable String customerEmail) { customerService.deleteCustomer(customerEmail); return new ResponseEntity<>(HttpStatus.NO_CONTENT); } diff --git a/src/main/resources/db-init/schema.sql b/src/main/resources/db-init/schema.sql index 7ccc163507..12d8d04cb8 100644 --- a/src/main/resources/db-init/schema.sql +++ b/src/main/resources/db-init/schema.sql @@ -19,4 +19,3 @@ CREATE TABLE vouchers registration_date datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP (6), expiration_date datetime(6) NOT NULL ); - From 28a3116639924cc93cb39df29708e58cc80e0d4f Mon Sep 17 00:00:00 2001 From: parksey Date: Tue, 25 Jul 2023 00:46:33 +0900 Subject: [PATCH 25/28] =?UTF-8?q?refactor:=20api,=20web=20=EB=B0=8F=20util?= =?UTF-8?q?=EC=9D=98=20=ED=8C=A8=ED=82=A4=EC=A7=80=20=EA=B5=AC=EC=A1=B0=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/weekly/weekly/VoucherManagementController.java | 8 ++++---- .../controller/api}/CustomerAPIController.java | 2 +- .../controller/web}/CustomerWebController.java | 6 ++---- .../weekly/customer/dto/response/CustomersResponse.java | 2 +- .../weekly/customer/exception/CustomerException.java | 2 +- .../weekly/customer/exception/CustomerValidator.java | 2 +- .../customer/repository/JdbcCustomerRepository.java | 2 +- .../weekly/weekly/customer/service/CustomerService.java | 2 +- .../advice => global/handler}/APIExceptionHandler.java | 4 +--- .../weekly/{api/dto => global/handler}/ErrorResponse.java | 2 +- .../weekly/{util => global/handler}/ExceptionCode.java | 2 +- .../exception => global/handler}/WebExceptionDto.java | 2 +- .../org/weekly/weekly/{ => global}/util/CustomerMenu.java | 3 ++- .../org/weekly/weekly/{ => global}/util/ManageMenu.java | 4 +++- .../java/org/weekly/weekly/{ => global}/util/Menu.java | 2 +- .../weekly/weekly/{ => global}/util/PrintMessageType.java | 2 +- .../org/weekly/weekly/{ => global}/util/VoucherMenu.java | 3 ++- .../java/org/weekly/weekly/ui/CommandLineApplication.java | 8 ++++---- .../org/weekly/weekly/ui/exception/InputException.java | 2 +- .../org/weekly/weekly/ui/exception/InputValidator.java | 2 +- .../org/weekly/weekly/ui/reader/BufferedReaderWrap.java | 2 +- .../java/org/weekly/weekly/ui/writer/SystemWriter.java | 1 + .../controller/api}/VoucherAPIController.java | 2 +- .../controller/web}/VoucherWebController.java | 4 ++-- .../org/weekly/weekly/voucher/domain/DiscountType.java | 2 +- .../weekly/voucher/dto/response/VouchersResponse.java | 2 +- .../weekly/weekly/voucher/exception/VoucherException.java | 2 +- .../weekly/weekly/voucher/exception/VoucherValidator.java | 2 +- .../weekly/voucher/repository/JdbcVoucherRepository.java | 2 +- .../voucher/repository/MemoryVoucherRepository.java | 2 +- src/test/java/org/weekly/weekly/util/VoucherMenuTest.java | 1 + 31 files changed, 43 insertions(+), 41 deletions(-) rename src/main/java/org/weekly/weekly/{api/customer => customer/controller/api}/CustomerAPIController.java (97%) rename src/main/java/org/weekly/weekly/{web/customer => customer/controller/web}/CustomerWebController.java (96%) rename src/main/java/org/weekly/weekly/{api/advice => global/handler}/APIExceptionHandler.java (93%) rename src/main/java/org/weekly/weekly/{api/dto => global/handler}/ErrorResponse.java (89%) rename src/main/java/org/weekly/weekly/{util => global/handler}/ExceptionCode.java (97%) rename src/main/java/org/weekly/weekly/{web/exception => global/handler}/WebExceptionDto.java (84%) rename src/main/java/org/weekly/weekly/{ => global}/util/CustomerMenu.java (93%) rename src/main/java/org/weekly/weekly/{ => global}/util/ManageMenu.java (91%) rename src/main/java/org/weekly/weekly/{ => global}/util/Menu.java (58%) rename src/main/java/org/weekly/weekly/{ => global}/util/PrintMessageType.java (96%) rename src/main/java/org/weekly/weekly/{ => global}/util/VoucherMenu.java (91%) rename src/main/java/org/weekly/weekly/{api/voucher => voucher/controller/api}/VoucherAPIController.java (96%) rename src/main/java/org/weekly/weekly/{web/voucher => voucher/controller/web}/VoucherWebController.java (95%) diff --git a/src/main/java/org/weekly/weekly/VoucherManagementController.java b/src/main/java/org/weekly/weekly/VoucherManagementController.java index fa884d9029..41cfbe2336 100644 --- a/src/main/java/org/weekly/weekly/VoucherManagementController.java +++ b/src/main/java/org/weekly/weekly/VoucherManagementController.java @@ -9,10 +9,10 @@ import org.weekly.weekly.customer.dto.response.CustomerResponse; import org.weekly.weekly.customer.dto.response.CustomersResponse; import org.weekly.weekly.ui.CommandLineApplication; -import org.weekly.weekly.util.CustomerMenu; -import org.weekly.weekly.util.ManageMenu; -import org.weekly.weekly.util.PrintMessageType; -import org.weekly.weekly.util.VoucherMenu; +import org.weekly.weekly.global.util.CustomerMenu; +import org.weekly.weekly.global.util.ManageMenu; +import org.weekly.weekly.global.util.PrintMessageType; +import org.weekly.weekly.global.util.VoucherMenu; import org.weekly.weekly.voucher.controller.VoucherController; import org.weekly.weekly.voucher.dto.request.VoucherCreationRequest; import org.weekly.weekly.voucher.dto.response.VoucherCreationResponse; diff --git a/src/main/java/org/weekly/weekly/api/customer/CustomerAPIController.java b/src/main/java/org/weekly/weekly/customer/controller/api/CustomerAPIController.java similarity index 97% rename from src/main/java/org/weekly/weekly/api/customer/CustomerAPIController.java rename to src/main/java/org/weekly/weekly/customer/controller/api/CustomerAPIController.java index 77a0eb6bca..669bf28b98 100644 --- a/src/main/java/org/weekly/weekly/api/customer/CustomerAPIController.java +++ b/src/main/java/org/weekly/weekly/customer/controller/api/CustomerAPIController.java @@ -1,4 +1,4 @@ -package org.weekly.weekly.api.customer; +package org.weekly.weekly.customer.controller.api; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; diff --git a/src/main/java/org/weekly/weekly/web/customer/CustomerWebController.java b/src/main/java/org/weekly/weekly/customer/controller/web/CustomerWebController.java similarity index 96% rename from src/main/java/org/weekly/weekly/web/customer/CustomerWebController.java rename to src/main/java/org/weekly/weekly/customer/controller/web/CustomerWebController.java index 8d5efd257d..236a873a2f 100644 --- a/src/main/java/org/weekly/weekly/web/customer/CustomerWebController.java +++ b/src/main/java/org/weekly/weekly/customer/controller/web/CustomerWebController.java @@ -1,7 +1,5 @@ -package org.weekly.weekly.web.customer; +package org.weekly.weekly.customer.controller.web; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; @@ -14,7 +12,7 @@ import org.weekly.weekly.customer.dto.response.CustomersResponse; import org.weekly.weekly.customer.exception.CustomerException; import org.weekly.weekly.customer.service.CustomerService; -import org.weekly.weekly.web.exception.WebExceptionDto; +import org.weekly.weekly.global.handler.WebExceptionDto; @Controller @RequestMapping("/customer") diff --git a/src/main/java/org/weekly/weekly/customer/dto/response/CustomersResponse.java b/src/main/java/org/weekly/weekly/customer/dto/response/CustomersResponse.java index 294e0ba9d0..908b16b29c 100644 --- a/src/main/java/org/weekly/weekly/customer/dto/response/CustomersResponse.java +++ b/src/main/java/org/weekly/weekly/customer/dto/response/CustomersResponse.java @@ -1,7 +1,7 @@ package org.weekly.weekly.customer.dto.response; import org.weekly.weekly.customer.domain.Customer; -import org.weekly.weekly.util.PrintMessageType; +import org.weekly.weekly.global.util.PrintMessageType; import java.util.List; diff --git a/src/main/java/org/weekly/weekly/customer/exception/CustomerException.java b/src/main/java/org/weekly/weekly/customer/exception/CustomerException.java index 52f3382577..5c3f5fe62f 100644 --- a/src/main/java/org/weekly/weekly/customer/exception/CustomerException.java +++ b/src/main/java/org/weekly/weekly/customer/exception/CustomerException.java @@ -1,6 +1,6 @@ package org.weekly.weekly.customer.exception; -import org.weekly.weekly.util.ExceptionCode; +import org.weekly.weekly.global.handler.ExceptionCode; public class CustomerException extends RuntimeException { diff --git a/src/main/java/org/weekly/weekly/customer/exception/CustomerValidator.java b/src/main/java/org/weekly/weekly/customer/exception/CustomerValidator.java index 9b921bc59c..3ba3f132da 100644 --- a/src/main/java/org/weekly/weekly/customer/exception/CustomerValidator.java +++ b/src/main/java/org/weekly/weekly/customer/exception/CustomerValidator.java @@ -1,6 +1,6 @@ package org.weekly.weekly.customer.exception; -import org.weekly.weekly.util.ExceptionCode; +import org.weekly.weekly.global.handler.ExceptionCode; import java.util.regex.Pattern; diff --git a/src/main/java/org/weekly/weekly/customer/repository/JdbcCustomerRepository.java b/src/main/java/org/weekly/weekly/customer/repository/JdbcCustomerRepository.java index 58342bfd34..59e3790134 100644 --- a/src/main/java/org/weekly/weekly/customer/repository/JdbcCustomerRepository.java +++ b/src/main/java/org/weekly/weekly/customer/repository/JdbcCustomerRepository.java @@ -6,7 +6,7 @@ import org.springframework.stereotype.Repository; import org.weekly.weekly.customer.domain.Customer; import org.weekly.weekly.customer.exception.CustomerException; -import org.weekly.weekly.util.ExceptionCode; +import org.weekly.weekly.global.handler.ExceptionCode; import javax.sql.DataSource; import java.nio.ByteBuffer; diff --git a/src/main/java/org/weekly/weekly/customer/service/CustomerService.java b/src/main/java/org/weekly/weekly/customer/service/CustomerService.java index 1b1332af51..9958721cde 100644 --- a/src/main/java/org/weekly/weekly/customer/service/CustomerService.java +++ b/src/main/java/org/weekly/weekly/customer/service/CustomerService.java @@ -9,7 +9,7 @@ import org.weekly.weekly.customer.dto.response.CustomersResponse; import org.weekly.weekly.customer.exception.CustomerException; import org.weekly.weekly.customer.repository.CustomerRepository; -import org.weekly.weekly.util.ExceptionCode; +import org.weekly.weekly.global.handler.ExceptionCode; import java.util.List; import java.util.Optional; diff --git a/src/main/java/org/weekly/weekly/api/advice/APIExceptionHandler.java b/src/main/java/org/weekly/weekly/global/handler/APIExceptionHandler.java similarity index 93% rename from src/main/java/org/weekly/weekly/api/advice/APIExceptionHandler.java rename to src/main/java/org/weekly/weekly/global/handler/APIExceptionHandler.java index 28ca1447c9..666bb9297e 100644 --- a/src/main/java/org/weekly/weekly/api/advice/APIExceptionHandler.java +++ b/src/main/java/org/weekly/weekly/global/handler/APIExceptionHandler.java @@ -1,12 +1,10 @@ -package org.weekly.weekly.api.advice; +package org.weekly.weekly.global.handler; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; -import org.weekly.weekly.api.dto.ErrorResponse; import org.weekly.weekly.customer.exception.CustomerException; -import org.weekly.weekly.util.ExceptionCode; import org.weekly.weekly.voucher.exception.VoucherException; @RestControllerAdvice(basePackages = {"org.weekly.weekly.api"}) diff --git a/src/main/java/org/weekly/weekly/api/dto/ErrorResponse.java b/src/main/java/org/weekly/weekly/global/handler/ErrorResponse.java similarity index 89% rename from src/main/java/org/weekly/weekly/api/dto/ErrorResponse.java rename to src/main/java/org/weekly/weekly/global/handler/ErrorResponse.java index 363c8c4ef8..4e5a133f2f 100644 --- a/src/main/java/org/weekly/weekly/api/dto/ErrorResponse.java +++ b/src/main/java/org/weekly/weekly/global/handler/ErrorResponse.java @@ -1,4 +1,4 @@ -package org.weekly.weekly.api.dto; +package org.weekly.weekly.global.handler; public class ErrorResponse { diff --git a/src/main/java/org/weekly/weekly/util/ExceptionCode.java b/src/main/java/org/weekly/weekly/global/handler/ExceptionCode.java similarity index 97% rename from src/main/java/org/weekly/weekly/util/ExceptionCode.java rename to src/main/java/org/weekly/weekly/global/handler/ExceptionCode.java index 46c052122c..244802616e 100644 --- a/src/main/java/org/weekly/weekly/util/ExceptionCode.java +++ b/src/main/java/org/weekly/weekly/global/handler/ExceptionCode.java @@ -1,4 +1,4 @@ -package org.weekly.weekly.util; +package org.weekly.weekly.global.handler; import org.springframework.http.HttpStatus; diff --git a/src/main/java/org/weekly/weekly/web/exception/WebExceptionDto.java b/src/main/java/org/weekly/weekly/global/handler/WebExceptionDto.java similarity index 84% rename from src/main/java/org/weekly/weekly/web/exception/WebExceptionDto.java rename to src/main/java/org/weekly/weekly/global/handler/WebExceptionDto.java index f5cd14bcd4..4550e2649d 100644 --- a/src/main/java/org/weekly/weekly/web/exception/WebExceptionDto.java +++ b/src/main/java/org/weekly/weekly/global/handler/WebExceptionDto.java @@ -1,4 +1,4 @@ -package org.weekly.weekly.web.exception; +package org.weekly.weekly.global.handler; public class WebExceptionDto { diff --git a/src/main/java/org/weekly/weekly/util/CustomerMenu.java b/src/main/java/org/weekly/weekly/global/util/CustomerMenu.java similarity index 93% rename from src/main/java/org/weekly/weekly/util/CustomerMenu.java rename to src/main/java/org/weekly/weekly/global/util/CustomerMenu.java index 2a1f4603f4..41d52a0997 100644 --- a/src/main/java/org/weekly/weekly/util/CustomerMenu.java +++ b/src/main/java/org/weekly/weekly/global/util/CustomerMenu.java @@ -1,6 +1,7 @@ -package org.weekly.weekly.util; +package org.weekly.weekly.global.util; import org.weekly.weekly.customer.exception.CustomerException; +import org.weekly.weekly.global.handler.ExceptionCode; import java.util.Arrays; import java.util.Map; diff --git a/src/main/java/org/weekly/weekly/util/ManageMenu.java b/src/main/java/org/weekly/weekly/global/util/ManageMenu.java similarity index 91% rename from src/main/java/org/weekly/weekly/util/ManageMenu.java rename to src/main/java/org/weekly/weekly/global/util/ManageMenu.java index 4637ebaf24..1ce8e2c54b 100644 --- a/src/main/java/org/weekly/weekly/util/ManageMenu.java +++ b/src/main/java/org/weekly/weekly/global/util/ManageMenu.java @@ -1,4 +1,6 @@ -package org.weekly.weekly.util; +package org.weekly.weekly.global.util; + +import org.weekly.weekly.global.handler.ExceptionCode; import java.util.Arrays; import java.util.Map; diff --git a/src/main/java/org/weekly/weekly/util/Menu.java b/src/main/java/org/weekly/weekly/global/util/Menu.java similarity index 58% rename from src/main/java/org/weekly/weekly/util/Menu.java rename to src/main/java/org/weekly/weekly/global/util/Menu.java index 40981c0f93..9c286bd89a 100644 --- a/src/main/java/org/weekly/weekly/util/Menu.java +++ b/src/main/java/org/weekly/weekly/global/util/Menu.java @@ -1,4 +1,4 @@ -package org.weekly.weekly.util; +package org.weekly.weekly.global.util; public interface Menu { String printMessage(); diff --git a/src/main/java/org/weekly/weekly/util/PrintMessageType.java b/src/main/java/org/weekly/weekly/global/util/PrintMessageType.java similarity index 96% rename from src/main/java/org/weekly/weekly/util/PrintMessageType.java rename to src/main/java/org/weekly/weekly/global/util/PrintMessageType.java index c42e69ef39..4bd9f3e925 100644 --- a/src/main/java/org/weekly/weekly/util/PrintMessageType.java +++ b/src/main/java/org/weekly/weekly/global/util/PrintMessageType.java @@ -1,4 +1,4 @@ -package org.weekly.weekly.util; +package org.weekly.weekly.global.util; public enum PrintMessageType { MANAGE_PROGRAM("=== Manage Program ==="), diff --git a/src/main/java/org/weekly/weekly/util/VoucherMenu.java b/src/main/java/org/weekly/weekly/global/util/VoucherMenu.java similarity index 91% rename from src/main/java/org/weekly/weekly/util/VoucherMenu.java rename to src/main/java/org/weekly/weekly/global/util/VoucherMenu.java index a81bc60df0..64995cf695 100644 --- a/src/main/java/org/weekly/weekly/util/VoucherMenu.java +++ b/src/main/java/org/weekly/weekly/global/util/VoucherMenu.java @@ -1,5 +1,6 @@ -package org.weekly.weekly.util; +package org.weekly.weekly.global.util; +import org.weekly.weekly.global.handler.ExceptionCode; import org.weekly.weekly.voucher.exception.VoucherException; import java.util.Arrays; diff --git a/src/main/java/org/weekly/weekly/ui/CommandLineApplication.java b/src/main/java/org/weekly/weekly/ui/CommandLineApplication.java index a08044f247..a1ed65596a 100644 --- a/src/main/java/org/weekly/weekly/ui/CommandLineApplication.java +++ b/src/main/java/org/weekly/weekly/ui/CommandLineApplication.java @@ -9,10 +9,10 @@ import org.weekly.weekly.ui.exception.InputValidator; import org.weekly.weekly.ui.reader.CommandReader; import org.weekly.weekly.ui.writer.SystemWriter; -import org.weekly.weekly.util.CustomerMenu; -import org.weekly.weekly.util.ManageMenu; -import org.weekly.weekly.util.Menu; -import org.weekly.weekly.util.VoucherMenu; +import org.weekly.weekly.global.util.CustomerMenu; +import org.weekly.weekly.global.util.ManageMenu; +import org.weekly.weekly.global.util.Menu; +import org.weekly.weekly.global.util.VoucherMenu; import org.weekly.weekly.voucher.domain.DiscountType; import org.weekly.weekly.voucher.dto.request.VoucherCreationRequest; import org.weekly.weekly.voucher.dto.request.VoucherInfoRequest; diff --git a/src/main/java/org/weekly/weekly/ui/exception/InputException.java b/src/main/java/org/weekly/weekly/ui/exception/InputException.java index dae1f441ff..6c56107daf 100644 --- a/src/main/java/org/weekly/weekly/ui/exception/InputException.java +++ b/src/main/java/org/weekly/weekly/ui/exception/InputException.java @@ -1,6 +1,6 @@ package org.weekly.weekly.ui.exception; -import org.weekly.weekly.util.ExceptionCode; +import org.weekly.weekly.global.handler.ExceptionCode; public class InputException extends RuntimeException { diff --git a/src/main/java/org/weekly/weekly/ui/exception/InputValidator.java b/src/main/java/org/weekly/weekly/ui/exception/InputValidator.java index f50f6a481f..171e2fc775 100644 --- a/src/main/java/org/weekly/weekly/ui/exception/InputValidator.java +++ b/src/main/java/org/weekly/weekly/ui/exception/InputValidator.java @@ -1,6 +1,6 @@ package org.weekly.weekly.ui.exception; -import org.weekly.weekly.util.ExceptionCode; +import org.weekly.weekly.global.handler.ExceptionCode; import java.util.Arrays; diff --git a/src/main/java/org/weekly/weekly/ui/reader/BufferedReaderWrap.java b/src/main/java/org/weekly/weekly/ui/reader/BufferedReaderWrap.java index 4c9263603e..eb310ebae3 100644 --- a/src/main/java/org/weekly/weekly/ui/reader/BufferedReaderWrap.java +++ b/src/main/java/org/weekly/weekly/ui/reader/BufferedReaderWrap.java @@ -3,7 +3,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.stereotype.Component; import org.weekly.weekly.ui.exception.InputException; -import org.weekly.weekly.util.ExceptionCode; +import org.weekly.weekly.global.handler.ExceptionCode; import java.io.BufferedReader; import java.io.IOException; diff --git a/src/main/java/org/weekly/weekly/ui/writer/SystemWriter.java b/src/main/java/org/weekly/weekly/ui/writer/SystemWriter.java index e90184b18e..03cb7d1547 100644 --- a/src/main/java/org/weekly/weekly/ui/writer/SystemWriter.java +++ b/src/main/java/org/weekly/weekly/ui/writer/SystemWriter.java @@ -4,6 +4,7 @@ import org.slf4j.LoggerFactory; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.stereotype.Component; +import org.weekly.weekly.global.util.*; import org.weekly.weekly.util.*; import org.weekly.weekly.voucher.domain.DiscountType; diff --git a/src/main/java/org/weekly/weekly/api/voucher/VoucherAPIController.java b/src/main/java/org/weekly/weekly/voucher/controller/api/VoucherAPIController.java similarity index 96% rename from src/main/java/org/weekly/weekly/api/voucher/VoucherAPIController.java rename to src/main/java/org/weekly/weekly/voucher/controller/api/VoucherAPIController.java index e51aaa41d0..9dffac129f 100644 --- a/src/main/java/org/weekly/weekly/api/voucher/VoucherAPIController.java +++ b/src/main/java/org/weekly/weekly/voucher/controller/api/VoucherAPIController.java @@ -1,4 +1,4 @@ -package org.weekly.weekly.api.voucher; +package org.weekly.weekly.voucher.controller.api; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; diff --git a/src/main/java/org/weekly/weekly/web/voucher/VoucherWebController.java b/src/main/java/org/weekly/weekly/voucher/controller/web/VoucherWebController.java similarity index 95% rename from src/main/java/org/weekly/weekly/web/voucher/VoucherWebController.java rename to src/main/java/org/weekly/weekly/voucher/controller/web/VoucherWebController.java index c93a342f9b..1cdadbbfd9 100644 --- a/src/main/java/org/weekly/weekly/web/voucher/VoucherWebController.java +++ b/src/main/java/org/weekly/weekly/voucher/controller/web/VoucherWebController.java @@ -1,4 +1,4 @@ -package org.weekly.weekly.web.voucher; +package org.weekly.weekly.voucher.controller.web; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; @@ -11,7 +11,7 @@ import org.weekly.weekly.voucher.dto.response.VouchersResponse; import org.weekly.weekly.voucher.exception.VoucherException; import org.weekly.weekly.voucher.service.VoucherService; -import org.weekly.weekly.web.exception.WebExceptionDto; +import org.weekly.weekly.global.handler.WebExceptionDto; @Controller @RequestMapping("/voucher") diff --git a/src/main/java/org/weekly/weekly/voucher/domain/DiscountType.java b/src/main/java/org/weekly/weekly/voucher/domain/DiscountType.java index 4bff10995a..f871f313cc 100644 --- a/src/main/java/org/weekly/weekly/voucher/domain/DiscountType.java +++ b/src/main/java/org/weekly/weekly/voucher/domain/DiscountType.java @@ -1,6 +1,6 @@ package org.weekly.weekly.voucher.domain; -import org.weekly.weekly.util.ExceptionCode; +import org.weekly.weekly.global.handler.ExceptionCode; import org.weekly.weekly.voucher.exception.VoucherException; import java.lang.reflect.InvocationTargetException; diff --git a/src/main/java/org/weekly/weekly/voucher/dto/response/VouchersResponse.java b/src/main/java/org/weekly/weekly/voucher/dto/response/VouchersResponse.java index 9d60e60232..263afc1f8d 100644 --- a/src/main/java/org/weekly/weekly/voucher/dto/response/VouchersResponse.java +++ b/src/main/java/org/weekly/weekly/voucher/dto/response/VouchersResponse.java @@ -1,6 +1,6 @@ package org.weekly.weekly.voucher.dto.response; -import org.weekly.weekly.util.PrintMessageType; +import org.weekly.weekly.global.util.PrintMessageType; import org.weekly.weekly.voucher.domain.Voucher; import java.util.List; diff --git a/src/main/java/org/weekly/weekly/voucher/exception/VoucherException.java b/src/main/java/org/weekly/weekly/voucher/exception/VoucherException.java index e878f3cd7a..d7af54212e 100644 --- a/src/main/java/org/weekly/weekly/voucher/exception/VoucherException.java +++ b/src/main/java/org/weekly/weekly/voucher/exception/VoucherException.java @@ -1,6 +1,6 @@ package org.weekly.weekly.voucher.exception; -import org.weekly.weekly.util.ExceptionCode; +import org.weekly.weekly.global.handler.ExceptionCode; public class VoucherException extends RuntimeException { diff --git a/src/main/java/org/weekly/weekly/voucher/exception/VoucherValidator.java b/src/main/java/org/weekly/weekly/voucher/exception/VoucherValidator.java index ad4ce18ac6..b4efecdb54 100644 --- a/src/main/java/org/weekly/weekly/voucher/exception/VoucherValidator.java +++ b/src/main/java/org/weekly/weekly/voucher/exception/VoucherValidator.java @@ -1,6 +1,6 @@ package org.weekly.weekly.voucher.exception; -import org.weekly.weekly.util.ExceptionCode; +import org.weekly.weekly.global.handler.ExceptionCode; import org.weekly.weekly.voucher.domain.DiscountType; import java.time.LocalDate; diff --git a/src/main/java/org/weekly/weekly/voucher/repository/JdbcVoucherRepository.java b/src/main/java/org/weekly/weekly/voucher/repository/JdbcVoucherRepository.java index 48c4709397..e69e54016c 100644 --- a/src/main/java/org/weekly/weekly/voucher/repository/JdbcVoucherRepository.java +++ b/src/main/java/org/weekly/weekly/voucher/repository/JdbcVoucherRepository.java @@ -5,7 +5,7 @@ import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Repository; -import org.weekly.weekly.util.ExceptionCode; +import org.weekly.weekly.global.handler.ExceptionCode; import org.weekly.weekly.voucher.domain.DiscountType; import org.weekly.weekly.voucher.domain.Voucher; import org.weekly.weekly.voucher.exception.VoucherException; diff --git a/src/main/java/org/weekly/weekly/voucher/repository/MemoryVoucherRepository.java b/src/main/java/org/weekly/weekly/voucher/repository/MemoryVoucherRepository.java index b1197d4924..78328ec1ac 100644 --- a/src/main/java/org/weekly/weekly/voucher/repository/MemoryVoucherRepository.java +++ b/src/main/java/org/weekly/weekly/voucher/repository/MemoryVoucherRepository.java @@ -2,7 +2,7 @@ import org.springframework.context.annotation.Profile; import org.springframework.stereotype.Repository; -import org.weekly.weekly.util.ExceptionCode; +import org.weekly.weekly.global.handler.ExceptionCode; import org.weekly.weekly.voucher.domain.DiscountType; import org.weekly.weekly.voucher.domain.Voucher; import org.weekly.weekly.voucher.exception.VoucherException; diff --git a/src/test/java/org/weekly/weekly/util/VoucherMenuTest.java b/src/test/java/org/weekly/weekly/util/VoucherMenuTest.java index a49bc0d129..0659cf2291 100644 --- a/src/test/java/org/weekly/weekly/util/VoucherMenuTest.java +++ b/src/test/java/org/weekly/weekly/util/VoucherMenuTest.java @@ -2,6 +2,7 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; +import org.weekly.weekly.global.util.VoucherMenu; import static org.assertj.core.api.Assertions.assertThatThrownBy; From e3a8a72518e1f230b7a26479b7e3a11302dd8b45 Mon Sep 17 00:00:00 2001 From: parksey Date: Tue, 25 Jul 2023 01:14:13 +0900 Subject: [PATCH 26/28] =?UTF-8?q?feat:=20Restful=ED=95=9C=20=ED=98=84?= =?UTF-8?q?=EC=8B=9D=EC=97=90=20=EB=A7=9E=EB=8A=94=20URL=20=EB=B0=8F=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=20=EB=B3=80=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/api/CustomerAPIController.java | 14 +++++++------- .../controller/api/VoucherAPIController.java | 6 +++--- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/weekly/weekly/customer/controller/api/CustomerAPIController.java b/src/main/java/org/weekly/weekly/customer/controller/api/CustomerAPIController.java index 669bf28b98..f22a81a65f 100644 --- a/src/main/java/org/weekly/weekly/customer/controller/api/CustomerAPIController.java +++ b/src/main/java/org/weekly/weekly/customer/controller/api/CustomerAPIController.java @@ -12,7 +12,7 @@ import java.util.List; @RestController -@RequestMapping("/api/v1") +@RequestMapping("/api/v1/customers") public class CustomerAPIController { private final CustomerService customerService; @@ -21,37 +21,37 @@ public CustomerAPIController(CustomerService customerService) { this.customerService = customerService; } - @PostMapping("/customer") + @PostMapping public ResponseEntity create(@RequestBody CustomerCreationRequest creationRequest) { CustomerResponse customerResponse = customerService.createCustomer(creationRequest); return new ResponseEntity<>(customerResponse, HttpStatus.CREATED); } - @GetMapping("/customers") + @GetMapping public ResponseEntity> customers() { CustomersResponse customersResponse = customerService.findAllCustomer(); return new ResponseEntity<>(customersResponse.getCustomerResponses(), HttpStatus.OK); } - @GetMapping("/find/{customerEmail}") + @GetMapping("/{customerEmail}") public ResponseEntity findCustomer(@PathVariable String customerEmail) { CustomerResponse customerResponse = customerService.findDetailCustomer(customerEmail); return new ResponseEntity<>(customerResponse, HttpStatus.OK); } - @PatchMapping("/update") + @PatchMapping public ResponseEntity updateCustomer(@RequestBody CustomerUpdateRequest customerUpdateRequest) { CustomerResponse customerResponse = customerService.updateCustomer(customerUpdateRequest); return new ResponseEntity<>(customerResponse, HttpStatus.OK); } - @DeleteMapping("/delete/{customerEmail}") + @DeleteMapping("/{customerEmail}") public ResponseEntity deleteCustomer(@PathVariable String customerEmail) { customerService.deleteCustomer(customerEmail); return new ResponseEntity<>(HttpStatus.NO_CONTENT); } - @DeleteMapping("/delete/all") + @DeleteMapping("/delete-all") public ResponseEntity deleteAll() { customerService.deleteAllCustomers(); return new ResponseEntity<>(HttpStatus.NO_CONTENT); diff --git a/src/main/java/org/weekly/weekly/voucher/controller/api/VoucherAPIController.java b/src/main/java/org/weekly/weekly/voucher/controller/api/VoucherAPIController.java index 9dffac129f..b050fab915 100644 --- a/src/main/java/org/weekly/weekly/voucher/controller/api/VoucherAPIController.java +++ b/src/main/java/org/weekly/weekly/voucher/controller/api/VoucherAPIController.java @@ -11,7 +11,7 @@ import java.util.List; @RestController -@RequestMapping("/api/v1") +@RequestMapping("/api/v1/vouchers") public class VoucherAPIController { private final VoucherService voucherService; @@ -20,14 +20,14 @@ public VoucherAPIController(VoucherService voucherService) { this.voucherService = voucherService; } - @PostMapping("/voucher") + @PostMapping public ResponseEntity createVoucher(@RequestBody VoucherCreationRequest voucherCreationRequest) { VoucherCreationResponse voucherCreationResponse = voucherService.insertVoucher(voucherCreationRequest); return new ResponseEntity<>(voucherCreationResponse, HttpStatus.OK); } - @GetMapping("/vouchers") + @GetMapping public ResponseEntity> getVouchers() { VouchersResponse vouchersResponse = voucherService.getVouchers(); return new ResponseEntity<>(vouchersResponse.getResult(), HttpStatus.OK); From 0aa932aa428d66b55edf314dd0603c7ad046da4e Mon Sep 17 00:00:00 2001 From: parksey Date: Tue, 25 Jul 2023 06:05:58 +0900 Subject: [PATCH 27/28] =?UTF-8?q?test:=20Voucher=20=EB=B0=8F=20Customer?= =?UTF-8?q?=EC=97=90=20=EB=8C=80=ED=95=9C=20service=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=9E=91=EC=84=B1=20=EB=B0=8F?= =?UTF-8?q?=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=98=A4=EB=A5=98=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 5 + .../weekly/VoucherManagementController.java | 2 +- .../dto/request/CustomerCreationRequest.java | 4 + .../customer/service/CustomerService.java | 4 +- .../weekly/ui/CommandLineApplication.java | 6 +- .../weekly/ui/exception/InputValidator.java | 2 +- .../weekly/ui/reader/BufferedReaderWrap.java | 2 +- .../weekly/weekly/ui/writer/SystemWriter.java | 1 - .../voucher/service/VoucherService.java | 4 +- .../customer/JdbcCustomerRepositoryTest.java | 1 - .../weekly/customer/dto/CustomerDtoTest.java | 74 ++++++ .../customer/service/CustomerServiceTest.java | 225 ++++++++++++++++++ .../{ => global}/util/DiscountMapTest.java | 2 +- .../{ => global}/util/VoucherMenuTest.java | 9 +- .../weekly/weekly/voucher/VoucherTest.java | 4 +- .../weekly/voucher/dto/VoucherDtoTest.java | 90 +++++++ .../voucher/service/VoucherServiceTest.java | 88 +++++++ 17 files changed, 499 insertions(+), 24 deletions(-) create mode 100644 src/test/java/org/weekly/weekly/customer/dto/CustomerDtoTest.java create mode 100644 src/test/java/org/weekly/weekly/customer/service/CustomerServiceTest.java rename src/test/java/org/weekly/weekly/{ => global}/util/DiscountMapTest.java (96%) rename src/test/java/org/weekly/weekly/{ => global}/util/VoucherMenuTest.java (79%) create mode 100644 src/test/java/org/weekly/weekly/voucher/dto/VoucherDtoTest.java create mode 100644 src/test/java/org/weekly/weekly/voucher/service/VoucherServiceTest.java diff --git a/pom.xml b/pom.xml index ea55bea69b..e432970fdb 100644 --- a/pom.xml +++ b/pom.xml @@ -75,6 +75,11 @@ test + + org.mockito + mockito-core + + diff --git a/src/main/java/org/weekly/weekly/VoucherManagementController.java b/src/main/java/org/weekly/weekly/VoucherManagementController.java index 41cfbe2336..38df9e1eb9 100644 --- a/src/main/java/org/weekly/weekly/VoucherManagementController.java +++ b/src/main/java/org/weekly/weekly/VoucherManagementController.java @@ -8,11 +8,11 @@ import org.weekly.weekly.customer.dto.request.CustomerUpdateRequest; import org.weekly.weekly.customer.dto.response.CustomerResponse; import org.weekly.weekly.customer.dto.response.CustomersResponse; -import org.weekly.weekly.ui.CommandLineApplication; import org.weekly.weekly.global.util.CustomerMenu; import org.weekly.weekly.global.util.ManageMenu; import org.weekly.weekly.global.util.PrintMessageType; import org.weekly.weekly.global.util.VoucherMenu; +import org.weekly.weekly.ui.CommandLineApplication; import org.weekly.weekly.voucher.controller.VoucherController; import org.weekly.weekly.voucher.dto.request.VoucherCreationRequest; import org.weekly.weekly.voucher.dto.response.VoucherCreationResponse; diff --git a/src/main/java/org/weekly/weekly/customer/dto/request/CustomerCreationRequest.java b/src/main/java/org/weekly/weekly/customer/dto/request/CustomerCreationRequest.java index 5292b3dd80..8651b3db9d 100644 --- a/src/main/java/org/weekly/weekly/customer/dto/request/CustomerCreationRequest.java +++ b/src/main/java/org/weekly/weekly/customer/dto/request/CustomerCreationRequest.java @@ -29,6 +29,10 @@ public String getEmail() { return email; } + public String getName() { + return name; + } + public void setName(String name) { this.name = name; } diff --git a/src/main/java/org/weekly/weekly/customer/service/CustomerService.java b/src/main/java/org/weekly/weekly/customer/service/CustomerService.java index 9958721cde..d193afd878 100644 --- a/src/main/java/org/weekly/weekly/customer/service/CustomerService.java +++ b/src/main/java/org/weekly/weekly/customer/service/CustomerService.java @@ -28,8 +28,8 @@ public CustomerResponse createCustomer(CustomerCreationRequest creationRequest) validateCustomerNotExist(creationRequest.getEmail()); Customer customer = creationRequest.toCustomer(); - customerRepository.insert(customer); - return CustomerResponse.of(customer); + Customer savedCustomer = customerRepository.insert(customer); + return CustomerResponse.of(savedCustomer); } @Transactional diff --git a/src/main/java/org/weekly/weekly/ui/CommandLineApplication.java b/src/main/java/org/weekly/weekly/ui/CommandLineApplication.java index a1ed65596a..80e84e9730 100644 --- a/src/main/java/org/weekly/weekly/ui/CommandLineApplication.java +++ b/src/main/java/org/weekly/weekly/ui/CommandLineApplication.java @@ -6,13 +6,13 @@ import org.weekly.weekly.customer.dto.request.CustomerUpdateRequest; import org.weekly.weekly.customer.dto.response.CustomerResponse; import org.weekly.weekly.customer.dto.response.CustomersResponse; -import org.weekly.weekly.ui.exception.InputValidator; -import org.weekly.weekly.ui.reader.CommandReader; -import org.weekly.weekly.ui.writer.SystemWriter; import org.weekly.weekly.global.util.CustomerMenu; import org.weekly.weekly.global.util.ManageMenu; import org.weekly.weekly.global.util.Menu; import org.weekly.weekly.global.util.VoucherMenu; +import org.weekly.weekly.ui.exception.InputValidator; +import org.weekly.weekly.ui.reader.CommandReader; +import org.weekly.weekly.ui.writer.SystemWriter; import org.weekly.weekly.voucher.domain.DiscountType; import org.weekly.weekly.voucher.dto.request.VoucherCreationRequest; import org.weekly.weekly.voucher.dto.request.VoucherInfoRequest; diff --git a/src/main/java/org/weekly/weekly/ui/exception/InputValidator.java b/src/main/java/org/weekly/weekly/ui/exception/InputValidator.java index 171e2fc775..ff42dfa461 100644 --- a/src/main/java/org/weekly/weekly/ui/exception/InputValidator.java +++ b/src/main/java/org/weekly/weekly/ui/exception/InputValidator.java @@ -27,7 +27,7 @@ public static void notVoucherInputSize(String[] userInputs) { public static void notNumber(String[] userInputs) { try { Arrays.stream(userInputs) - .forEach(Long::parseLong); + .forEach(userInput->Long.parseLong(userInput.trim())); } catch (NumberFormatException exception) { throw new InputException(ExceptionCode.NOT_INPUT_FORMAT); } diff --git a/src/main/java/org/weekly/weekly/ui/reader/BufferedReaderWrap.java b/src/main/java/org/weekly/weekly/ui/reader/BufferedReaderWrap.java index eb310ebae3..08483777b5 100644 --- a/src/main/java/org/weekly/weekly/ui/reader/BufferedReaderWrap.java +++ b/src/main/java/org/weekly/weekly/ui/reader/BufferedReaderWrap.java @@ -2,8 +2,8 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.stereotype.Component; -import org.weekly.weekly.ui.exception.InputException; import org.weekly.weekly.global.handler.ExceptionCode; +import org.weekly.weekly.ui.exception.InputException; import java.io.BufferedReader; import java.io.IOException; diff --git a/src/main/java/org/weekly/weekly/ui/writer/SystemWriter.java b/src/main/java/org/weekly/weekly/ui/writer/SystemWriter.java index 03cb7d1547..848425ec92 100644 --- a/src/main/java/org/weekly/weekly/ui/writer/SystemWriter.java +++ b/src/main/java/org/weekly/weekly/ui/writer/SystemWriter.java @@ -5,7 +5,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.stereotype.Component; import org.weekly.weekly.global.util.*; -import org.weekly.weekly.util.*; import org.weekly.weekly.voucher.domain.DiscountType; import java.util.Arrays; diff --git a/src/main/java/org/weekly/weekly/voucher/service/VoucherService.java b/src/main/java/org/weekly/weekly/voucher/service/VoucherService.java index e1120a3e40..e48535e4fb 100644 --- a/src/main/java/org/weekly/weekly/voucher/service/VoucherService.java +++ b/src/main/java/org/weekly/weekly/voucher/service/VoucherService.java @@ -20,8 +20,8 @@ public VoucherService(VoucherRepository voucherRepository) { public VoucherCreationResponse insertVoucher(VoucherCreationRequest voucherCreationRequest) { Voucher voucher = voucherCreationRequest.toVoucher(); - voucherRepository.insert(voucher); - return new VoucherCreationResponse(voucher); + Voucher savedVoucher = voucherRepository.insert(voucher); + return new VoucherCreationResponse(savedVoucher); } public VouchersResponse getVouchers() { diff --git a/src/test/java/org/weekly/weekly/customer/JdbcCustomerRepositoryTest.java b/src/test/java/org/weekly/weekly/customer/JdbcCustomerRepositoryTest.java index f13b0ded8d..eff3456bf9 100644 --- a/src/test/java/org/weekly/weekly/customer/JdbcCustomerRepositoryTest.java +++ b/src/test/java/org/weekly/weekly/customer/JdbcCustomerRepositoryTest.java @@ -100,7 +100,6 @@ void deleteCustomer() { void 회원_삭제_실패_테스트() { // when jdbcCustomerRepository.deleteByEmail(customer.getEmail()); - } @Test diff --git a/src/test/java/org/weekly/weekly/customer/dto/CustomerDtoTest.java b/src/test/java/org/weekly/weekly/customer/dto/CustomerDtoTest.java new file mode 100644 index 0000000000..d0f711119b --- /dev/null +++ b/src/test/java/org/weekly/weekly/customer/dto/CustomerDtoTest.java @@ -0,0 +1,74 @@ +package org.weekly.weekly.customer.dto; + +import org.junit.jupiter.api.*; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; +import org.weekly.weekly.customer.dto.request.CustomerCreationRequest; +import org.weekly.weekly.customer.dto.request.CustomerUpdateRequest; +import org.weekly.weekly.ui.exception.InputException; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +@DisplayName("CustomerDto 테스트") +@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) +public class CustomerDtoTest { + + @DisplayName("CustomerUpdate: 업데이트, 삭제, 조회") + @Nested + class Update { + + @Test + void 고객정보_업데이트요청_성공_테스트() { + // Given + String email = "psy@naver.com"; + String newEamil = "newPsy@naver.com"; + + // When + CustomerUpdateRequest customerUpdateRequest = new CustomerUpdateRequest(email, newEamil); + + // Then + assertThat(customerUpdateRequest.email()).isEqualTo(email); + assertThat(customerUpdateRequest.newEmail()).isEqualTo(newEamil); + } + + @ParameterizedTest + @CsvSource({" , ", + "test, ", + ", test"}) + void 고객정보_잘못된_입력으로_업데이트_요청_실패_테스트(String email, String newEmail) { + assertThatThrownBy(() -> new CustomerUpdateRequest(email, newEmail)) + .isInstanceOf(InputException.class); + } + } + + @DisplayName("CustomerCreate") + @Nested + class Create { + + @Test + void 고객생성_요청_성공_테스트() { + // Given + String email = "email@naver.com"; + String name = "psy"; + + // When + CustomerCreationRequest customerCreationRequest = new CustomerCreationRequest(email, name); + + // Then + assertThat(customerCreationRequest.getEmail()).isEqualTo(email); + assertThat(customerCreationRequest.getName()).isEqualTo(name); + } + + @ParameterizedTest + @CsvSource({ + "email@naver.com, ", + ", name", + " , " + }) + void 고객정보_잘못된_입력으로_고객생성_요청_실패_테스트(String email, String name) { + assertThatThrownBy(() -> new CustomerUpdateRequest(email, name)) + .isInstanceOf(InputException.class); + } + } +} diff --git a/src/test/java/org/weekly/weekly/customer/service/CustomerServiceTest.java b/src/test/java/org/weekly/weekly/customer/service/CustomerServiceTest.java new file mode 100644 index 0000000000..a5dd066803 --- /dev/null +++ b/src/test/java/org/weekly/weekly/customer/service/CustomerServiceTest.java @@ -0,0 +1,225 @@ +package org.weekly.weekly.customer.service; + +import org.junit.jupiter.api.*; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.transaction.annotation.Transactional; +import org.weekly.weekly.customer.domain.Customer; +import org.weekly.weekly.customer.dto.request.CustomerCreationRequest; +import org.weekly.weekly.customer.dto.request.CustomerUpdateRequest; +import org.weekly.weekly.customer.dto.response.CustomerResponse; +import org.weekly.weekly.customer.dto.response.CustomersResponse; +import org.weekly.weekly.customer.exception.CustomerException; +import org.weekly.weekly.customer.repository.CustomerRepository; +import org.weekly.weekly.customer.service.CustomerService; + +import java.time.LocalDateTime; +import java.util.List; +import java.util.Optional; +import java.util.UUID; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.jupiter.api.Assertions.assertAll; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.mockito.BDDMockito.any; +import static org.mockito.BDDMockito.given; + +@DisplayName("CustomerService 테스트") +@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) +@ExtendWith(MockitoExtension.class) +public class CustomerServiceTest { + + @InjectMocks CustomerService customerService; + + @Mock CustomerRepository customerRepository; + + @Nested + class Create { + + private CustomerCreationRequest customerCreationRequest; + + @BeforeEach + void init_request() { + String email = "psy@naver.com"; + String name = "name"; + + customerCreationRequest = new CustomerCreationRequest(email, name); + } + + @Test + @Transactional + void 고객생성_성공_테스트() { + // Given + Customer customer = new Customer(UUID.randomUUID(), + customerCreationRequest.getName(), + customerCreationRequest.getEmail(), + LocalDateTime.now()); + CustomerResponse customerResponse = CustomerResponse.of(customer); + Customer savedCustomer = new Customer(customer.getCustomerId(), customer.getName(), customer.getEmail(), customer.getCreateAt()); + + given(customerRepository.findByEmail(customerCreationRequest.getEmail())).willReturn(Optional.empty()); + given(customerRepository.insert(any(Customer.class))).willReturn(savedCustomer); + + // When + CustomerResponse expectResponse = customerService.createCustomer(customerCreationRequest); + + // Then + assertThat(expectResponse).isNotNull(); + assertAll( + () -> assertThat(customerResponse.getEmail()).isEqualTo(expectResponse.getEmail()), + () -> assertThat(customerResponse.getName()).isEqualTo(expectResponse.getName()) + ); + } + + @Test + void 중복된_이메일으로_고객생성_실패_테스트() { + // Given + Customer customer = new Customer(UUID.randomUUID(), + customerCreationRequest.getName(), + customerCreationRequest.getEmail(), + LocalDateTime.now()); + given(customerRepository.findByEmail(customerCreationRequest.getEmail())).willReturn(Optional.of(customer)); + + // When + assertThatThrownBy(() -> customerService.createCustomer(customerCreationRequest)) + .isInstanceOf(CustomerException.class); + } + } + + @Nested + class Delete { + + private CustomerUpdateRequest customerUpdateRequest; + + @BeforeEach + void init_request() { + String email = "psy@naver.com"; + + customerUpdateRequest = new CustomerUpdateRequest(email); + } + + @Test + @Transactional + void 고객삭제_성공_테스트() { + // When + assertDoesNotThrow(() -> customerService.deleteCustomer(customerUpdateRequest)); + } + } + + @Nested + class Search { + + private CustomerUpdateRequest searchRequest; + + @BeforeEach + void init_request() { + String email = "psy@naver.com"; + + searchRequest = new CustomerUpdateRequest(email); + } + + @Test + void 고객_상세조회_성공_테스트() { + // Given + String mockName = "psy"; + Customer customer = new Customer(UUID.randomUUID(), + mockName, + searchRequest.email(), + LocalDateTime.now()); + CustomerResponse expectCustomer = CustomerResponse.of(customer); + + given(customerRepository.findByEmail(searchRequest.email())).willReturn(Optional.of(customer)); + + // When + CustomerResponse customerResponse = customerService.findDetailCustomer(searchRequest); + + // Then + assertThat(customerResponse).isNotNull(); + + assertAll( + () -> assertThat(expectCustomer.getName()).isEqualTo(customerResponse.getName()), + () -> assertThat(expectCustomer.getEmail()).isEqualTo(customerResponse.getEmail()), + () -> assertThat(expectCustomer.getCreateAt()).isEqualTo(customerResponse.getCreateAt()) + ); + } + + @Test + void 존재하지_않는_고객조회로_실패_테스트() { + // Given + given(customerRepository.findByEmail(searchRequest.email())).willReturn(Optional.empty()); + + // When + assertThatThrownBy(() -> customerService.findDetailCustomer(searchRequest)) + .isInstanceOf(CustomerException.class); + } + + @Test + void 모든_고객조회_성공_테스트() { + // Given + Customer mockCustomer = new Customer(UUID.randomUUID(), + "mock", + "mock@naver.com", + LocalDateTime.now()); + + given(customerRepository.findAll()).willReturn(List.of(mockCustomer)); + + // When + CustomersResponse customers = customerService.findAllCustomer(); + + // Then + assertThat(customers).isNotNull(); + assertThat(customers.getCustomerResponses()).isNotEmpty(); + } + } + + @Nested + class Update { + + private CustomerUpdateRequest updateRequest; + + @BeforeEach + void init_request() { + String email = "before@naver.com"; + String newEamil = "after@naver.com"; + + updateRequest = new CustomerUpdateRequest(email, newEamil); + } + + @Test + @Transactional + void 고객_이메일_업데이트_성공_테스트() { + // Given + String mockName = "mock"; + Customer customer = new Customer(UUID.randomUUID(), + mockName, + updateRequest.email(), + LocalDateTime.now()); + + Customer updatedCustomer = new Customer(customer.getCustomerId(), + customer.getName(), + updateRequest.newEmail(), + customer.getCreateAt()); + + CustomerResponse expectCustomer = CustomerResponse.of(updatedCustomer); + + given(customerRepository.findByEmail(updateRequest.newEmail())).willReturn(Optional.empty()); + given(customerRepository.findByEmail(updateRequest.email())).willReturn(Optional.of(customer)); + given(customerRepository.update(customer, updateRequest.newEmail())).willReturn(updatedCustomer); + + // When + CustomerResponse customerResponse = customerService.updateCustomer(updateRequest); + + // Then + assertThat(customerResponse).isNotNull(); + + assertAll( + () -> assertThat(expectCustomer.getName()).isEqualTo(customerResponse.getName()), + () -> assertThat(expectCustomer.getEmail()).isEqualTo(customerResponse.getEmail()), + () -> assertThat(expectCustomer.getCreateAt()).isEqualTo(customerResponse.getCreateAt()) + ); + } + } +} diff --git a/src/test/java/org/weekly/weekly/util/DiscountMapTest.java b/src/test/java/org/weekly/weekly/global/util/DiscountMapTest.java similarity index 96% rename from src/test/java/org/weekly/weekly/util/DiscountMapTest.java rename to src/test/java/org/weekly/weekly/global/util/DiscountMapTest.java index 90755b1595..61732248a6 100644 --- a/src/test/java/org/weekly/weekly/util/DiscountMapTest.java +++ b/src/test/java/org/weekly/weekly/global/util/DiscountMapTest.java @@ -1,4 +1,4 @@ -package org.weekly.weekly.util; +package org.weekly.weekly.global.util; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; diff --git a/src/test/java/org/weekly/weekly/util/VoucherMenuTest.java b/src/test/java/org/weekly/weekly/global/util/VoucherMenuTest.java similarity index 79% rename from src/test/java/org/weekly/weekly/util/VoucherMenuTest.java rename to src/test/java/org/weekly/weekly/global/util/VoucherMenuTest.java index 0659cf2291..7f1f2f6556 100644 --- a/src/test/java/org/weekly/weekly/util/VoucherMenuTest.java +++ b/src/test/java/org/weekly/weekly/global/util/VoucherMenuTest.java @@ -1,8 +1,7 @@ -package org.weekly.weekly.util; +package org.weekly.weekly.global.util; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; -import org.weekly.weekly.global.util.VoucherMenu; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -10,12 +9,6 @@ public class VoucherMenuTest { @ParameterizedTest @ValueSource(strings = {"exti", "he lo", "123fdp", "test"}) void 사용자_입력이_Voucher_메뉴에_없을때_예외반환(String testValue) { - // given - - // when - - // then - assertThatThrownBy(() -> VoucherMenu.getMenu(testValue)) .isInstanceOf(RuntimeException.class); } diff --git a/src/test/java/org/weekly/weekly/voucher/VoucherTest.java b/src/test/java/org/weekly/weekly/voucher/VoucherTest.java index 7b1c4ab167..799acc7d4e 100644 --- a/src/test/java/org/weekly/weekly/voucher/VoucherTest.java +++ b/src/test/java/org/weekly/weekly/voucher/VoucherTest.java @@ -30,7 +30,7 @@ void setVoucherRepository() { "100000,12: 1", "10,1: 1" }, delimiter = ':') - void 바우처가_이미_존재하면_예외발생(String userInput, String no) { + void 중복된_바우처_저장시_예외발생(String userInput, String no) { // Given UUID voucherId = UUID.randomUUID(); VoucherInfoRequest voucherInfo = VoucherInfoRequest.of(userInput); @@ -53,8 +53,6 @@ void setVoucherRepository() { }) void 바우처_발행시간이_유효시간보다_느리면_예외발생(String userInput) { // Given -// UUID voucherId = UUID.randomUUID(); -// LocalDate localDate = LocalDate.now(); DiscountType discount = DiscountType.FIXED; VoucherInfoRequest voucherInfo = VoucherInfoRequest.of(userInput); diff --git a/src/test/java/org/weekly/weekly/voucher/dto/VoucherDtoTest.java b/src/test/java/org/weekly/weekly/voucher/dto/VoucherDtoTest.java new file mode 100644 index 0000000000..e4281f912a --- /dev/null +++ b/src/test/java/org/weekly/weekly/voucher/dto/VoucherDtoTest.java @@ -0,0 +1,90 @@ +package org.weekly.weekly.voucher.dto; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.DisplayNameGeneration; +import org.junit.jupiter.api.DisplayNameGenerator; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; +import org.weekly.weekly.ui.exception.InputException; +import org.weekly.weekly.voucher.domain.DiscountType; +import org.weekly.weekly.voucher.domain.Voucher; +import org.weekly.weekly.voucher.dto.request.VoucherCreationRequest; +import org.weekly.weekly.voucher.dto.request.VoucherInfoRequest; +import org.weekly.weekly.voucher.dto.response.VoucherCreationResponse; + +import java.text.MessageFormat; +import java.time.LocalDate; +import java.util.UUID; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +@DisplayName("CustomerDto 테스트") +@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) +public class VoucherDtoTest { + + @ParameterizedTest + @ValueSource(strings = { + "10, 10", + "50, 12", + "70, 123" + }) + void 고정바우처_생성_성공_테스트(String userInput) { + // Given + VoucherInfoRequest voucherInfoRequest = VoucherInfoRequest.of(userInput); + + // When + VoucherCreationRequest voucherCreationRequest = new VoucherCreationRequest(voucherInfoRequest, DiscountType.FIXED); + + // Then + assertThat(voucherCreationRequest).isNotNull(); + assertThat(voucherCreationRequest.getDiscountType()).isEqualTo(DiscountType.FIXED); + } + + @ParameterizedTest + @ValueSource(strings = { + "10, 10", + "50, 12", + "70, 123" + }) + void 퍼센트바우처_생성_성공_테스트(String userInput) { + // Given + VoucherInfoRequest voucherInfoRequest = VoucherInfoRequest.of(userInput); + + // When + VoucherCreationRequest voucherCreationRequest = new VoucherCreationRequest(voucherInfoRequest, DiscountType.PERCENT); + + // Then + assertThat(voucherCreationRequest).isNotNull(); + assertThat(voucherCreationRequest.getDiscountType()).isEqualTo(DiscountType.PERCENT); + } + + @ParameterizedTest + @ValueSource(strings = {" , ", + "가나다, ", + ", 나다라" + }) + void 바우처_잘못된_입력으로_실패_테스트(String userInput) { + // When + Then + assertThatThrownBy(() -> VoucherInfoRequest.of(userInput)) + .isInstanceOf(InputException.class); + + } + + @Test + void 바우처_생성요청에_대한_반환_메세지_테스트() { + // Given + Voucher voucher = Voucher.of(UUID.randomUUID(), + 1000L, + LocalDate.now(), + 12, + DiscountType.FIXED); + + VoucherCreationResponse creationResponse = new VoucherCreationResponse(voucher); + + assertThat(creationResponse.result()) + .isEqualTo(MessageFormat.format("[ID: {0}, 금액: {1}, 등록일자: {2}, 유효기간: {3}]", + voucher.getVoucherId(), voucher.getAmount(), voucher.getRegistrationDate(), voucher.getExpirationDate())); + } +} diff --git a/src/test/java/org/weekly/weekly/voucher/service/VoucherServiceTest.java b/src/test/java/org/weekly/weekly/voucher/service/VoucherServiceTest.java new file mode 100644 index 0000000000..a02480aebc --- /dev/null +++ b/src/test/java/org/weekly/weekly/voucher/service/VoucherServiceTest.java @@ -0,0 +1,88 @@ +package org.weekly.weekly.voucher.service; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.DisplayNameGeneration; +import org.junit.jupiter.api.DisplayNameGenerator; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.weekly.weekly.voucher.domain.DiscountType; +import org.weekly.weekly.voucher.domain.Voucher; +import org.weekly.weekly.voucher.dto.request.VoucherCreationRequest; +import org.weekly.weekly.voucher.dto.request.VoucherInfoRequest; +import org.weekly.weekly.voucher.dto.response.VoucherCreationResponse; +import org.weekly.weekly.voucher.repository.VoucherRepository; +import org.weekly.weekly.voucher.service.VoucherService; + +import java.time.LocalDate; +import java.util.UUID; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.any; +import static org.mockito.BDDMockito.given; + +@DisplayName("VoucherService 테스트") +@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) +@ExtendWith(MockitoExtension.class) +public class VoucherServiceTest { + + @InjectMocks + VoucherService voucherService; + + @Mock + VoucherRepository voucherRepository; + + @Test + void 고정_바우처_생성_성공_테스트() { + // Given + Long amount = 1000000L; + Long expire = 1L; + LocalDate registrationDate = LocalDate.now(); + LocalDate expirationDate = LocalDate.now().plusDays(expire); + DiscountType discount = DiscountType.FIXED; + + VoucherInfoRequest voucherFixedInfo = new VoucherInfoRequest(amount, expire); + VoucherCreationRequest fixedRequest = new VoucherCreationRequest(voucherFixedInfo, discount); + Voucher mockVoucehr = new Voucher(UUID.randomUUID(), + amount, + registrationDate, + expirationDate, + discount.getNewInstance()); + + given(voucherRepository.insert(any(Voucher.class))).willReturn(mockVoucehr); + + // When + VoucherCreationResponse voucherCreationResponse = voucherService.insertVoucher(fixedRequest); + + // Then; + assertThat(voucherCreationResponse).isNotNull(); + } + + @Test + void 할인_바우처_생성_성공_테스트() { + // Given + Long percnet = 10L; + Long expire = 1L; + LocalDate registrationDate = LocalDate.now(); + LocalDate expirationDate = LocalDate.now().plusDays(expire); + DiscountType discount = DiscountType.PERCENT; + + VoucherInfoRequest voucherPercentInfo = new VoucherInfoRequest(percnet, expire); + VoucherCreationRequest percentRequest = new VoucherCreationRequest(voucherPercentInfo, discount); + Voucher mockVoucehr = new Voucher(UUID.randomUUID(), + percnet, + registrationDate, + expirationDate, + discount.getNewInstance()); + + given(voucherRepository.insert(any(Voucher.class))).willReturn(mockVoucehr); + + // When + VoucherCreationResponse voucherCreationResponse = voucherService.insertVoucher(percentRequest); + + // Then; + assertThat(voucherCreationResponse).isNotNull(); + } +} From 1b51c5d6eb51c18bcb1b4db5a2d65553a2e42ac7 Mon Sep 17 00:00:00 2001 From: parksey Date: Tue, 25 Jul 2023 23:16:25 +0900 Subject: [PATCH 28/28] =?UTF-8?q?fix:=20static=EA=B3=BC=20final=EC=9D=98?= =?UTF-8?q?=20=EC=9C=84=EC=B9=98=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/org/weekly/weekly/global/util/VoucherMenu.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/weekly/weekly/global/util/VoucherMenu.java b/src/main/java/org/weekly/weekly/global/util/VoucherMenu.java index 64995cf695..a6c5532e15 100644 --- a/src/main/java/org/weekly/weekly/global/util/VoucherMenu.java +++ b/src/main/java/org/weekly/weekly/global/util/VoucherMenu.java @@ -14,7 +14,7 @@ public enum VoucherMenu implements Menu { private final String printMessage; - private final static Map VOUCHER_MENU_MAP; + private static final Map VOUCHER_MENU_MAP; static { VOUCHER_MENU_MAP = new ConcurrentHashMap<>();