JVFabia

Resources

Aug 25th, 2020
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.69 KB | None | 0 0
  1. package com.example.forge.miniproyecto.resource;
  2.  
  3. import com.example.forge.miniproyecto.dao.UserDAO;
  4. import com.example.forge.miniproyecto.entity.User;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.web.bind.annotation.*;
  7.  
  8. import java.util.List;
  9.  
  10. @RestController
  11. @RequestMapping("user")
  12. public class UserResource {
  13.  
  14.     @Autowired
  15.     UserDAO userDao;
  16.  
  17.     // crear (C de crud)
  18.     @RequestMapping(method = RequestMethod.POST)
  19.     public User crearUsuario(@RequestBody User usuario){
  20.         int retorno = userDao.insertar(usuario);
  21.         return usuario;
  22.     }
  23.  
  24.     // recuperar
  25.     @RequestMapping(method = RequestMethod.GET)
  26.     public List<User> listarUsuarios(){
  27.         return userDao.listarUsuarios();
  28.     }
  29.  
  30.     // eliminar
  31.     //@RequestMapping(method = RequestMethod.DELETE, value = "/{id}")
  32.     @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
  33.     public int eliminar(@PathVariable("id") int id){
  34.         int retorno = userDao.eliminar(id);
  35.         return retorno;
  36.     }
  37.  
  38.     // actualizar
  39.     @RequestMapping(value = "/{id}", method = RequestMethod.PUT)
  40.     public int actualizar(@RequestBody User usuario, @PathVariable("id") int id){
  41.         int retorno = userDao.actualizar(usuario, id);
  42.         return retorno;
  43.     }
  44.  
  45.     // recuperar
  46.     @RequestMapping(value = "/find/{id}", method = RequestMethod.GET)
  47.     public User findId(@PathVariable("id") int id){
  48.         return userDao.findId(id);
  49.     }
  50.  
  51.     // Exist
  52.     @RequestMapping(value = "/mail/{correo}", method = RequestMethod.GET)
  53.     public boolean isExist (@PathVariable("correo") String correo){
  54.         return userDao.isExists(correo);
  55.     }
  56. }
Add Comment
Please, Sign In to add comment