Browse Source

APIREST RequestMapping

master
Juanjo 1 year ago
parent
commit
41a06d62c0
4 changed files with 66 additions and 0 deletions
  1. +1
    -0
      src/main/java/es/fp/edu/conecta2/controladores/Controlador01.java
  2. +32
    -0
      src/main/java/es/fp/edu/conecta2/controladores/TestController.java
  3. +16
    -0
      src/main/java/es/fp/edu/conecta2/servicios/AdminService.java
  4. +17
    -0
      src/main/java/es/fp/edu/conecta2/servicios/UserService.java

+ 1
- 0
src/main/java/es/fp/edu/conecta2/controladores/Controlador01.java View File

@ -9,4 +9,5 @@ public class Controlador01 {
public String prueba() { public String prueba() {
return "Esto es una prueba"; return "Esto es una prueba";
} }
} }

+ 32
- 0
src/main/java/es/fp/edu/conecta2/controladores/TestController.java View File

@ -0,0 +1,32 @@
package es.fp.edu.conecta2.controladores;
import es.fp.edu.conecta2.modelo.admin.Admin;
import es.fp.edu.conecta2.modelo.user.User;
import es.fp.edu.conecta2.servicios.AdminService;
import es.fp.edu.conecta2.servicios.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/databases")
public class TestController {
@Autowired
private AdminService adminService;
@Autowired
private UserService userService;
@ResponseStatus(HttpStatus.CREATED)
@PostMapping("/admin")
public void registrarAdmin(@RequestBody Admin admin){
adminService.registrar(admin);
}
@ResponseStatus(HttpStatus.CREATED)
@PostMapping("/user")
public void registrarUser(@RequestBody User usuario){
userService.registrar(usuario);
}
}

+ 16
- 0
src/main/java/es/fp/edu/conecta2/servicios/AdminService.java View File

@ -0,0 +1,16 @@
package es.fp.edu.conecta2.servicios;
import es.fp.edu.conecta2.modelo.admin.Admin;
import es.fp.edu.conecta2.repo.admin.IAdminRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class AdminService {
@Autowired
private IAdminRepo repo;
public void registrar(Admin t){
repo.save(t);
}
}

+ 17
- 0
src/main/java/es/fp/edu/conecta2/servicios/UserService.java View File

@ -0,0 +1,17 @@
package es.fp.edu.conecta2.servicios;
import es.fp.edu.conecta2.modelo.user.User;
import es.fp.edu.conecta2.repo.user.IUserRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class UserService {
@Autowired
private IUserRepo repo;
public void registrar(User t){
repo.save(t);
}
}

Loading…
Cancel
Save