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 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
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");
}
}
28 changes: 28 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,28 @@
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 = "Availability cannot be null")
private Boolean available = true;

@Override
@ElementCollection
public Collection<GrantedAuthority> getAuthorities() {
return AuthorityUtils.createAuthorityList("ROLE_DIRECTOR");
}
}
57 changes: 57 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,57 @@
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 = "The first name must be between 2 and 50 characters")
private String name;

@NotEmpty
@Size(min = 2, max = 50, message = "The last name must be between 2 and 50 characters")
private String surname;

@NotEmpty
@Size(min = 2, max = 100, message = "The position must be between 2 and 100 characters")
private String position;

@NotEmpty
@Size(min = 2, max = 100, message = "The organization must be between 2 and 100 characters")
private String organization;

@NotEmpty
@Size(min = 5, max = 100, message = "The address must be between 5 and 100 characters")
private String address;

@NotEmpty
@Size(min = 2, max = 50, message = "The municipality must be between 2 and 50 characters")
private String municipality;

@NotEmpty
@Pattern(regexp = "^[0-9]{5}$", message = "The postal code must contain exactly 5 digits")
private String postalCode;

@NotEmpty
@Pattern(regexp = "^[0-9]{9}$", message = "The phone number must contain exactly 9 digits")
private String phoneNumber;

@Override
@ElementCollection
public Collection<GrantedAuthority> getAuthorities() {
return AuthorityUtils.createAuthorityList("ROLE_EXTERNAL");
}
}
41 changes: 41 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,41 @@
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 = "The faculty name must be between 2 and 100 characters")
private String faculty;

@NotEmpty
@Size(min = 2, max = 100, message = "The department name must be between 2 and 100 characters")
private String department;

@NotEmpty
@Size(min = 2, max = 50, message = "The first name must be between 2 and 50 characters")
private String name;

@NotEmpty
@Size(min = 2, max = 50, message = "The last name must be between 2 and 50 characters")
private String surname;

@Override
@ElementCollection
public Collection<GrantedAuthority> getAuthorities() {
return AuthorityUtils.createAuthorityList("ROLE_PROFESSOR");
}
}
57 changes: 57 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,57 @@
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 = "The name must be between 2 and 50 characters long")
private String name;

@NotEmpty
@Size(min = 2, max = 50, message = "The surname must be between 2 and 50 characters long")
private String surname;

@NotEmpty
@Pattern(regexp = "^[0-9]{8}[A-Za-z]$", message = "The DNI must have 8 digits followed by a letter")
private String DNI;

@NotEmpty
@Size(min = 5, max = 100, message = "The address must be between 5 and 100 characters long")
private String address;

@NotEmpty
@Size(min = 2, max = 50, message = "The municipality must be between 2 and 50 characters long")
private String municipality;

@NotEmpty
@Pattern(regexp = "^[0-9]{5}$", message = "The postal code must contain exactly 5 digits")
private String postalCode;

@NotEmpty
@Pattern(regexp = "^[0-9]{9}$", message = "The phone number must contain exactly 9 digits")
private String phoneNumber;

@NotEmpty
@Size(min = 2, max = 100, message = "The degree name must be between 2 and 100 characters long")
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;

// Favourites for the list of favorite proposals still has to be created.

public void encodePassword() {
this.password = passwordEncoder.encode(this.password);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package cat.udl.eps.softarch.tfgfinder.repository;

import cat.udl.eps.softarch.tfgfinder.domain.Admin;
import cat.udl.eps.softarch.tfgfinder.domain.User;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;

import java.util.List;

@RepositoryRestResource
public interface AdminRepository extends CrudRepository<Admin, String>, PagingAndSortingRepository<Admin, String> {
List<User> findByIdContaining(@Param("text") String text);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package cat.udl.eps.softarch.tfgfinder.repository;

import cat.udl.eps.softarch.tfgfinder.domain.Director;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;

import java.util.List;

@RepositoryRestResource
public interface DirectorRepository extends CrudRepository<Director, String>, PagingAndSortingRepository<Director, String> {
List<Director> findByAvailable(@Param("available") Boolean available);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package cat.udl.eps.softarch.tfgfinder.repository;


import cat.udl.eps.softarch.tfgfinder.domain.External;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;

import java.util.List;

@RepositoryRestResource
public interface ExternalRepository extends CrudRepository<External, String>, PagingAndSortingRepository<External, String> {
List<External> findByOrganizationContaining(@Param("organization") String organization);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package cat.udl.eps.softarch.tfgfinder.repository;


import cat.udl.eps.softarch.tfgfinder.domain.Professor;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;

import java.util.List;

@RepositoryRestResource
public interface ProfessorRepository extends CrudRepository<Professor, String>, PagingAndSortingRepository<Professor, String> {
List<Professor> findByDepartmentContaining(@Param("department") String department);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package cat.udl.eps.softarch.tfgfinder.repository;

import cat.udl.eps.softarch.tfgfinder.domain.Student;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;

import java.util.List;

@RepositoryRestResource
public interface StudentRepository extends CrudRepository<Student, String>, PagingAndSortingRepository<Student, String> {
List<Student> findByNameContaining(@Param("name") String name);
}