Skip to content

Commit a995da5

Browse files
committed
1 parent 7dddb01 commit a995da5

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

src/main/java/guru/springframework/spring6restmvc/controller/CustomerController.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package guru.springframework.spring6restmvc.controller;
22

3+
import guru.springframework.spring6restmvc.model.Beer;
34
import guru.springframework.spring6restmvc.model.Customer;
45
import guru.springframework.spring6restmvc.service.CustomerService;
56
import 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) {

src/main/java/guru/springframework/spring6restmvc/service/CustomerService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

src/main/java/guru/springframework/spring6restmvc/service/CustomerServiceImpl.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)