-
Notifications
You must be signed in to change notification settings - Fork 165
Expand file tree
/
Copy pathCustomerViewController.java
More file actions
65 lines (51 loc) · 2.11 KB
/
CustomerViewController.java
File metadata and controls
65 lines (51 loc) · 2.11 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
61
62
63
64
65
package com.programmers.springweekly.controller;
import com.programmers.springweekly.dto.customer.request.CustomerCreateRequest;
import com.programmers.springweekly.dto.customer.response.CustomerListResponse;
import com.programmers.springweekly.dto.customer.response.CustomerResponse;
import com.programmers.springweekly.service.CustomerService;
import jakarta.validation.Valid;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.DeleteMapping;
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.RequestMapping;
@Controller
@RequiredArgsConstructor
@RequestMapping("/view/customer")
public class CustomerViewController {
private final CustomerService customerService;
@GetMapping
public String getMenuPage() {
return "customer/menu";
}
@GetMapping("/save")
public String getCreatePage() {
return "customer/create";
}
@PostMapping("/save")
public String save(@Valid CustomerCreateRequest customerCreateRequest) {
customerService.save(customerCreateRequest);
return "customer/menu";
}
@GetMapping("/findAll")
public String getFindAllPage(Model model) {
CustomerListResponse customerListResponse = customerService.findAll();
model.addAttribute("customerList", customerListResponse.getCustomerList());
return "customer/findAll";
}
@GetMapping("/find/{id}")
public String findById(@PathVariable("id") UUID customerId, Model model) {
CustomerResponse customerResponse = customerService.findById(customerId);
model.addAttribute("customer", customerResponse);
return "customer/find";
}
@DeleteMapping("/delete/{id}")
public String deleteById(@PathVariable("id") UUID customerId) {
customerService.deleteById(customerId);
return "redirect:/view/customer/find";
}
}