mirror of
https://github.com/st-tu-dresden-praktikum/swt23w23
synced 2024-07-19 21:04:36 +02:00
Simplifiy user id
This commit is contained in:
parent
317af597f5
commit
3ecdcffbcd
|
@ -4,8 +4,6 @@ import jakarta.persistence.Entity;
|
||||||
import jakarta.persistence.GeneratedValue;
|
import jakarta.persistence.GeneratedValue;
|
||||||
import jakarta.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
|
|
||||||
import org.springframework.data.domain.AbstractAggregateRoot;
|
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
public class Staff {
|
public class Staff {
|
||||||
|
|
||||||
|
|
|
@ -1,23 +1,18 @@
|
||||||
package catering.users;
|
package catering.users;
|
||||||
|
|
||||||
import jakarta.persistence.Embeddable;
|
|
||||||
import jakarta.persistence.EmbeddedId;
|
|
||||||
import jakarta.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.GeneratedValue;
|
||||||
|
import jakarta.persistence.Id;
|
||||||
import jakarta.persistence.OneToOne;
|
import jakarta.persistence.OneToOne;
|
||||||
|
|
||||||
|
import org.salespointframework.core.AbstractAggregateRoot;
|
||||||
import org.salespointframework.useraccount.Role;
|
import org.salespointframework.useraccount.Role;
|
||||||
import org.salespointframework.useraccount.UserAccount;
|
import org.salespointframework.useraccount.UserAccount;
|
||||||
import org.salespointframework.core.AbstractAggregateRoot;
|
|
||||||
|
|
||||||
import catering.users.User.UserIdentifier;
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.UUID;
|
|
||||||
import org.jmolecules.ddd.types.Identifier;
|
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
public class User extends AbstractAggregateRoot<UserIdentifier> {
|
public class User {
|
||||||
|
|
||||||
private @EmbeddedId UserIdentifier id = new UserIdentifier();
|
private @Id @GeneratedValue Long id;
|
||||||
private String address, fullName;
|
private String address, fullName;
|
||||||
|
|
||||||
@OneToOne
|
@OneToOne
|
||||||
|
@ -65,8 +60,7 @@ public class User extends AbstractAggregateRoot<UserIdentifier> {
|
||||||
return this.userAccount;
|
return this.userAccount;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public Long getId() {
|
||||||
public UserIdentifier getId() {
|
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,50 +71,4 @@ public class User extends AbstractAggregateRoot<UserIdentifier> {
|
||||||
public boolean hasRole(String role) {
|
public boolean hasRole(String role) {
|
||||||
return userAccount.getRoles().stream().toList().contains(Role.of(role));
|
return userAccount.getRoles().stream().toList().contains(Role.of(role));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Embeddable
|
|
||||||
public static final class UserIdentifier implements Identifier, Serializable {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 7740660930809051850L;
|
|
||||||
private final UUID identifier;
|
|
||||||
|
|
||||||
UserIdentifier() {
|
|
||||||
this(UUID.randomUUID());
|
|
||||||
}
|
|
||||||
|
|
||||||
UserIdentifier(UUID identifier) {
|
|
||||||
this.identifier = identifier;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
|
|
||||||
final int prime = 31;
|
|
||||||
int result = 1;
|
|
||||||
|
|
||||||
result = prime * result + (identifier == null ? 0 : identifier.hashCode());
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object obj) {
|
|
||||||
|
|
||||||
if (obj == this) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(obj instanceof UserIdentifier that)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.identifier.equals(that.identifier);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString(){
|
|
||||||
return identifier.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
package catering.users;
|
package catering.users;
|
||||||
|
|
||||||
import catering.users.User.UserIdentifier;
|
|
||||||
import org.springframework.data.repository.CrudRepository;
|
import org.springframework.data.repository.CrudRepository;
|
||||||
import org.springframework.data.util.Streamable;
|
import org.springframework.data.util.Streamable;
|
||||||
|
|
||||||
interface UserRepository extends CrudRepository<User, UserIdentifier> {
|
interface UserRepository extends CrudRepository<User, Long> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
Streamable<User> findAll();
|
Streamable<User> findAll();
|
||||||
|
|
Loading…
Reference in a new issue