-
Notifications
You must be signed in to change notification settings - Fork 165
Expand file tree
/
Copy pathCustomerWebController.java
More file actions
60 lines (48 loc) · 2.2 KB
/
CustomerWebController.java
File metadata and controls
60 lines (48 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package org.prgrms.kdtspringdemo.customer.controller;
import org.prgrms.kdtspringdemo.customer.domain.Customer;
import org.prgrms.kdtspringdemo.customer.domain.dto.CustomerRequestDto;
import org.prgrms.kdtspringdemo.customer.domain.dto.CustomerViewDto;
import org.prgrms.kdtspringdemo.customer.service.CustomerService;
import org.prgrms.kdtspringdemo.wallet.service.WalletService;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
@Controller
@RequestMapping("/customers")
public class CustomerWebController {
private final CustomerService customerService;
private final WalletService walletService;
public CustomerWebController(CustomerService customerService, WalletService walletService) {
this.customerService = customerService;
this.walletService = walletService;
}
@GetMapping
public String getAllCustomers(Model model) {
List<Customer> customerList = customerService.findAll();
List<CustomerViewDto> customerViewDtos = new ArrayList<>();
customerList.stream().forEach(customer -> customerViewDtos.add(new CustomerViewDto(customer)));
List<Customer> noneHaveWalletCustomers = customerService.findNoneHaveWalletCustomer();
model.addAttribute("customerList", customerViewDtos);
model.addAttribute("customers", noneHaveWalletCustomers);
return "customer";
}
@PostMapping("/create")
public String createCustomer(@ModelAttribute CustomerRequestDto customerRequestDto) {
Customer customer = customerService.insert(customerRequestDto);
if(customer!=null) walletService.create(customer.getCustomerId());
return "redirect:/customers";
}
@GetMapping("/{customerId}/createWallet")
public String createWalletForCustomer(@PathVariable UUID customerId) {
walletService.create(customerId);
return "redirect:/customers";
}
@GetMapping("/{customerId}/delete")
public String deleteVoucher(@PathVariable UUID customerId) {
customerService.deleteById(customerId);
return "redirect:/customers";
}
}