Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Antonio Rueda
/
reserva-hoteles
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
ab329f6b
authored
Oct 23, 2024
by
Antonio Rueda
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Creado primer repositorio, operación de guardado e infraestructura para tests
parent
d40f6cbc
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
58 additions
and
2 deletions
pom.xml
src/main/java/es/ujaen/dae/reservahoteles/repositorios/RepositorioUsuarios.java
src/main/java/es/ujaen/dae/reservahoteles/servicios/ServicioReservas.java
src/main/resources/application-test.yml
src/main/resources/application.yml
src/test/java/es/ujaen/dae/reservahoteles/servicios/TestServicioReservas.java
pom.xml
View file @
ab329f6b
...
@@ -40,6 +40,17 @@
...
@@ -40,6 +40,17 @@
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>
com.mysql
</groupId>
<artifactId>
mysql-connector-j
</artifactId>
</dependency>
<dependency>
<groupId>
com.h2database
</groupId>
<artifactId>
h2
</artifactId>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-test
</artifactId>
<artifactId>
spring-boot-starter-test
</artifactId>
<scope>
test
</scope>
<scope>
test
</scope>
...
...
src/main/java/es/ujaen/dae/reservahoteles/repositorios/RepositorioUsuarios.java
0 → 100644
View file @
ab329f6b
package
es
.
ujaen
.
dae
.
reservahoteles
.
repositorios
;
import
es.ujaen.dae.reservahoteles.entidades.Usuario
;
import
es.ujaen.dae.reservahoteles.excepciones.ClienteYaRegistrado
;
import
jakarta.persistence.EntityManager
;
import
jakarta.persistence.PersistenceContext
;
import
jakarta.transaction.Transactional
;
import
org.springframework.dao.DataIntegrityViolationException
;
import
org.springframework.stereotype.Repository
;
/**
*
* @author administrador
*/
@Transactional
@Repository
public
class
RepositorioUsuarios
{
@PersistenceContext
EntityManager
em
;
public
void
guardar
(
Usuario
usuario
)
{
if
(
em
.
find
(
Usuario
.
class
,
usuario
.
email
())
!=
null
)
throw
new
ClienteYaRegistrado
();
em
.
persist
(
usuario
);
em
.
flush
();
}
}
src/main/java/es/ujaen/dae/reservahoteles/servicios/ServicioReservas.java
View file @
ab329f6b
...
@@ -6,6 +6,7 @@ import es.ujaen.dae.reservahoteles.entidades.Usuario;
...
@@ -6,6 +6,7 @@ import es.ujaen.dae.reservahoteles.entidades.Usuario;
import
es.ujaen.dae.reservahoteles.entidades.Hotel
;
import
es.ujaen.dae.reservahoteles.entidades.Hotel
;
import
es.ujaen.dae.reservahoteles.entidades.Reserva
;
import
es.ujaen.dae.reservahoteles.entidades.Reserva
;
import
es.ujaen.dae.reservahoteles.excepciones.ClienteYaRegistrado
;
import
es.ujaen.dae.reservahoteles.excepciones.ClienteYaRegistrado
;
import
es.ujaen.dae.reservahoteles.repositorios.RepositorioUsuarios
;
import
es.ujaen.dae.reservahoteles.util.UtilString
;
import
es.ujaen.dae.reservahoteles.util.UtilString
;
import
jakarta.validation.Valid
;
import
jakarta.validation.Valid
;
import
jakarta.validation.constraints.Email
;
import
jakarta.validation.constraints.Email
;
...
@@ -18,6 +19,7 @@ import java.util.List;
...
@@ -18,6 +19,7 @@ import java.util.List;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.Optional
;
import
java.util.Optional
;
import
java.util.TreeMap
;
import
java.util.TreeMap
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
...
@@ -30,6 +32,9 @@ import org.springframework.validation.annotation.Validated;
...
@@ -30,6 +32,9 @@ import org.springframework.validation.annotation.Validated;
@Service
@Service
@Validated
@Validated
public
class
ServicioReservas
{
public
class
ServicioReservas
{
@Autowired
RepositorioUsuarios
repositorioClientes
;
Map
<
Integer
,
Hotel
>
hoteles
;
Map
<
Integer
,
Hotel
>
hoteles
;
Map
<
String
,
Usuario
>
clientes
;
Map
<
String
,
Usuario
>
clientes
;
...
@@ -57,11 +62,13 @@ public class ServicioReservas {
...
@@ -57,11 +62,13 @@ public class ServicioReservas {
// Evitar que se cree un usuario con la cuenta de direccion
// Evitar que se cree un usuario con la cuenta de direccion
if
(
cliente
.
email
().
equals
(
direccion
.
email
()))
if
(
cliente
.
email
().
equals
(
direccion
.
email
()))
throw
new
ClienteYaRegistrado
();
throw
new
ClienteYaRegistrado
();
/*
if (clientes.containsKey(cliente.email()))
if (clientes.containsKey(cliente.email()))
throw new ClienteYaRegistrado();
throw new ClienteYaRegistrado();
clientes.put(cliente.email(), cliente);
clientes.put(cliente.email(), cliente);
*/
repositorioClientes
.
guardar
(
cliente
);
}
}
public
Optional
<
Usuario
>
login
(
@Email
String
email
,
String
clave
)
{
public
Optional
<
Usuario
>
login
(
@Email
String
email
,
String
clave
)
{
...
...
src/main/resources/application-test.yml
0 → 100644
View file @
ab329f6b
meses-historico
:
3
spring.datasource.url
:
jdbc:h2:mem:ujacoin_test;MODE=MYSQL;DATABASE_TO_LOWER=TRUE;DB_CLOSE_DELAY=-1
spring.jpa.properties.jakarta.persistence.schema-generation.database.action
:
drop-and-create
src/main/resources/application.yml
View file @
ab329f6b
...
@@ -4,6 +4,6 @@ spring.datasource.url: jdbc:mysql://localhost:3306/reservas
...
@@ -4,6 +4,6 @@ spring.datasource.url: jdbc:mysql://localhost:3306/reservas
spring.datasource.username
:
reservas_usr
spring.datasource.username
:
reservas_usr
spring.datasource.password
:
secret
spring.datasource.password
:
secret
spring.jpa.properties.jakarta.persistence.schema-generation.database.action
:
drop-and-creat
e
spring.jpa.properties.jakarta.persistence.schema-generation.database.action
:
non
e
src/test/java/es/ujaen/dae/reservahoteles/servicios/TestServicioReservas.java
View file @
ab329f6b
...
@@ -14,6 +14,7 @@ import org.junit.jupiter.api.Test;
...
@@ -14,6 +14,7 @@ import org.junit.jupiter.api.Test;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.test.annotation.DirtiesContext
;
import
org.springframework.test.annotation.DirtiesContext
;
import
org.springframework.test.context.ActiveProfiles
;
/**
/**
* Test de integración del servicio principal del sistema
* Test de integración del servicio principal del sistema
...
@@ -21,6 +22,7 @@ import org.springframework.test.annotation.DirtiesContext;
...
@@ -21,6 +22,7 @@ import org.springframework.test.annotation.DirtiesContext;
*/
*/
@SpringBootTest
(
classes
=
es
.
ujaen
.
dae
.
reservahoteles
.
app
.
ReservaHoteles
.
class
)
@SpringBootTest
(
classes
=
es
.
ujaen
.
dae
.
reservahoteles
.
app
.
ReservaHoteles
.
class
)
@ActiveProfiles
(
"test"
)
public
class
TestServicioReservas
{
public
class
TestServicioReservas
{
@Autowired
@Autowired
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment