diff --git a/src/main/java/cat/udl/eps/softarch/demo/domain/Client.java b/src/main/java/cat/udl/eps/softarch/demo/domain/Client.java new file mode 100644 index 00000000..55cd6d47 --- /dev/null +++ b/src/main/java/cat/udl/eps/softarch/demo/domain/Client.java @@ -0,0 +1,21 @@ +package cat.udl.eps.softarch.demo.domain; + +import jakarta.persistence.ElementCollection; +import jakarta.persistence.Entity; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.authority.AuthorityUtils; + +import java.util.Collection; + +@EqualsAndHashCode(callSuper = true) +@Entity +@Data +public class Client extends User { + @Override + @ElementCollection + public Collection getAuthorities(){ + return AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_CLIENT"); + } +} diff --git a/src/main/java/cat/udl/eps/softarch/demo/domain/Location.java b/src/main/java/cat/udl/eps/softarch/demo/domain/Location.java deleted file mode 100644 index c4773b14..00000000 --- a/src/main/java/cat/udl/eps/softarch/demo/domain/Location.java +++ /dev/null @@ -1,30 +0,0 @@ -package cat.udl.eps.softarch.demo.domain; - -import jakarta.persistence.Entity; -import jakarta.persistence.Id; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -@Entity -@Data -@NoArgsConstructor -@AllArgsConstructor - -public class Location extends UriEntity{ - @Id - private Long id; - - private String address; - - private float latitude; - - private float longitude; - - private String province; - - private String municipality; - - private String postalCode; - -} diff --git a/src/main/java/cat/udl/eps/softarch/demo/repository/ClientRepository.java b/src/main/java/cat/udl/eps/softarch/demo/repository/ClientRepository.java new file mode 100644 index 00000000..c4afb86d --- /dev/null +++ b/src/main/java/cat/udl/eps/softarch/demo/repository/ClientRepository.java @@ -0,0 +1,26 @@ +package cat.udl.eps.softarch.demo.repository; + +import cat.udl.eps.softarch.demo.domain.Client; +import cat.udl.eps.softarch.demo.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 ClientRepository extends CrudRepository, PagingAndSortingRepository { + + /* Interface provides automatically, as defined in + * https://docs.spring.io/spring-data/commons/docs/current/api/org/springframework/data/repository/CrudRepository.html + * and + * https://docs.spring.io/spring-data/commons/docs/current/api/org/springframework/data/repository/PagingAndSortingRepository.html + * the methods: count, delete, deleteAll, deleteById, existsById, findAll, findAllById, findById, save, saveAll,... + * + * Additional methods like findByUsernameContaining can be defined following: + * https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#jpa.query-methods.query-creation + */ + + List findByIdContaining(@Param("text") String text); +}