-
Notifications
You must be signed in to change notification settings - Fork 171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[5기 - 이중원] SpringBoot Part3 Weekly Mission 제출합니다. #970
base: shoeone
Are you sure you want to change the base?
Changes from all commits
2cfd990
ab537b1
143ea86
f54ae10
50e516c
f84a2ee
90d64ae
2f5e047
888f096
b106396
656ac05
e3f8c4d
fdab3d6
a06c20a
a903890
06b430c
f0661d5
0fa0927
9a3745e
8c9d938
c1b4fc7
acab01c
574c0b9
a690cd9
c47a0fd
351a4b2
6289fe6
5aa2bf2
d48a364
b3223fd
2a62343
1f0a414
ad4ab58
fbf567c
1df00a5
52b3520
ac9547c
54a0120
f2259de
d5b64d8
928a67e
320a0f0
6ae254f
f3adea9
e61363d
9c51d76
55c86a4
7621d23
daa7ec1
b5fc35c
8ff277d
a621efd
b062ff4
da3092e
1e62ee8
107a963
af88595
be43468
abf4e90
0846470
9a6c275
9ace237
f15bc48
20dd088
719fb6f
81c405f
0cee509
b46dce4
efe9095
a335184
ecdea71
9b2e795
a232c8a
1e27ba4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,8 @@ | |
.idea/**/dictionaries | ||
.idea/**/shelf | ||
|
||
**/csv/** | ||
|
||
# AWS User-specific | ||
.idea/**/aws.xml | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.programmers.springorder; | ||
|
||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
|
||
@Controller | ||
public class HomeController { | ||
@GetMapping("/") | ||
public String home(){ | ||
return "index"; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,21 @@ | ||
package org.programmers.springorder; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.http.converter.HttpMessageConverter; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
|
||
import java.util.List; | ||
|
||
@SpringBootApplication | ||
public class SpringOrderApplication { | ||
private static final Logger log = LoggerFactory.getLogger(SpringOrderApplication.class); | ||
public class SpringOrderApplication implements WebMvcConfigurer { | ||
|
||
public static void main(String[] args) { | ||
log.info("Voucher 관리 애플리케이션 구동"); | ||
SpringApplication.run(SpringOrderApplication.class, args).close(); | ||
} | ||
public static void main(String[] args) { | ||
SpringApplication.run(SpringOrderApplication.class, args); | ||
} | ||
|
||
@Override | ||
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) { | ||
WebMvcConfigurer.super.configureMessageConverters(converters); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,65 @@ | ||
package org.programmers.springorder; | ||
|
||
import org.programmers.springorder.console.Console; | ||
import org.programmers.springorder.consts.ErrorMessage; | ||
import org.programmers.springorder.consts.Message; | ||
import org.programmers.springorder.customer.controller.CustomerController; | ||
import org.programmers.springorder.utils.MenuType; | ||
import org.programmers.springorder.voucher.controller.VoucherController; | ||
import org.programmers.springorder.voucher.controller.VoucherConsoleController; | ||
import org.springframework.boot.CommandLineRunner; | ||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Profile("test") | ||
@Component | ||
public class VoucherApplication implements CommandLineRunner { | ||
|
||
private final Console console; | ||
private final VoucherController voucherController; | ||
private final VoucherConsoleController voucherConsoleController; | ||
private final CustomerController customerController; | ||
public VoucherApplication(Console console, VoucherController voucherController, CustomerController customerController) { | ||
public VoucherApplication(Console console, VoucherConsoleController voucherConsoleController, CustomerController customerController) { | ||
this.console = console; | ||
this.voucherController = voucherController; | ||
this.voucherConsoleController = voucherConsoleController; | ||
this.customerController = customerController; | ||
} | ||
|
||
@Override | ||
public void run(String... args) { | ||
boolean isRunning = true; | ||
|
||
boolean isRunning = true; | ||
boolean isWeb = false; | ||
if(chooseMedia()){ | ||
isWeb = true; | ||
}; | ||
while(isRunning) { | ||
if(isWeb) break; | ||
MenuType menu = console.inputMenu(); | ||
|
||
switch (menu) { | ||
case EXIT -> { | ||
isRunning = false; | ||
console.printMessage(Message.EXIT_PROGRAM_MESSAGE); | ||
} | ||
case CREATE -> voucherController.createVoucher(); | ||
case LIST -> voucherController.getVoucherList(); | ||
case CREATE -> voucherConsoleController.createVoucher(); | ||
case LIST -> voucherConsoleController.getVoucherList(); | ||
case BLACK -> customerController.printBlackList(); | ||
case ALLOCATE -> voucherController.giveVoucher(); | ||
case GET_OWNER_VOUCHER -> voucherController.getVouchersOfOwner(); | ||
case DELETE_VOUCHER -> voucherController.deleteVoucher(); | ||
case ALLOCATE -> voucherConsoleController.giveVoucher(); | ||
case GET_OWNER_VOUCHER -> voucherConsoleController.getVouchersOfOwner(); | ||
case DELETE_VOUCHER -> voucherConsoleController.deleteVoucher(); | ||
case SEARCH_VOUCHER_OWNER -> customerController.getVoucherOwner(); | ||
} | ||
} | ||
} | ||
|
||
private boolean chooseMedia() { | ||
String media = console.chooseMedia(); | ||
if(media.equals("1")){ | ||
return true; | ||
} | ||
if(media.equals("2")){ | ||
return false; | ||
}; | ||
throw new RuntimeException(ErrorMessage.INVALID_VALUE_MESSAGE); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,64 @@ | ||||||||||||||||||
package org.programmers.springorder.customer.controller; | ||||||||||||||||||
|
||||||||||||||||||
import org.programmers.springorder.customer.dto.CustomerRequestDto; | ||||||||||||||||||
import org.programmers.springorder.customer.dto.CustomerResponseDto; | ||||||||||||||||||
import org.programmers.springorder.customer.service.CustomerService; | ||||||||||||||||||
import org.programmers.springorder.voucher.dto.VoucherResponseDto; | ||||||||||||||||||
import org.programmers.springorder.voucher.service.VoucherService; | ||||||||||||||||||
import org.springframework.context.annotation.Profile; | ||||||||||||||||||
import org.springframework.stereotype.Controller; | ||||||||||||||||||
import org.springframework.ui.Model; | ||||||||||||||||||
import org.springframework.web.bind.annotation.GetMapping; | ||||||||||||||||||
import org.springframework.web.bind.annotation.PathVariable; | ||||||||||||||||||
import org.springframework.web.bind.annotation.PostMapping; | ||||||||||||||||||
|
||||||||||||||||||
import java.util.List; | ||||||||||||||||||
import java.util.UUID; | ||||||||||||||||||
|
||||||||||||||||||
@Profile("prod") | ||||||||||||||||||
@Controller | ||||||||||||||||||
public class CustomerPageController { | ||||||||||||||||||
|
||||||||||||||||||
private final CustomerService customerService; | ||||||||||||||||||
private final VoucherService voucherService; | ||||||||||||||||||
|
||||||||||||||||||
public CustomerPageController(CustomerService customerService, VoucherService voucherService) { | ||||||||||||||||||
this.customerService = customerService; | ||||||||||||||||||
this.voucherService = voucherService; | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
@GetMapping("/customers") | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. /customers를 prefix 형태로 설정하면 좋을 것 같습니다. |
||||||||||||||||||
public String getCustomerListPage(Model model){ | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. query String으로 필터해서 blackcustomers까지 하나의 컨트롤러에서 처리하는게 훨씬 좋을거 같습니다. |
||||||||||||||||||
List<CustomerResponseDto> allCustomers = customerService.getAllCustomers(); | ||||||||||||||||||
model.addAttribute("customerList", allCustomers); | ||||||||||||||||||
return "customers"; | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
@GetMapping("/blackCustomers") | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. /customer path에 query string으로 표현해보는 건 어떨까요? |
||||||||||||||||||
public String getBlackCustomerListPage(Model model){ | ||||||||||||||||||
List<CustomerResponseDto> allCustomers = customerService.getBlackList(); | ||||||||||||||||||
model.addAttribute("customerList", allCustomers); | ||||||||||||||||||
return "customers"; | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
@GetMapping("/customers/{customerId}") | ||||||||||||||||||
public String getCustomerListPage(@PathVariable UUID customerId, Model model){ | ||||||||||||||||||
CustomerResponseDto customer = customerService.findCustomer(customerId); | ||||||||||||||||||
List<VoucherResponseDto> customerOwnedVouchers = voucherService.getCustomerOwnedVouchers(customerId); | ||||||||||||||||||
model.addAttribute("customer", customer); | ||||||||||||||||||
model.addAttribute("customerVoucherList", customerOwnedVouchers); | ||||||||||||||||||
return "customer-detail"; | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
@GetMapping("/new-customer") | ||||||||||||||||||
public String getNewCustomerPage(){ | ||||||||||||||||||
return "new-customer"; | ||||||||||||||||||
} | ||||||||||||||||||
Comment on lines
+53
to
+56
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
|
||||||||||||||||||
@PostMapping("/customers") | ||||||||||||||||||
public String enrollCustomer(CustomerRequestDto requestDto){ | ||||||||||||||||||
customerService.newCustomer(requestDto); | ||||||||||||||||||
return "redirect:/customers"; | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package org.programmers.springorder.customer.controller; | ||
|
||
import org.programmers.springorder.customer.dto.CustomerRequestDto; | ||
import org.programmers.springorder.customer.dto.CustomerResponseDto; | ||
import org.programmers.springorder.customer.service.CustomerService; | ||
import org.programmers.springorder.voucher.dto.Response; | ||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.ui.Model; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
@Profile("default") | ||
@RestController | ||
public class CustomerRestController { | ||
|
||
private final CustomerService customerService; | ||
|
||
public CustomerRestController(CustomerService customerService) { | ||
this.customerService = customerService; | ||
} | ||
|
||
@GetMapping("api/v1/customers") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ReqeustMapping에 api/v1/customers를 동일하게 넣어두면 좋을거 같습니다. |
||
public Response<List<CustomerResponseDto>> getCustomerListPage(){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. blackcustomers를 쿼리스토링으로 필터링 하는게 더 좋을거 같아요. |
||
return Response.success(customerService.getAllCustomers()); | ||
} | ||
|
||
@GetMapping("api/v1/blackCustomers") | ||
public Response<List<CustomerResponseDto>> getBlackCustomerListPage(){ | ||
return Response.success(customerService.getBlackList()); | ||
} | ||
|
||
@GetMapping("api/v1/customers/{customerId}") | ||
public Response<CustomerResponseDto> getCustomerDetail(@PathVariable UUID customerId, Model model){ | ||
return Response.success(customerService.findCustomer(customerId)); | ||
} | ||
|
||
|
||
@PostMapping("api/v1/customers") | ||
public Response<Void> enrollCustomer(CustomerRequestDto requestDto){ | ||
customerService.newCustomer(requestDto); | ||
return Response.success(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. status 204 no_content 을 쓰는게 더 좋을거 같습니다. |
||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package org.programmers.springorder.customer.dto; | ||
|
||
import org.programmers.springorder.customer.model.CustomerType; | ||
import org.springframework.lang.NonNull; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. validatiton으로 하면 좋을거 같습니다. |
||
|
||
public record CustomerRequestDto( | ||
@NonNull String name, | ||
@NonNull CustomerType customerType) { | ||
Comment on lines
+7
to
+8
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 빈값이 들어와도 괜찮을까요? |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
통일성을 맞춰서 예약어는 대문자로 쓰시는게 어떨까요?