Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@
hs_err_pid*
replay_pid*

# End of https://www.toptal.com/developers/gitignore/api/java
# End of https://www.toptal.com/developers/gitignore/api/java
/target/
7 changes: 0 additions & 7 deletions .vscode/settings.json

This file was deleted.

2 changes: 0 additions & 2 deletions db/user.csv

This file was deleted.

1 change: 1 addition & 0 deletions filedbejer4
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Manu�|caca|75858548574
55 changes: 55 additions & 0 deletions nbactions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?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:3.0.0:exec</goal>
</goals>
<properties>
<exec.vmArgs></exec.vmArgs>
<exec.args>${exec.vmArgs} -classpath %classpath ${exec.mainClass} ${exec.appArgs}</exec.args>
<exec.appArgs></exec.appArgs>
<exec.mainClass>com.curso.baptisterio.java.App</exec.mainClass>
<exec.executable>java</exec.executable>
</properties>
</action>
<action>
<actionName>debug</actionName>
<packagings>
<packaging>jar</packaging>
</packagings>
<goals>
<goal>process-classes</goal>
<goal>org.codehaus.mojo:exec-maven-plugin:3.0.0:exec</goal>
</goals>
<properties>
<exec.vmArgs>-agentlib:jdwp=transport=dt_socket,server=n,address=${jpda.address}</exec.vmArgs>
<exec.args>${exec.vmArgs} -classpath %classpath ${exec.mainClass} ${exec.appArgs}</exec.args>
<exec.appArgs></exec.appArgs>
<exec.mainClass>com.curso.baptisterio.java.App</exec.mainClass>
<exec.executable>java</exec.executable>
<jpda.listen>true</jpda.listen>
</properties>
</action>
<action>
<actionName>profile</actionName>
<packagings>
<packaging>jar</packaging>
</packagings>
<goals>
<goal>process-classes</goal>
<goal>org.codehaus.mojo:exec-maven-plugin:3.0.0:exec</goal>
</goals>
<properties>
<exec.vmArgs></exec.vmArgs>
<exec.args>${exec.vmArgs} -classpath %classpath ${exec.mainClass} ${exec.appArgs}</exec.args>
<exec.mainClass>com.curso.baptisterio.java.App</exec.mainClass>
<exec.executable>java</exec.executable>
<exec.appArgs></exec.appArgs>
</properties>
</action>
</actions>
14 changes: 14 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.curso</groupId>
<artifactId>Baptisterio-Java</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>19</maven.compiler.source>
<maven.compiler.target>19</maven.compiler.target>
<exec.mainClass>com.curso.baptisterio.java.BaptisterioJava</exec.mainClass>
</properties>
</project>
37 changes: 0 additions & 37 deletions src/User.java

This file was deleted.

51 changes: 31 additions & 20 deletions src/App.java → .../java/com/curso/baptisterio/java/App.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@

package com.curso.baptisterio.java;
import java.time.DateTimeException;
import java.time.LocalDate;
import java.time.format.DateTimeParseException;
Expand Down Expand Up @@ -46,8 +48,14 @@ public class App {
static Baptisterio baptisterio = new Baptisterio();

public static void main(String[] args) throws Exception {
///////////////////////auth creation

AuthSystem auth= new AuthSystem();
User logged= auth.run();

/////////////////////
System.out.print("¿¿¿A quién no le va a gustar un buen baptisterio???");

System.out.println("HOLA "+logged.getUserName());
var option = MenuOptions.NOOP;
Scanner scan = new Scanner(System.in);
Exception error = null;
Expand Down Expand Up @@ -80,9 +88,10 @@ public static void main(String[] args) throws Exception {
}

switch (option) {

case BOOK -> {
try {
book(scan);
book(scan,logged);
}
catch (DateTimeException e) {
error = e;
Expand All @@ -91,7 +100,7 @@ public static void main(String[] args) throws Exception {
error = e;
}
}
case CANCEL -> cancel(scan);
case CANCEL -> cancel(scan,logged);
case EXIT -> System.out.println("¡Hasta luego!");
case LIST -> baptisterio.printReservations();
case NOOP -> {}
Expand All @@ -118,21 +127,21 @@ private static LocalDateWrapper readDate(Scanner scan) throws DateTimeException{
}


private static User readUser(Scanner scan){
System.out.println("¿Cuál es tu nombre?");
System.out.print("> ");
String name = scan.nextLine();

System.out.println("¿Cuál es tu DNI?");
System.out.print("> ");
String dni = scan.nextLine();

User user = new User(name, dni);
return user;
}
// private static User readUser(Scanner scan){
// System.out.println("¿Cuál es tu nombre?");
// System.out.print("> ");
// String name = scan.nextLine();
//
// System.out.println("¿Cuál es tu DNI?");
// System.out.print("> ");
// String dni = scan.nextLine();
//
// User user = new User(name, dni);
// return user;
// }


private static void book (Scanner scan) throws Exception, DateTimeException {
private static void book (Scanner scan, User logged) throws Exception, DateTimeException {
LocalDateWrapper date = null;

try {
Expand All @@ -149,8 +158,9 @@ private static void book (Scanner scan) throws Exception, DateTimeException {
throw new Exception("La fecha introducida no está disponible");
}

User user = readUser(scan);

//User user = readUser(scan);
User user=logged;

int round = 0;
int remaining = baptisterio.PRICE;
ArrayList<CoinEuro> coins = new ArrayList<CoinEuro>();
Expand Down Expand Up @@ -182,7 +192,7 @@ private static void book (Scanner scan) throws Exception, DateTimeException {
Thread.sleep(2000);
}

private static void cancel (Scanner scan) throws InterruptedException {
private static void cancel (Scanner scan, User logged) throws InterruptedException {
LocalDateWrapper date = null;

try {
Expand All @@ -192,7 +202,8 @@ private static void cancel (Scanner scan) throws InterruptedException {
throw e;
}

User user = readUser(scan);
//User user = readUser(scan);
User user = logged;

if (baptisterio.cancel(user, date)) {
System.out.println("Su cita se ha cancelado con éxito!");
Expand Down
102 changes: 102 additions & 0 deletions src/main/java/com/curso/baptisterio/java/AuthSystem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package com.curso.baptisterio.java;

import static com.curso.baptisterio.java.Constants.*;

/**
*
* @author dpadilla
*/
public class AuthSystem {

UserInterface ui;
DB db;
User loggedU;
boolean loggedCorrect;

public AuthSystem() {
ui = new UserInterface();
db = new DB(FILEDATABASE);
loggedCorrect = false;
}

public User run() {
boolean exit = false;
int option = DEFAULTOPTION;
db.start();

while (!exit) {
System.out.println(MENU);
option = ui.show();

switch (option) {
case LOGIN:
login();
break;
case REGISTER:
register();
break;
default:
System.out.println("Invalid option");
}

if (loggedCorrect) {
exit = true;
}

}
return loggedU;

}

private void register() {
User user = null;
boolean canRegister = false;

while (!canRegister) {
user = ui.askName();
if (!db.exist(user)) {
canRegister = true;
} else {
System.out.println("User already taken");
}
}
user.setDni(ui.askDNI());
user.setPass(ui.askPasword());

db.add(user);

System.out.println("Register succesfull");
}

private void login() {
User user = null;
boolean canLogin = false;
boolean correct = true;
String pasword;

user = ui.askName();
if (!db.exist(user)) {
correct = false;
}

pasword = ui.askPasword();

if (correct) {
correct = db.check(user, pasword);
}

if (correct) {
loggedU = db.getUser(user.getUserName());
System.out.println(USERWELCOME);
loggedCorrect = true;
} else {
System.out.println(USERERROR);
}

}

}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
package com.curso.baptisterio.java;
import java.util.ArrayList;
import java.util.HashMap;

Expand Down Expand Up @@ -53,7 +54,7 @@ public void printReservations() {

for (var date : reservations.keySet()) {
System.out.println(date + " -> "
+ reservations.get(date).getName()
+ reservations.get(date).getUserName()
+ " ("+reservations.get(date).getDni() + ")"
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
package com.curso.baptisterio.java;
import java.util.ArrayList;

public enum CoinEuro { // En céntimos
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/com/curso/baptisterio/java/Constants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package com.curso.baptisterio.java;

/**
*
* @author dpadilla
*/
public class Constants {
public static final String SEPARE = "|";
public static final String FILEDATABASE = "filedbejer4";
public static final String MENU = "1-> Login\n2-> Register\n";
public static final String USERERROR = "User or pasword not correct";
public static final String USERWELCOME = "You have been logged correctly =D";
public static final int DEFAULTOPTION = 0;
public static final int LOGIN = 1;
public static final int REGISTER = 2;
public static final int EXIT = 3;
}
Loading