Skip to content

Commit

Permalink
feat(user): started adding new user interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
zZHorizonZz committed Aug 25, 2024
1 parent 51887f2 commit fce11ce
Show file tree
Hide file tree
Showing 12 changed files with 184 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
import dev.cloudeko.zenei.extension.core.model.user.UserPassword;
import dev.cloudeko.zenei.extension.core.repository.UserPasswordRepository;
import dev.cloudeko.zenei.extension.core.repository.UserRepository;
import dev.cloudeko.zenei.user.BasicUserAccount;
import dev.cloudeko.zenei.user.runtime.DefaultUserAccount;
import dev.cloudeko.zenei.user.runtime.DefaultUserAccountManager;
import dev.cloudeko.zenei.user.runtime.DefaultUserAccountReactiveProvider;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.transaction.Transactional;
import lombok.AllArgsConstructor;
Expand All @@ -36,7 +35,7 @@ public class CreateUserImpl implements CreateUser {
private final UserRepository userRepository;
private final UserPasswordRepository userPasswordRepository;

private final DefaultUserAccountManager userAccountManager;
private final DefaultUserAccountReactiveProvider userAccountManager;

@Override
@Transactional
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package dev.cloudeko.zenei.user.deployment;

import dev.cloudeko.zenei.user.runtime.DefaultUserAccountInitializer;
import dev.cloudeko.zenei.user.runtime.DefaultUserAccountManager;
import dev.cloudeko.zenei.user.runtime.DefaultUserAccountReactiveProvider;
import dev.cloudeko.zenei.user.runtime.DefaultUserAccountRecorder;
import dev.cloudeko.zenei.user.runtime.DefaultUserAccountRepository;
import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
Expand Down Expand Up @@ -80,7 +80,7 @@ AdditionalBeanBuildItem setupBeans() {

@BuildStep
AdditionalBeanBuildItem setupManager() {
return new AdditionalBeanBuildItem(DefaultUserAccountManager.class);
return new AdditionalBeanBuildItem(DefaultUserAccountReactiveProvider.class);
}

private static final class ReactiveClientBuildItem extends SimpleBuildItem {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package dev.cloudeko.zenei.user;

import io.smallrye.mutiny.Uni;

import java.util.List;

public interface EmailAddressReactiveProvider<ENTITY extends UserAccount<ID>, ID> {

Uni<List<EmailAddress>> listEmailAddresses(ID id);

Uni<EmailAddress> getEmailAddress(ID id, String emailAddress);

Uni<EmailAddress> addEmailAddress(ID id, EmailAddress emailAddress);

Uni<EmailAddress> updateEmailAddress(ID id, EmailAddress emailAddress);

Uni<Void> removeEmailAddress(ID id, String emailAddress);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package dev.cloudeko.zenei.user;

public interface PhoneNumberManager {

}
Original file line number Diff line number Diff line change
@@ -1,47 +1,37 @@
package dev.cloudeko.zenei.user;

import java.time.LocalDateTime;
import java.util.List;

public abstract class UserAccount<ID> {
public abstract interface UserAccount<ID> {

private ID id;
private LocalDateTime createdAt;
private LocalDateTime updatedAt;
ID getId();

public UserAccount() {
}
String getUsername();

public UserAccount(ID id) {
this(id, null, null);
}
void setUsername(String username);

public UserAccount(ID id, LocalDateTime createdAt, LocalDateTime updatedAt) {
this.id = id;
this.createdAt = createdAt;
this.updatedAt = updatedAt;
default EmailAddress getPrimaryEmailAddress() {
return getEmailAddresses().stream().filter(EmailAddress::isPrimaryEmail).findFirst().orElse(null);
}

public ID getId() {
return id;
}
List<EmailAddress> getEmailAddresses();

public void setId(ID id) {
this.id = id;
}
void setEmailAddresses(List<EmailAddress> emailAddresses);

public LocalDateTime getCreatedAt() {
return createdAt;
default PhoneNumber getPrimaryPhoneNumber() {
return getPhoneNumbers().stream().filter(PhoneNumber::isPrimaryPhoneNumber).findFirst().orElse(null);
}

public void setCreatedAt(LocalDateTime createdAt) {
this.createdAt = createdAt;
}
List<PhoneNumber> getPhoneNumbers();

public LocalDateTime getUpdatedAt() {
return updatedAt;
}
void setPhoneNumbers(List<PhoneNumber> phoneNumbers);

public void setUpdatedAt(LocalDateTime updatedAt) {
this.updatedAt = updatedAt;
}
LocalDateTime getCreatedAt();

void setCreatedAt(LocalDateTime createdAt);

LocalDateTime getUpdatedAt();

void setUpdatedAt(LocalDateTime updatedAt);
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package dev.cloudeko.zenei.user;

import io.smallrye.mutiny.Uni;

import java.util.List;
import java.util.Optional;

public interface UserAccountProvider<ID> {

Optional<UserAccount<ID>> findUserByIdentifierBlocking(ID id);

UserAccount<ID> createUserBlocking(UserAccount<ID> entity);

UserAccount<ID> updateUserBlocking(UserAccount<ID> entity);

boolean deleteUserBlocking(ID id);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package dev.cloudeko.zenei.user;

import java.util.List;
import java.util.Optional;

public interface UserAccountQueryProvider<ID> {

Optional<UserAccount<ID>> findUserByUsernameBlocking(String username);

List<UserAccount<ID>> listUsersBlocking();

List<UserAccount<ID>> listUsersBlocking(int page, int pageSize);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package dev.cloudeko.zenei.user;

import io.smallrye.mutiny.Uni;

import java.util.List;
import java.util.Optional;

public interface UserAccountReactiveProvider<ID> {

Uni<UserAccount<ID>> findUserByIdentifier(ID id);

default Optional<UserAccount<ID>> findUserByIdentifierBlocking(ID id) {
return Optional.ofNullable(findUserByIdentifier(id).await().indefinitely());
}

Uni<UserAccount<ID>> findUserByPrimaryEmailAddress(String email);

default Optional<UserAccount<ID>> findUserByPrimaryEmailAddressBlocking(String email) {
return Optional.ofNullable(findUserByPrimaryEmailAddress(email).await().indefinitely());
}

Uni<UserAccount<ID>> findUserByPrimaryPhoneNumber(String phoneNumber);

default Optional<UserAccount<ID>> findUserByPrimaryPhoneNumberBlocking(String phoneNumber) {
return Optional.ofNullable(findUserByPrimaryPhoneNumber(phoneNumber).await().indefinitely());
}

Uni<UserAccount<ID>> findUserByUsername(String username);

default Optional<UserAccount<ID>> findUserByUsernameBlocking(String username) {
return Optional.ofNullable(findUserByUsername(username).await().indefinitely());
}

Uni<List<UserAccount<ID>>> listUsers();

default List<UserAccount<ID>> listUsersBlocking() {
return listUsers().await().indefinitely();
}

Uni<List<UserAccount<ID>>> listUsers(int page, int pageSize);

default List<UserAccount<ID>> listUsersBlocking(int page, int pageSize) {
return listUsers(page, pageSize).await().indefinitely();
}

Uni<UserAccount<ID>> createUser(UserAccount<ID> entity);

default UserAccount<ID> createUserBlocking(UserAccount<ID> entity) {
return createUser(entity).await().indefinitely();
}

Uni<UserAccount<ID>> updateUser(UserAccount<ID> entity);

default UserAccount<ID> updateUserBlocking(UserAccount<ID> entity) {
return updateUser(entity).await().indefinitely();
}

Uni<Boolean> deleteUser(ID id);

default boolean deleteUserBlocking(ID id) {
return deleteUser(id).await().indefinitely();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package dev.cloudeko.zenei.user;

import io.smallrye.mutiny.Uni;

import java.util.List;
import java.util.Optional;

public interface UserManager<ID> extends UserAccountProvider<ID>, UserAccountReactiveProvider<ID> {

@Override
default Optional<UserAccount<ID>> findUserByIdentifierBlocking(ID id) {
return Optional.ofNullable(findUserByIdentifier(id).await().indefinitely());
}

@Override
default Optional<UserAccount<ID>> findUserByUsernameBlocking(String username) {
return Optional.ofNullable(findUserByUsername(username).await().indefinitely());
}

@Override
default List<UserAccount<ID>> listUsersBlocking() {
return listUsers().await().indefinitely();
}

@Override
default List<UserAccount<ID>> listUsersBlocking(int page, int pageSize) {
return listUsers(page, pageSize).await().indefinitely();
}

@Override
default UserAccount<ID> createUserBlocking(UserAccount<ID> entity) {
return createUser(entity).await().indefinitely();
}

@Override
default UserAccount<ID> updateUserBlocking(UserAccount<ID> entity) {
return updateUser(entity).await().indefinitely();
}

@Override
default boolean deleteUserBlocking(ID id) {
return deleteUser(id).await().indefinitely();
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
package dev.cloudeko.zenei.user.runtime;

import dev.cloudeko.zenei.user.EmailAddress;
import dev.cloudeko.zenei.user.UserAccountManager;
import dev.cloudeko.zenei.user.UserAccountReactiveProvider;
import io.smallrye.mutiny.Multi;
import io.smallrye.mutiny.Uni;
import org.jboss.logging.Logger;

import java.util.ArrayList;
import java.util.List;

public class DefaultUserAccountManager implements UserAccountManager<DefaultUserAccount, Long> {
public class DefaultUserAccountReactiveProvider implements UserAccountReactiveProvider<DefaultUserAccount, Long> {

private static final Logger log = Logger.getLogger(DefaultUserAccountManager.class);
private static final Logger log = Logger.getLogger(DefaultUserAccountReactiveProvider.class);

private final DefaultUserAccountRepository userAccountRepository;
private final DefaultUserAccountEmailAddressRepository emailAddressRepository;

public DefaultUserAccountManager(DefaultUserAccountRepository userAccountRepository,
public DefaultUserAccountReactiveProvider(DefaultUserAccountRepository userAccountRepository,
DefaultUserAccountEmailAddressRepository emailAddressRepository) {
this.userAccountRepository = userAccountRepository;
this.emailAddressRepository = emailAddressRepository;
Expand Down

0 comments on commit fce11ce

Please sign in to comment.