Skip to content

Instantly share code, notes, and snippets.

@diegosilva13
Created December 17, 2017 18:08
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 diegosilva13/0b06c0062e36e1fd4d111113e715de28 to your computer and use it in GitHub Desktop.
Save diegosilva13/0b06c0062e36e1fd4d111113e715de28 to your computer and use it in GitHub Desktop.
package com.coderef.delivery.controller;
import com.coderef.delivery.model.Order;
import com.coderef.delivery.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping(value = "/api/orders", produces = MediaType.APPLICATION_JSON_VALUE)
public class OrderController {
@Autowired
private OrderService orderService;
@RequestMapping(method = RequestMethod.POST)
public ResponseEntity<Order> save(@RequestBody Order order){
return ResponseEntity.ok(orderService.save(order));
}
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public ResponseEntity<Order> findById(@PathVariable("id") Integer id){
return ResponseEntity.ok(orderService.findById(id));
}
@RequestMapping(method = RequestMethod.GET)
public ResponseEntity<Iterable<Order>> findAll(){
return ResponseEntity.ok().body(orderService.findAll());
}
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
public ResponseEntity<?> delete(@PathVariable("id") Integer id){
orderService.delete(id);
return ResponseEntity.ok().build();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment