Add fields to user entity.
This commit is contained in:
@@ -51,6 +51,11 @@ public class UserJpaAdapter implements UserPort {
|
||||
return userJpaRepository.existsById(userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean existsByEmail(String email) {
|
||||
return userJpaRepository.existsByEmail(email);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<RefreshToken> findRefreshTokenByUserId(UUID userId) {
|
||||
return refreshTokenJpaRepository.findByUserId(userId)
|
||||
|
||||
@@ -27,10 +27,14 @@ import lombok.Setter;
|
||||
public class UserEntity {
|
||||
@Id
|
||||
private UUID id;
|
||||
|
||||
@Column(nullable = false)
|
||||
private String pseudo;
|
||||
@Column(nullable = false)
|
||||
private String email;
|
||||
@Column(nullable = false)
|
||||
private String password;
|
||||
|
||||
@Column
|
||||
private UUID photoId;
|
||||
@ElementCollection(targetClass = UserRole.class)
|
||||
@CollectionTable(
|
||||
name = "user_role",
|
||||
@@ -41,14 +45,20 @@ public class UserEntity {
|
||||
|
||||
public UserEntity(User user) {
|
||||
id = user.id();
|
||||
pseudo = user.pseudo();
|
||||
email = user.email();
|
||||
password = user.password();
|
||||
photoId = user.photoId();
|
||||
roles = user.roles();
|
||||
}
|
||||
|
||||
public User toUser() {
|
||||
return new User(
|
||||
id,
|
||||
pseudo,
|
||||
email,
|
||||
password,
|
||||
photoId,
|
||||
roles
|
||||
);
|
||||
}
|
||||
|
||||
@@ -17,4 +17,6 @@ public interface UserJpaRepository extends JpaRepository<UserEntity, UUID> {
|
||||
|
||||
@Query("SELECT u FROM UserEntity u JOIN FETCH u.roles")
|
||||
List<UserEntity> findAll();
|
||||
|
||||
boolean existsByEmail(String email);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
insert into "user" values
|
||||
('5ad462b8-8f9e-4a26-bb86-c74fef5d11b6', 'Standard user', 'standard.user@codiki.org', '$2a$10$FVhrYRXw.Zw2V5jGUkvX/.1U.IdWlwd8J.Y/5pb5etAzyoBhJ3FHG', null),
|
||||
('15a13dc7-029d-4eab-a63d-c1e96f90241d', 'Admin user', 'admin.user@codiki.org', '$2a$10$FVhrYRXw.Zw2V5jGUkvX/.1U.IdWlwd8J.Y/5pb5etAzyoBhJ3FHG', null);
|
||||
|
||||
insert into user_role values
|
||||
('5ad462b8-8f9e-4a26-bb86-c74fef5d11b6', 0),
|
||||
('15a13dc7-029d-4eab-a63d-c1e96f90241d', 0),
|
||||
('15a13dc7-029d-4eab-a63d-c1e96f90241d', 1);
|
||||
|
||||
insert into category values
|
||||
('172fa901-3f4b-4540-92f3-1c15820e8ec9', 'Main category', null),
|
||||
('3f4b4540-a901-92f3-1c15-8ec9172f820e', 'Sub category', '172fa901-3f4b-4540-92f3-1c15820e8ec9');
|
||||
@@ -1,7 +1,9 @@
|
||||
CREATE TABLE IF NOT EXISTS "user" (
|
||||
id UUID NOT NULL,
|
||||
name VARCHAR NOT NULL,
|
||||
pseudo VARCHAR NOT NULL,
|
||||
email VARCHAR NOT NULL,
|
||||
password VARCHAR NOT NULL,
|
||||
photo_id UUID,
|
||||
CONSTRAINT user_pk PRIMARY KEY (id)
|
||||
);
|
||||
|
||||
@@ -39,6 +41,9 @@ CREATE TABLE IF NOT EXISTS picture (
|
||||
);
|
||||
CREATE INDEX picture_publisher_id_idx ON picture (publisher_id);
|
||||
|
||||
ALTER TABLE "user" ADD CONSTRAINT user_photo_id_fk FOREIGN KEY (photo_id) REFERENCES picture (id);
|
||||
CREATE INDEX user_photo_id_idx ON "user" (photo_id);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS publication (
|
||||
id UUID NOT NULL,
|
||||
key VARCHAR(10) NOT NULL,
|
||||
|
||||
Reference in New Issue
Block a user