Commit 71cd62a9 by Adrian

Añadido edición de detalles de usuario, falta comprobaciones de datos

parent 52348f94
<?xml version="1.0" encoding="UTF-8"?>
<actions>
<action>
<actionName>run</actionName>
<packagings>
<packaging>jar</packaging>
</packagings>
<goals>
<goal>process-classes</goal>
<goal>org.codehaus.mojo:exec-maven-plugin:1.5.0:exec</goal>
</goals>
<properties>
<exec.args>-classpath %classpath es.ujaen.dae.ujacoinconsoleclient.client.Launcher</exec.args>
<exec.executable>java</exec.executable>
</properties>
</action>
</actions>
......@@ -13,7 +13,6 @@ import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.springframework.http.ResponseEntity;
import org.springframework.http.client.ClientHttpRequestFactory;
......@@ -73,4 +72,25 @@ public class InterfazAPIRest {
return new Pair<>(ErrorInterfaz.OK, response.getBody());
}
public Pair<ErrorInterfaz, ClienteDTO> actualizarCliente(ClienteDTO cliente) {
String url = "https://localhost:8080/ujacoin/clientes/{dni}";
ResponseEntity<ClienteDTO> response = null;
try {
restTemplate.put(url, cliente, dni);
response = restTemplate.getForEntity(url, ClienteDTO.class, dni);
} catch (Exception ex) {
if (ex instanceof org.springframework.web.client.HttpClientErrorException && ex.getMessage().startsWith("404")) {
return new Pair<>(ErrorInterfaz.ErrorCredenciales, null);
} else {
return new Pair<>(ErrorInterfaz.ErrorConexion, null);
}
}
return new Pair<>(ErrorInterfaz.OK, response.getBody());
}
}
......@@ -71,9 +71,9 @@ public class UjaCoinClient {
}
} while (respuesta.first != ErrorInterfaz.OK);
usuario = respuesta.second;
System.out.println("Login correcto");
menuUsuario();
......@@ -83,9 +83,9 @@ public class UjaCoinClient {
private void menuUsuario() {
int opcion = 0;
limpiarConsola();
do {
limpiarConsola();
System.out.println("Usuario " + usuario.getNombre());
System.out.println("Acciones:");
System.out.println("1->Detalles de usuario.");
......@@ -127,7 +127,7 @@ public class UjaCoinClient {
}
private void menuDetalleUsuario() {
int opcion = 0;
limpiarConsola();
......@@ -151,7 +151,7 @@ public class UjaCoinClient {
switch (opcion) {
case 1:
System.out.println("Opción no implementada, cliente en desarrollo");
menuEditarDatos();
break;
case 2:
break;
......@@ -162,7 +162,27 @@ public class UjaCoinClient {
}
} while (opcion != 2);
}
private void menuEditarDatos() {
System.out.println("Nueva dirección:");
usuario.setDireccion(scanner.nextLine());
System.out.println("Nuevo email:");
usuario.setEmail(scanner.nextLine());
System.out.println("Nuevo teléfono:");
usuario.setTelefono(scanner.nextLine());
//Comprobar datos introducidos antes de enviarlos al servidor
Pair<ErrorInterfaz, ClienteDTO> respuesta = interfaz.actualizarCliente(usuario);
if (respuesta.first == ErrorInterfaz.OK) {
usuario = respuesta.second;
}
}
private void menuCuentas() {
......
......@@ -87,4 +87,18 @@ public class ClienteDTO {
cuentasAsociadas.add(tarjeta);
}
public void setDireccion(String direccion) {
this.direccion = direccion;
}
public void setTelefono(String telefono) {
this.telefono = telefono;
}
public void setEmail(String email) {
this.email = email;
}
}
......@@ -12,5 +12,6 @@ package es.ujaen.dae.ujacoinconsoleclient.util;
public enum ErrorInterfaz {
OK,
ErrorConexion,
ErrorCredenciales
ErrorCredenciales,
ErrorFormatoDatos
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment