Advertisement
andersonalmada2

Untitled

Aug 12th, 2022
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.86 KB | None | 0 0
  1. package br.ufc.mandacaru5.controller;
  2.  
  3. import java.util.List;
  4.  
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.http.HttpStatus;
  7. import org.springframework.http.ResponseEntity;
  8. import org.springframework.web.bind.annotation.DeleteMapping;
  9. import org.springframework.web.bind.annotation.GetMapping;
  10. import org.springframework.web.bind.annotation.PathVariable;
  11. import org.springframework.web.bind.annotation.PostMapping;
  12. import org.springframework.web.bind.annotation.PutMapping;
  13. import org.springframework.web.bind.annotation.RequestBody;
  14. import org.springframework.web.bind.annotation.RequestMapping;
  15. import org.springframework.web.bind.annotation.RestController;
  16.  
  17. import br.ufc.mandacaru5.model.Post;
  18. import br.ufc.mandacaru5.service.PostService;
  19. import br.ufc.mandacaru5.util.Properties;
  20.  
  21. @RestController
  22. @RequestMapping(path = "/api/posts")
  23. public class PostController {
  24.  
  25.     @Autowired
  26.     PostService service;
  27.    
  28.     @Autowired
  29.     Properties properties;
  30.  
  31.     @GetMapping
  32.     public ResponseEntity<List<Post>> findAll() {
  33.         System.out.println(properties.getPost());
  34.        
  35.         return new ResponseEntity<List<Post>>(service.findAllPostsByRequest(), HttpStatus.OK);
  36.     }
  37.    
  38.     @GetMapping(path = "{id}")
  39.     public ResponseEntity<Post> find(@PathVariable("id") int id) {
  40.         return new ResponseEntity<Post>(service.findPostByRequest(id), HttpStatus.OK);
  41.     }
  42.    
  43.     @PostMapping
  44.     public ResponseEntity<Post> save(@RequestBody Post post) {
  45.         return new ResponseEntity<Post>(service.saveByRequest(post), HttpStatus.OK);
  46.     }
  47.  
  48.     @PutMapping(path = "{id}")
  49.     public ResponseEntity<Post> update(@PathVariable("id") int id, @RequestBody Post post) {
  50.         return new ResponseEntity<Post>(service.updateByRequest(id, post), HttpStatus.OK);
  51.     }
  52.  
  53.     @DeleteMapping(path = "{id}")
  54.     public void delete(@PathVariable("id") int id) {
  55.         service.deleteByRequest(id);
  56.     }
  57. }
  58.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement