File tree Expand file tree Collapse file tree 3 files changed +17
-0
lines changed
src/main/java/guru/springframework/spring6restmvc Expand file tree Collapse file tree 3 files changed +17
-0
lines changed Original file line number Diff line number Diff line change 11package guru .springframework .spring6restmvc .controller ;
22
3+ import guru .springframework .spring6restmvc .model .Beer ;
34import guru .springframework .spring6restmvc .model .Customer ;
45import guru .springframework .spring6restmvc .service .CustomerService ;
56import lombok .AllArgsConstructor ;
@@ -20,7 +21,12 @@ public class CustomerController {
2021
2122 private final CustomerService customerService ;
2223
24+ @ PutMapping ("{customerId}" )
25+ public ResponseEntity updateById (@ PathVariable ("customerId" ) UUID customerId , @ RequestBody Customer customer ) {
26+ customerService .updateCustomerById (customerId , customer );
2327
28+ return new ResponseEntity (HttpStatus .NO_CONTENT );
29+ }
2430
2531 @ PostMapping
2632 public ResponseEntity <Customer > createCustomer (@ RequestBody Customer customer ) {
Original file line number Diff line number Diff line change @@ -9,4 +9,6 @@ public interface CustomerService {
99 List <Customer > getAllCustomers ();
1010
1111 Customer saveNewCustomer (Customer customer );
12+
13+ void updateCustomerById (UUID customerId , Customer customer );
1214}
Original file line number Diff line number Diff line change @@ -67,4 +67,13 @@ public Customer saveNewCustomer(Customer customer) {
6767
6868 return savedCustomer ;
6969 }
70+
71+ @ Override
72+ public void updateCustomerById (UUID customerId , Customer customer ) {
73+ Customer existingCustomer = customerMap .get (customerId );
74+ existingCustomer .setName (customer .getName ());
75+ existingCustomer .setUpdateDate (LocalDateTime .now ());
76+
77+ customerMap .put (existingCustomer .getId (), existingCustomer );
78+ }
7079}
You can’t perform that action at this time.
0 commit comments