changes to use service from escolares
This commit is contained in:
@@ -48,6 +48,12 @@
|
||||
<groupId>org.postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>8.0.28</version>
|
||||
</dependency>
|
||||
<!-- JSON dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.json</groupId>
|
||||
|
||||
@@ -10,10 +10,7 @@ import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.MapsId;
|
||||
import javax.persistence.OneToOne;
|
||||
import javax.validation.constraints.Email;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Pattern;
|
||||
import javax.validation.constraints.Size;
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
@Entity
|
||||
@Data
|
||||
@@ -32,6 +29,9 @@ public class Student {
|
||||
@Email
|
||||
private String email;
|
||||
|
||||
@NotBlank
|
||||
private String name = "Nuevo Usuario";
|
||||
|
||||
@OneToOne
|
||||
@NotNull
|
||||
private Career codeCareer = new Career((long) 0, "New Student", (long) 1);
|
||||
@@ -55,10 +55,11 @@ public class Student {
|
||||
|
||||
private Boolean infected = false;
|
||||
|
||||
public Student(AuthUser user, Career career) {
|
||||
public Student(AuthUser user, Career career, String name) {
|
||||
this.id = user.getId();
|
||||
this.user = user;
|
||||
this.codeCareer = career;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -66,9 +66,16 @@ public class SicknesService {
|
||||
}
|
||||
|
||||
public List<Evolution> evolutions(String noCta) {
|
||||
LocalDateTime today = LocalDateTime.now();
|
||||
final LocalDateTime[] lastDay = {LocalDateTime.now()};
|
||||
final Boolean[] firstTime = {true};
|
||||
return evolutionRepository.findAll().stream().filter(evolution -> evolution.getStudent().getUser().getUsername().equals(noCta)).
|
||||
filter(evolution -> evolution.getDateTime().isAfter(today.minusDays(1))).collect(Collectors.toList());
|
||||
filter(evolution -> {
|
||||
if(firstTime[0]){
|
||||
lastDay[0] = evolution.getDateTime().minusDays(1);
|
||||
firstTime[0] = false;
|
||||
}
|
||||
return evolution.getDateTime().isAfter(lastDay[0]);
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,8 @@ public class UserService {
|
||||
private ManageService manageService;
|
||||
|
||||
@Transactional
|
||||
public CreateUserResponse create(SingUpUserRequest signUpRequest, String roleNames) {
|
||||
public CreateUserResponse create(SingUpUserRequest signUpRequest, String roleNames, String name) {
|
||||
name = name.substring(2);
|
||||
CreateUserRequest createUserRequest = CreateUserRequest.builder()
|
||||
.username(signUpRequest.getCuenta())
|
||||
.password(signUpRequest.getPassword())
|
||||
@@ -42,7 +43,7 @@ public class UserService {
|
||||
Career career = manageService.getCareer(signUpRequest.getCarer());
|
||||
if (createUserResponse.isSuccess()) {
|
||||
AuthUser authUser = authService.getUser(signUpRequest.getCuenta());
|
||||
Student student = new Student(authUser, career);
|
||||
Student student = new Student(authUser, career, name);
|
||||
studentRepository.save(student);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import javax.validation.Valid;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.sql.*;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@@ -38,15 +39,14 @@ public class LoginController {
|
||||
|
||||
@PostMapping("/sign-up")
|
||||
public ResponseEntity<?> signUp(@Valid @RequestBody SingUpUserRequest signUpRequest) {
|
||||
int role;
|
||||
if (signUpRequest.getCuenta().length() < 9) {
|
||||
role = 1;
|
||||
} else {
|
||||
role = 0;
|
||||
}
|
||||
System.out.println(RoleName.list().get(role));
|
||||
if (!authService.userExists(signUpRequest.getCuenta())) {
|
||||
CreateUserResponse createUserResponse = userService.create(signUpRequest, RoleName.list().get(role));
|
||||
|
||||
if (!authService.userExists(signUpRequest.getCuenta()) && signUpRequest.getCuenta().length() == 9 ) {
|
||||
String name[] = verifyStudent(signUpRequest.getCuenta(), signUpRequest.getPassword(), signUpRequest.getCarer());
|
||||
if(name[0].equalsIgnoreCase("no")){
|
||||
return ResponseEntity.status(HttpStatus.FORBIDDEN)
|
||||
.body("Error en las credenciales de usuario");
|
||||
}
|
||||
CreateUserResponse createUserResponse = userService.create(signUpRequest, RoleName.ROLE_USER, name[2]);
|
||||
|
||||
if (createUserResponse.isSuccess()) {
|
||||
GenerateTokenRequest tokenRequest = new GenerateTokenRequest(signUpRequest.getCuenta(),
|
||||
@@ -110,4 +110,37 @@ public class LoginController {
|
||||
return bytes;
|
||||
}
|
||||
|
||||
private String[] verifyStudent(String noCta, String password, Long career) {
|
||||
try {
|
||||
//Getting the connection
|
||||
String mysqlUrl = "jdbc:mysql://132.248.80.95:3306/historias?noAccessToProcedureBodies=true";
|
||||
Connection con = DriverManager.getConnection(mysqlUrl, "CovidMac", "LeBA5eT6ru");
|
||||
System.out.println("Revisando inscripción de usuario: " + noCta);
|
||||
//Preparing a CallableStatement to call a function
|
||||
CallableStatement cstmt = con.prepareCall("{CALL busca_alumno_covid(?,?,?)}");
|
||||
//Registering the out parameter of the function (return type)
|
||||
//Setting the input parameters of the function
|
||||
cstmt.setString(1, noCta);
|
||||
cstmt.setString(2, password);
|
||||
cstmt.setString(3, career.toString() );
|
||||
//Executing the statement
|
||||
ResultSet rs = cstmt.executeQuery();
|
||||
String alumnoString[] = new String[3];
|
||||
while (rs.next()) {
|
||||
alumnoString[0] = rs.getString("Alumno");
|
||||
alumnoString[1] = rs.getString("inscrito");
|
||||
alumnoString[2] = rs.getString("nombre");
|
||||
|
||||
System.out.println(alumnoString[0] + " " + alumnoString[1]);
|
||||
}
|
||||
con.close();
|
||||
return alumnoString;
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
String[] message = new String[1];
|
||||
message[0] = e.getMessage();
|
||||
return message;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user