diff --git a/src/main/java/sg/com/smartinventory/controllers/CustomerController.java b/src/main/java/sg/com/smartinventory/controllers/CustomerController.java index 9339dc7..19ed27c 100644 --- a/src/main/java/sg/com/smartinventory/controllers/CustomerController.java +++ b/src/main/java/sg/com/smartinventory/controllers/CustomerController.java @@ -1,6 +1,10 @@ package sg.com.smartinventory.controllers; +import java.util.ArrayList; +import java.util.List; + import org.springframework.http.HttpStatus; +import org.springframework.http.HttpStatusCode; import org.springframework.http.ResponseEntity; // import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; @@ -14,6 +18,12 @@ // import sg.com.smartinventory.entities.Review; import sg.com.smartinventory.services.CustomerService; +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.RequestParam; +import org.springframework.web.bind.annotation.PutMapping; + @RestController @RequestMapping("/customers") public class CustomerController { @@ -35,6 +45,35 @@ public ResponseEntity createCustomer(@Valid @RequestBody Customer cust return new ResponseEntity<>(newCustomer, HttpStatus.CREATED); } + // READ (all) + @GetMapping("") + public ResponseEntity> getAllCustomers() { + ArrayList allCustomers = customerService.getAllCustomers(); + return new ResponseEntity<>(allCustomers, HttpStatus.OK); + } + + // READ (id) + @GetMapping("/{id}") + public ResponseEntity getCustomer(@PathVariable long id) { + Customer foundCustomer = customerService.getCustomer(id); + return new ResponseEntity<>(foundCustomer, HttpStatus.OK); + } + + // UPDATE + @PutMapping("/{id}") + public ResponseEntity updateCustomer(@PathVariable long id, @RequestBody Customer customer) { + // TODO: process PUT request + Customer updatedCustomer = customerService.updateCustomer(id, customer); + return new ResponseEntity<>(updatedCustomer, HttpStatus.OK); + } + + // DELETE + @DeleteMapping("/{id}") + public ResponseEntity deleteCustomer(@PathVariable long id) { + customerService.deleteCustomer(id); + return new ResponseEntity<>(HttpStatus.NOT_FOUND); + } + // // Nested route - Add review to customer. // @PostMapping("/{id}/reviews") // public ResponseEntity addReviewToCustomer(@PathVariable Long id,