2 Commits

Author SHA1 Message Date
  Juanjo d3168c58b2 ApiControlar 1 year ago
  Juanjo 188d7722ec Controlador 1 year ago
5 changed files with 28 additions and 5 deletions
Unified View
  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
  3. +3
    -2
      src/main/resources/application.properties
  4. +5
    -0
      src/test/java/es/fp/edu/conecta2/Conecta2Application.java
  5. +2
    -0
      src/test/java/es/fp/edu/conecta2/Conecta2ApplicationTests.java

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

@ -8,25 +8,39 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
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(){


+ 3
- 2
src/main/resources/application.properties View File

@ -20,10 +20,11 @@ persistente.jpa.properties.hibernate.dialect=org.hibernate.dialect.MariaDBDialec
#persistente.jpa.hibernate.naming.physical-strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy #persistente.jpa.hibernate.naming.physical-strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy
temporal.datasource.url=jdbc:h2:mem:test
temporal.datasource.url=jdbc:h2:mem:AZ;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
temporal.datasource.driverClassName=org.h2.Driver
temporal.datasource.username=sa temporal.datasource.username=sa
temporal.datasource.password= temporal.datasource.password=
temporal.jpa.show-sql=true
temporal.jpa.database-platform=org.hibernate.dialect.H2Dialect
temporal.jpa.hibernate.ddl-auto=update temporal.jpa.hibernate.ddl-auto=update


src/main/java/es/fp/edu/conecta2/Conecta2Application.java → src/test/java/es/fp/edu/conecta2/Conecta2Application.java View File

@ -2,6 +2,7 @@ package es.fp.edu.conecta2;
import es.fp.edu.conecta2.modelo.user.User; import es.fp.edu.conecta2.modelo.user.User;
import es.fp.edu.conecta2.repo.user.IUserRepo; import es.fp.edu.conecta2.repo.user.IUserRepo;
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.boot.CommandLineRunner; import org.springframework.boot.CommandLineRunner;
@ -15,9 +16,13 @@ public class Conecta2Application implements CommandLineRunner {
SpringApplication.run(Conecta2Application.class, args); SpringApplication.run(Conecta2Application.class, args);
} }
@Autowired @Autowired
private UserService repositorioUser; private UserService repositorioUser;
@Autowired
private AdminService repositorioAdmin;
@Override @Override
public void run(String... args) throws Exception { public void run(String... args) throws Exception {
User user1 = new User(); User user1 = new User();

+ 2
- 0
src/test/java/es/fp/edu/conecta2/Conecta2ApplicationTests.java View File

@ -2,9 +2,11 @@ package es.fp.edu.conecta2;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.jdbc.Sql;
@SpringBootTest @SpringBootTest
class Conecta2ApplicationTests { class Conecta2ApplicationTests {
@Sql({ "/schema.sql", "/data.sql" })
@Test @Test
void contextLoads() { void contextLoads() {


Loading…
Cancel
Save