Skip to content

Commit

Permalink
Merge pull request #15 from kiblykat/SIS-29
Browse files Browse the repository at this point in the history
Sis 29
  • Loading branch information
kiblykat authored Mar 24, 2024
2 parents 4175791 + 3f29f32 commit a133e31
Showing 1 changed file with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 {
Expand All @@ -35,6 +45,35 @@ public ResponseEntity<Customer> createCustomer(@Valid @RequestBody Customer cust
return new ResponseEntity<>(newCustomer, HttpStatus.CREATED);
}

// READ (all)
@GetMapping("")
public ResponseEntity<ArrayList<Customer>> getAllCustomers() {
ArrayList<Customer> allCustomers = customerService.getAllCustomers();
return new ResponseEntity<>(allCustomers, HttpStatus.OK);
}

// READ (id)
@GetMapping("/{id}")
public ResponseEntity<Customer> getCustomer(@PathVariable long id) {
Customer foundCustomer = customerService.getCustomer(id);
return new ResponseEntity<>(foundCustomer, HttpStatus.OK);
}

// UPDATE
@PutMapping("/{id}")
public ResponseEntity<Customer> 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<HttpStatus> deleteCustomer(@PathVariable long id) {
customerService.deleteCustomer(id);
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}

// // Nested route - Add review to customer.
// @PostMapping("/{id}/reviews")
// public ResponseEntity<Review> addReviewToCustomer(@PathVariable Long id,
Expand Down

0 comments on commit a133e31

Please sign in to comment.