Browse Source

Controlador

master
Juanjo 1 year ago
parent
commit
188d7722ec
2 changed files with 18 additions and 3 deletions
  1. +16
    -2
      src/main/java/es/fp/edu/conecta2/controladores/ApiControlador.java
  2. +2
    -1
      src/main/java/es/fp/edu/conecta2/servicios/UserService.java

+ 16
- 2
src/main/java/es/fp/edu/conecta2/controladores/ApiControlador.java View File

@ -6,27 +6,41 @@ import es.fp.edu.conecta2.servicios.AdminService;
import es.fp.edu.conecta2.servicios.UserService; import es.fp.edu.conecta2.servicios.UserService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController @RestController
@RequestMapping("/api") @RequestMapping("/api")
public class ApiControlador { public class ApiControlador {
@Autowired @Autowired
private AdminService adminService; private AdminService adminService;
@Autowired @Autowired
private UserService userService; private UserService userService;
@ResponseStatus(HttpStatus.CREATED) @ResponseStatus(HttpStatus.CREATED)
@PostMapping("/admin") @PostMapping("/admin")
public void registrarAdmin(@RequestBody Admin admin){ public void registrarAdmin(@RequestBody Admin admin){
adminService.registrar(admin); adminService.registrar(admin);
} }
@ResponseStatus(HttpStatus.CREATED) @ResponseStatus(HttpStatus.CREATED)
@PostMapping("/user") @PostMapping("/user")
public void registrarUser(@RequestBody User usuario){
userService.registrar(usuario);
public User registrarUser(@RequestBody User usuario){
return this.userService.registrar(usuario);
}
@Autowired
private UserService servicioUser;
@GetMapping()
public List<User> obtenerUsuarios(){
return servicioUser.listarUser();
} }
} }

+ 2
- 1
src/main/java/es/fp/edu/conecta2/servicios/UserService.java View File

@ -12,8 +12,9 @@ public class UserService {
@Autowired @Autowired
private IUserRepo repo; private IUserRepo repo;
public void registrar(User t){
public User registrar(User t){
repo.save(t); repo.save(t);
return t;
} }
public List<User> listarUser(){ public List<User> listarUser(){


Loading…
Cancel
Save