diff --git a/src/main/java/cat/udl/eps/softarch/demo/domain/Student.java b/src/main/java/cat/udl/eps/softarch/demo/domain/Student.java new file mode 100644 index 0000000..366a56f --- /dev/null +++ b/src/main/java/cat/udl/eps/softarch/demo/domain/Student.java @@ -0,0 +1,25 @@ +package cat.udl.eps.softarch.demo.domain; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +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 Student extends User { + + @NotEmpty + private String phoneNumber; + + @NotEmpty + private String name; + +} \ No newline at end of file diff --git a/src/main/java/cat/udl/eps/softarch/demo/domain/User.java b/src/main/java/cat/udl/eps/softarch/demo/domain/User.java index f6adb2e..1456d8b 100644 --- a/src/main/java/cat/udl/eps/softarch/demo/domain/User.java +++ b/src/main/java/cat/udl/eps/softarch/demo/domain/User.java @@ -55,6 +55,9 @@ public void encodePassword() { @JsonValue(value = false) @JsonProperty(access = JsonProperty.Access.READ_ONLY) public Collection getAuthorities() { + if (this instanceof Student) { + return AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_STUDENT"); + } return AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_USER"); } diff --git a/src/main/java/cat/udl/eps/softarch/demo/repository/StudentRepository.java b/src/main/java/cat/udl/eps/softarch/demo/repository/StudentRepository.java new file mode 100644 index 0000000..057bde1 --- /dev/null +++ b/src/main/java/cat/udl/eps/softarch/demo/repository/StudentRepository.java @@ -0,0 +1,7 @@ +package cat.udl.eps.softarch.demo.repository; + +import cat.udl.eps.softarch.demo.domain.Student; +import org.springframework.data.repository.CrudRepository; + +public interface StudentRepository extends CrudRepository { +}