Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Antonio Rueda
/
UJACoin
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
41bedd45
authored
Dec 17, 2020
by
Antonio Rueda
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Terminar de implementar listado de movimientos (con paginación)
parent
5f3b355a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
22 deletions
src/main/java/es/ujaen/dae/ujacoin/controladoresREST/ControladorREST.java
src/main/java/es/ujaen/dae/ujacoin/controladoresREST/DTO/DTOMovimiento.java
src/main/java/es/ujaen/dae/ujacoin/controladoresREST/ControladorREST.java
View file @
41bedd45
...
@@ -14,6 +14,7 @@ import es.ujaen.dae.ujacoin.entidades.Cuenta;
...
@@ -14,6 +14,7 @@ import es.ujaen.dae.ujacoin.entidades.Cuenta;
import
es.ujaen.dae.ujacoin.entidades.movimientos.Movimiento
;
import
es.ujaen.dae.ujacoin.entidades.movimientos.Movimiento
;
import
es.ujaen.dae.ujacoin.excepciones.ClienteNoRegistrado
;
import
es.ujaen.dae.ujacoin.excepciones.ClienteNoRegistrado
;
import
es.ujaen.dae.ujacoin.excepciones.ClienteYaRegistrado
;
import
es.ujaen.dae.ujacoin.excepciones.ClienteYaRegistrado
;
import
es.ujaen.dae.ujacoin.excepciones.SaldoInsuficienteParaOperacion
;
import
es.ujaen.dae.ujacoin.excepciones.TarjetaYaRegistrada
;
import
es.ujaen.dae.ujacoin.excepciones.TarjetaYaRegistrada
;
import
es.ujaen.dae.ujacoin.servicios.ServicioUjaCoin
;
import
es.ujaen.dae.ujacoin.servicios.ServicioUjaCoin
;
import
java.time.LocalDateTime
;
import
java.time.LocalDateTime
;
...
@@ -37,7 +38,7 @@ import org.springframework.web.bind.annotation.ResponseStatus;
...
@@ -37,7 +38,7 @@ import org.springframework.web.bind.annotation.ResponseStatus;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.RestController
;
/**
/**
* Controlador REST
* Controlador REST
para los servicios de UjaCoin
* @author ajrueda
* @author ajrueda
*/
*/
@RestController
@RestController
...
@@ -46,17 +47,20 @@ public class ControladorREST {
...
@@ -46,17 +47,20 @@ public class ControladorREST {
@Autowired
@Autowired
ServicioUjaCoin
servicios
;
ServicioUjaCoin
servicios
;
/** Handler para excepciones de violación de restricciones */
@ExceptionHandler
(
ConstraintViolationException
.
class
)
@ExceptionHandler
(
ConstraintViolationException
.
class
)
@ResponseStatus
(
HttpStatus
.
BAD_REQUEST
)
@ResponseStatus
(
HttpStatus
.
BAD_REQUEST
)
public
void
handlerViolacionRestricciones
(
ConstraintViolationException
e
)
{
public
void
handlerViolacionRestricciones
(
ConstraintViolationException
e
)
{
// return ResponseEntity.badRequest().body(e.getMessage());
// return ResponseEntity.badRequest().body(e.getMessage());
}
}
/** Handler para excepciones de accesos de usuarios no registrados */
@ExceptionHandler
(
ClienteNoRegistrado
.
class
)
@ExceptionHandler
(
ClienteNoRegistrado
.
class
)
@ResponseStatus
(
HttpStatus
.
NOT_FOUND
)
@ResponseStatus
(
HttpStatus
.
NOT_FOUND
)
public
void
handlerClienteNoRegistrado
(
ClienteNoRegistrado
e
)
{
public
void
handlerClienteNoRegistrado
(
ClienteNoRegistrado
e
)
{
}
}
/** Creación de clientes */
@PostMapping
(
"/clientes"
)
@PostMapping
(
"/clientes"
)
ResponseEntity
<
DTOCuenta
>
altaCliente
(
@RequestBody
DTOCliente
cliente
)
{
ResponseEntity
<
DTOCuenta
>
altaCliente
(
@RequestBody
DTOCliente
cliente
)
{
try
{
try
{
...
@@ -68,6 +72,7 @@ public class ControladorREST {
...
@@ -68,6 +72,7 @@ public class ControladorREST {
}
}
}
}
/** Login de clientes (temporal hasta incluir autenticación mediante Spring Security */
@GetMapping
(
"/clientes/{dni}"
)
@GetMapping
(
"/clientes/{dni}"
)
ResponseEntity
<
DTOCliente
>
loginCliente
(
@PathVariable
String
dni
,
@RequestParam
String
clave
)
{
ResponseEntity
<
DTOCliente
>
loginCliente
(
@PathVariable
String
dni
,
@RequestParam
String
clave
)
{
Optional
<
Cliente
>
cliente
=
servicios
.
loginCliente
(
dni
,
clave
);
Optional
<
Cliente
>
cliente
=
servicios
.
loginCliente
(
dni
,
clave
);
...
@@ -76,6 +81,7 @@ public class ControladorREST {
...
@@ -76,6 +81,7 @@ public class ControladorREST {
.
orElse
(
ResponseEntity
.
notFound
().
build
());
.
orElse
(
ResponseEntity
.
notFound
().
build
());
}
}
/** Registrar tarjetas */
@PostMapping
(
"/clientes/{dni}/tarjetas"
)
@PostMapping
(
"/clientes/{dni}/tarjetas"
)
ResponseEntity
<
Void
>
altaTarjeta
(
@PathVariable
String
dni
,
@RequestBody
DTOTarjeta
tarjeta
)
{
ResponseEntity
<
Void
>
altaTarjeta
(
@PathVariable
String
dni
,
@RequestBody
DTOTarjeta
tarjeta
)
{
try
{
try
{
...
@@ -87,6 +93,7 @@ public class ControladorREST {
...
@@ -87,6 +93,7 @@ public class ControladorREST {
}
}
}
}
/** Listar tarjetas */
@GetMapping
(
"/clientes/{dni}/tarjetas"
)
@GetMapping
(
"/clientes/{dni}/tarjetas"
)
@ResponseStatus
(
HttpStatus
.
OK
)
@ResponseStatus
(
HttpStatus
.
OK
)
List
<
DTOTarjeta
>
verTarjetas
(
@PathVariable
String
dni
)
{
List
<
DTOTarjeta
>
verTarjetas
(
@PathVariable
String
dni
)
{
...
@@ -94,6 +101,7 @@ public class ControladorREST {
...
@@ -94,6 +101,7 @@ public class ControladorREST {
.
map
(
t
->
new
DTOTarjeta
(
t
)).
collect
(
Collectors
.
toList
());
.
map
(
t
->
new
DTOTarjeta
(
t
)).
collect
(
Collectors
.
toList
());
}
}
/** Obtener una tarjeta concreta */
@GetMapping
(
"/clientes/{dni}/tarjetas/{num}"
)
@GetMapping
(
"/clientes/{dni}/tarjetas/{num}"
)
ResponseEntity
<
DTOTarjeta
>
verTarjeta
(
@PathVariable
String
dni
,
@PathVariable
String
num
)
{
ResponseEntity
<
DTOTarjeta
>
verTarjeta
(
@PathVariable
String
dni
,
@PathVariable
String
num
)
{
return
servicios
.
verTarjetas
(
dni
).
stream
()
return
servicios
.
verTarjetas
(
dni
).
stream
()
...
@@ -103,12 +111,14 @@ public class ControladorREST {
...
@@ -103,12 +111,14 @@ public class ControladorREST {
.
orElse
(
ResponseEntity
.
notFound
().
build
());
.
orElse
(
ResponseEntity
.
notFound
().
build
());
}
}
/** Crear cuentas adicionales */
@PostMapping
(
"/clientes/{dni}/cuentas"
)
@PostMapping
(
"/clientes/{dni}/cuentas"
)
@ResponseStatus
(
HttpStatus
.
CREATED
)
@ResponseStatus
(
HttpStatus
.
CREATED
)
DTOCuenta
altaCuenta
(
@PathVariable
String
dni
)
{
DTOCuenta
altaCuenta
(
@PathVariable
String
dni
)
{
return
new
DTOCuenta
(
servicios
.
crearCuenta
(
dni
));
return
new
DTOCuenta
(
servicios
.
crearCuenta
(
dni
));
}
}
/** Listar cuentas del cliente */
@GetMapping
(
"/clientes/{dni}/cuentas"
)
@GetMapping
(
"/clientes/{dni}/cuentas"
)
@ResponseStatus
(
HttpStatus
.
OK
)
@ResponseStatus
(
HttpStatus
.
OK
)
List
<
DTOCuenta
>
verCuentas
(
@PathVariable
String
dni
)
{
List
<
DTOCuenta
>
verCuentas
(
@PathVariable
String
dni
)
{
...
@@ -116,6 +126,7 @@ public class ControladorREST {
...
@@ -116,6 +126,7 @@ public class ControladorREST {
.
map
(
c
->
new
DTOCuenta
(
c
)).
collect
(
Collectors
.
toList
());
.
map
(
c
->
new
DTOCuenta
(
c
)).
collect
(
Collectors
.
toList
());
}
}
/** Obtener una cuenta concreta */
@GetMapping
(
"/clientes/{dni}/cuentas/{num}"
)
@GetMapping
(
"/clientes/{dni}/cuentas/{num}"
)
ResponseEntity
<
DTOCuenta
>
verCuenta
(
@PathVariable
String
dni
,
@PathVariable
String
num
)
{
ResponseEntity
<
DTOCuenta
>
verCuenta
(
@PathVariable
String
dni
,
@PathVariable
String
num
)
{
return
servicios
.
verCuentas
(
dni
).
stream
()
return
servicios
.
verCuentas
(
dni
).
stream
()
...
@@ -125,32 +136,39 @@ public class ControladorREST {
...
@@ -125,32 +136,39 @@ public class ControladorREST {
.
orElse
(
ResponseEntity
.
notFound
().
build
());
.
orElse
(
ResponseEntity
.
notFound
().
build
());
}
}
/** Registrar un nuevo movimiento en la cuenta */
@PostMapping
(
"/clientes/{dni}/cuentas/{numCuenta}/movimientos"
)
@PostMapping
(
"/clientes/{dni}/cuentas/{numCuenta}/movimientos"
)
ResponseEntity
<
Void
>
registrarMovimiento
(
@PathVariable
String
dni
,
@PathVariable
String
numCuenta
,
@RequestBody
DTOMovimiento
movimiento
)
{
ResponseEntity
<
Void
>
registrarMovimiento
(
@PathVariable
String
dni
,
@PathVariable
String
numCuenta
,
@RequestBody
DTOMovimiento
movimiento
)
{
if
(
movimiento
.
getTipo
()
==
null
)
{
if
(
movimiento
.
getTipo
()
==
null
)
{
return
ResponseEntity
.
badRequest
().
build
();
return
ResponseEntity
.
badRequest
().
build
();
}
}
switch
(
movimiento
.
getTipo
().
toLowerCase
())
{
try
{
case
DTOMovimiento
.
INGRESO
:
switch
(
movimiento
.
getTipo
())
{
servicios
.
ingreso
(
numCuenta
,
movimiento
.
getNumTarjeta
(),
movimiento
.
getImporte
());
case
DTOMovimiento
.
INGRESO
:
break
;
servicios
.
ingreso
(
numCuenta
,
movimiento
.
getNumTarjeta
(),
movimiento
.
getImporte
());
break
;
case
DTOMovimiento
.
REINTEGRO
:
servicios
.
reintegro
(
numCuenta
,
movimiento
.
getNumTarjeta
(),
movimiento
.
getImporte
());
case
DTOMovimiento
.
REINTEGRO
:
break
;
servicios
.
reintegro
(
numCuenta
,
movimiento
.
getNumTarjeta
(),
movimiento
.
getImporte
());
break
;
case
DTOMovimiento
.
TRANSFERENCIA_EMITIDA
:
servicios
.
transferencia
(
numCuenta
,
movimiento
.
getNumCuenta
(),
movimiento
.
getImporte
());
case
DTOMovimiento
.
TRANSFERENCIA_EMITIDA
:
break
;
servicios
.
transferencia
(
numCuenta
,
movimiento
.
getNumCuenta
(),
movimiento
.
getImporte
());
break
;
default
:
return
ResponseEntity
.
badRequest
().
build
();
default
:
return
ResponseEntity
.
badRequest
().
build
();
}
}
catch
(
SaldoInsuficienteParaOperacion
e
)
{
return
ResponseEntity
.
status
(
HttpStatus
.
PRECONDITION_FAILED
).
build
();
}
}
return
ResponseEntity
.
status
(
HttpStatus
.
CREATED
).
build
();
return
ResponseEntity
.
status
(
HttpStatus
.
CREATED
).
build
();
}
}
/** Listar movimientos, acotados por fechas y paginados */
@GetMapping
(
"/clientes/{dni}/cuentas/{numCuenta}/movimientos"
)
@GetMapping
(
"/clientes/{dni}/cuentas/{numCuenta}/movimientos"
)
ResponseEntity
<
List
<
DTOMovimiento
>>
verMovimientos
(
ResponseEntity
<
List
<
DTOMovimiento
>>
verMovimientos
(
@PathVariable
String
dni
,
@PathVariable
String
dni
,
...
...
src/main/java/es/ujaen/dae/ujacoin/controladoresREST/DTO/DTOMovimiento.java
View file @
41bedd45
...
@@ -34,23 +34,23 @@ public class DTOMovimiento {
...
@@ -34,23 +34,23 @@ public class DTOMovimiento {
/** Importe de la operación */
/** Importe de la operación */
float
importe
;
float
importe
;
public
DTOMovimiento
(
String
tipo
,
String
numTarjeta
,
String
numCuenta
,
in
t
importe
)
{
public
DTOMovimiento
(
String
tipo
,
String
numTarjeta
,
String
numCuenta
,
floa
t
importe
)
{
this
.
tipo
=
tipo
;
this
.
tipo
=
tipo
;
this
.
numTarjeta
=
numTarjeta
;
this
.
numTarjeta
=
numTarjeta
;
this
.
numCuenta
=
numCuenta
;
this
.
numCuenta
=
numCuenta
;
this
.
importe
=
importe
;
this
.
importe
=
importe
;
}
}
public
static
DTOMovimiento
ingreso
(
String
numTarjeta
,
in
t
importe
)
{
public
static
DTOMovimiento
ingreso
(
String
numTarjeta
,
floa
t
importe
)
{
return
new
DTOMovimiento
(
INGRESO
,
numTarjeta
,
null
,
importe
);
return
new
DTOMovimiento
(
INGRESO
,
numTarjeta
,
null
,
importe
);
}
}
public
static
DTOMovimiento
reintegro
(
String
numTarjeta
,
in
t
importe
)
{
public
static
DTOMovimiento
reintegro
(
String
numTarjeta
,
floa
t
importe
)
{
return
new
DTOMovimiento
(
REINTEGRO
,
numTarjeta
,
null
,
importe
);
return
new
DTOMovimiento
(
REINTEGRO
,
numTarjeta
,
null
,
importe
);
}
}
public
static
DTOMovimiento
transferencia
(
String
numCuentaDestino
,
in
t
importe
)
{
public
static
DTOMovimiento
transferencia
(
String
numCuentaDestino
,
floa
t
importe
)
{
return
new
DTOMovimiento
(
TRANSFERENCIA_EMITIDA
,
nu
mCuentaDestino
,
null
,
importe
);
return
new
DTOMovimiento
(
TRANSFERENCIA_EMITIDA
,
nu
ll
,
numCuentaDestino
,
importe
);
}
}
public
DTOMovimiento
(
Movimiento
movimiento
)
{
public
DTOMovimiento
(
Movimiento
movimiento
)
{
...
@@ -95,7 +95,7 @@ public class DTOMovimiento {
...
@@ -95,7 +95,7 @@ public class DTOMovimiento {
return
Optional
.
empty
();
return
Optional
.
empty
();
}
}
switch
(
tipo
.
toLowerCase
()
)
{
switch
(
tipo
)
{
case
INGRESO:
case
INGRESO:
if
(
numTarjeta
==
null
)
{
if
(
numTarjeta
==
null
)
{
return
Optional
.
empty
();
return
Optional
.
empty
();
...
...
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