Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/user #19

Merged
merged 6 commits into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from 4 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
22 changes: 22 additions & 0 deletions src/main/java/cat/udl/eps/softarch/tfgfinder/domain/Admin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package cat.udl.eps.softarch.tfgfinder.domain;
import jakarta.persistence.ElementCollection;
import jakarta.persistence.Entity;
import jakarta.validation.constraints.NotEmpty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.AuthorityUtils;

import java.util.Collection;

@Entity
@Data
@EqualsAndHashCode(callSuper = true)
public class Admin extends User{

@Override
@ElementCollection
public Collection<GrantedAuthority> getAuthorities() {
return AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_ADMIN");
}
}
27 changes: 27 additions & 0 deletions src/main/java/cat/udl/eps/softarch/tfgfinder/domain/Director.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package cat.udl.eps.softarch.tfgfinder.domain;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonValue;
import jakarta.persistence.ElementCollection;
import jakarta.persistence.Entity;
import jakarta.validation.constraints.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.AuthorityUtils;

import java.util.Collection;

@Entity
@Data
@EqualsAndHashCode(callSuper = true)
public class Director extends User {

@NotNull(message = "La disponibilidad no puede ser nula")
private Boolean available = true;

@Override
@ElementCollection
public Collection<GrantedAuthority> getAuthorities() {
return AuthorityUtils.createAuthorityList("ROLE_DIRECTOR");
}
}
58 changes: 58 additions & 0 deletions src/main/java/cat/udl/eps/softarch/tfgfinder/domain/External.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package cat.udl.eps.softarch.tfgfinder.domain;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonValue;
import jakarta.persistence.ElementCollection;
import jakarta.persistence.Entity;
import jakarta.validation.constraints.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.AuthorityUtils;

import java.util.Collection;



@Entity
@Data
@EqualsAndHashCode(callSuper = true)
public class External extends Director {

@NotEmpty
@Size(min = 2, max = 50, message = "El nombre debe tener entre 2 y 50 caracteres")
private String name;

@NotEmpty
@Size(min = 2, max = 50, message = "El apellido debe tener entre 2 y 50 caracteres")
private String surname;

@NotEmpty
@Size(min = 2, max = 100, message = "El cargo debe tener entre 2 y 100 caracteres")
private String position;

@NotEmpty
@Size(min = 2, max = 100, message = "La organización debe tener entre 2 y 100 caracteres")
private String organization;

@NotEmpty
@Size(min = 5, max = 100, message = "La dirección debe tener entre 5 y 100 caracteres")
private String address;

@NotEmpty
@Size(min = 2, max = 50, message = "El municipio debe tener entre 2 y 50 caracteres")
private String municipality;

@NotEmpty
@Pattern(regexp = "^[0-9]{5}$", message = "El código postal debe contener exactamente 5 dígitos")
private String postalCode;

@NotEmpty
@Pattern(regexp = "^[0-9]{9}$", message = "El número de teléfono debe contener exactamente 9 dígitos")
private String phoneNumber;

@Override
@ElementCollection
public Collection<GrantedAuthority> getAuthorities() {
return AuthorityUtils.createAuthorityList("ROLE_EXTERNAL");
}
}
40 changes: 40 additions & 0 deletions src/main/java/cat/udl/eps/softarch/tfgfinder/domain/Professor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package cat.udl.eps.softarch.tfgfinder.domain;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonValue;
import jakarta.persistence.ElementCollection;
import jakarta.persistence.Entity;
import jakarta.validation.constraints.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.AuthorityUtils;

import java.util.Collection;

@Entity
@Data
@EqualsAndHashCode(callSuper = true)
public class Professor extends Director {

@NotEmpty
@Size(min = 2, max = 100, message = "La facultad debe tener entre 2 y 100 caracteres")
private String faculty;

@NotEmpty
@Size(min = 2, max = 100, message = "El departamento debe tener entre 2 y 100 caracteres")
private String department;

@NotEmpty
@Size(min = 2, max = 50, message = "El nombre debe tener entre 2 y 50 caracteres")
private String name;

@NotEmpty
@Size(min = 2, max = 50, message = "El apellido debe tener entre 2 y 50 caracteres")
private String surname;

@Override
@ElementCollection
public Collection<GrantedAuthority> getAuthorities() {
return AuthorityUtils.createAuthorityList("ROLE_PROFESSOR");
}
}
56 changes: 56 additions & 0 deletions src/main/java/cat/udl/eps/softarch/tfgfinder/domain/Student.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package cat.udl.eps.softarch.tfgfinder.domain;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonValue;
import jakarta.persistence.ElementCollection;
import jakarta.persistence.Entity;
import jakarta.validation.constraints.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.AuthorityUtils;

import java.util.Collection;

@Entity
@Data
@EqualsAndHashCode(callSuper = true)
public class Student extends User {

@NotEmpty
@Size(min = 2, max = 50, message = "El nombre debe tener entre 2 y 50 caracteres")
private String name;

@NotEmpty
@Size(min = 2, max = 50, message = "El apellido debe tener entre 2 y 50 caracteres")
private String surname;

@NotEmpty
@Pattern(regexp = "^[0-9]{8}[A-Za-z]$", message = "El DNI debe tener 8 números seguidos de una letra")
private String DNI;

@NotEmpty
@Size(min = 5, max = 100, message = "La dirección debe tener entre 5 y 100 caracteres")
private String address;

@NotEmpty
@Size(min = 2, max = 50, message = "El municipio debe tener entre 2 y 50 caracteres")
private String municipality;

@NotEmpty
@Pattern(regexp = "^[0-9]{5}$", message = "El código postal debe contener exactamente 5 dígitos")
private String postalCode;

@NotEmpty
@Pattern(regexp = "^[0-9]{9}$", message = "El número de teléfono debe contener exactamente 9 dígitos")
private String phoneNumber;

@NotEmpty
@Size(min = 2, max = 100, message = "El nombre del grado debe tener entre 2 y 100 caracteres")
private String degree;

@Override
@ElementCollection
public Collection<GrantedAuthority> getAuthorities(){
return AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_STUDENT");
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package cat.udl.eps.softarch.tfgfinder.domain;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;

import jakarta.persistence.*;
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotBlank;

import com.fasterxml.jackson.annotation.JsonValue;
import jakarta.validation.constraints.NotEmpty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.validator.constraints.Length;
Expand All @@ -27,7 +29,7 @@ public class User extends UriEntity<String> implements UserDetails {
public static PasswordEncoder passwordEncoder = new BCryptPasswordEncoder();

@Id
private String id;
private String id; //username?

@NotBlank
@Email
Expand All @@ -42,6 +44,8 @@ public class User extends UriEntity<String> implements UserDetails {
@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
private boolean passwordReset;

//Faltarà crear favourites per la llista de propostes favorites

public void encodePassword() {
this.password = passwordEncoder.encode(this.password);
}
Expand Down