Skip to content

Instantly share code, notes, and snippets.

@henesgokdag
Created January 1, 2022 10:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save henesgokdag/5e9cfe16db4e1c2447d28323c0f7568d to your computer and use it in GitHub Desktop.
Save henesgokdag/5e9cfe16db4e1c2447d28323c0f7568d to your computer and use it in GitHub Desktop.
@RestController
@RequestMapping(value = "/api")
public class ProductController {
@Autowired
private ProductService productService;
@GetMapping("/products")
public ResponseEntity<List<Product>> allProducts() {
List<Product> allProducts = productService.allProducts();
return new ResponseEntity<List<Product>>(allProducts, HttpStatus.OK);
}
@PostMapping("/products")
public ResponseEntity<Product> createProduct(@RequestBody Product product) {
productService.saveProduct(product);
return new ResponseEntity<Product>(product, HttpStatus.OK);
}
@GetMapping("/products/{id}")
public ResponseEntity<Product> getProductById(@PathVariable("id") String id) {
Product product =productService.getProductById(id);
return new ResponseEntity<Product>(product, HttpStatus.OK);
}
@GetMapping("/find-product-by-name")
public ResponseEntity<List<Product>> findProductByName(@RequestParam String name) {
List<Product> products =productService.findProductByName(name);
return new ResponseEntity<List<Product>>(products, HttpStatus.OK);
}
@PutMapping("/products/{id}")
public ResponseEntity<Product> updateProductById(@PathVariable("id") String id, @RequestBody Product product) {
Product updatedProduct =productService.updateProductById(id,product);
return new ResponseEntity<Product>(updatedProduct, HttpStatus.OK);
}
@DeleteMapping("/products/{id}")
public ResponseEntity<String> deleteProductById(@PathVariable("id") String id) {
productService.deleteProductById(id);
return new ResponseEntity<String>("Ürün Silindi", HttpStatus.OK);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment