Last active
July 18, 2022 11:19
-
-
Save atesibrahim/ba8afef72335a3611c9e072eede74e2c to your computer and use it in GitHub Desktop.
RESTful example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RestController | |
@RequestMapping("books") | |
public class BookController { | |
@Autowired | |
private BookService bookService; | |
@GetMapping("/{id}") | |
public BookDto getById(@PathVariable(name = "id") Integer id) { | |
return bookService.getById(id); | |
} | |
@PostMapping | |
@ResponseStatus(HttpStatus.CREATED) | |
public void save(@RequestBody BookDto bookDto) { | |
bookService.create(bookDto); | |
} | |
@PutMapping("/{id}/stock") | |
public BookDto updateStock(@PathVariable(name = "id") Integer id, @RequestBody Stock stock){ | |
return bookService.updateStock(id, stock); | |
} | |
@DeleteMapping("/{id}") | |
@ResponseStatus(HttpStatus.NO_CONTENT) | |
public BookDto delete(@PathVariable(name = "id") Integer id) { | |
return bookService.delete(id); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment