Refactored UserRepository
This commit is contained in:
parent
d92a3fed6e
commit
4695dce10d
@ -1,26 +1,23 @@
|
|||||||
package ru.dragonestia.picker.api.repository;
|
package ru.dragonestia.picker.api.repository;
|
||||||
|
|
||||||
import ru.dragonestia.picker.api.model.room.ResponseRoom;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import ru.dragonestia.picker.api.model.room.RoomDetails;
|
|
||||||
import ru.dragonestia.picker.api.model.room.ShortResponseRoom;
|
import ru.dragonestia.picker.api.model.room.ShortResponseRoom;
|
||||||
import ru.dragonestia.picker.api.model.user.ResponseUser;
|
import ru.dragonestia.picker.api.model.user.ResponseUser;
|
||||||
import ru.dragonestia.picker.api.model.user.UserDetails;
|
import ru.dragonestia.picker.api.repository.request.user.*;
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public interface UserRepository {
|
public interface UserRepository {
|
||||||
|
|
||||||
void linkWithRoom(ResponseRoom room, Collection<ResponseUser> users, boolean force);
|
void linkUsersWithRoom(@NotNull LinkUsersWithRoom request);
|
||||||
|
|
||||||
void unlinkFromRoom(ResponseRoom room, Collection<ResponseUser> users);
|
void unlinkUsersFromRoom(@NotNull UnlinkUsersFromRoom request);
|
||||||
|
|
||||||
List<ResponseUser> all(ResponseRoom room, Set<UserDetails> details);
|
@NotNull List<ResponseUser> getAllUsersFormRoom(@NotNull GetAllUsersFromRoom request);
|
||||||
|
|
||||||
List<ResponseUser> search(String input, Set<UserDetails> details);
|
@NotNull List<ResponseUser> searchUsers(@NotNull SearchUsers request);
|
||||||
|
|
||||||
ResponseUser find(String userId, Set<UserDetails> details);
|
@NotNull ResponseUser findUserById(@NotNull FindUserById request);
|
||||||
|
|
||||||
List<ShortResponseRoom> getLinkedRoomsWithUsers(ResponseUser user, Set<RoomDetails> roomDetails);
|
@NotNull List<ShortResponseRoom> findRoomsLinkedWithUser(@NotNull FindRoomsLinkedWithUser request);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,66 @@
|
|||||||
|
package ru.dragonestia.picker.api.repository.request.user;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.Contract;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import ru.dragonestia.picker.api.model.room.RoomDetails;
|
||||||
|
import ru.dragonestia.picker.api.repository.type.UserIdentifier;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class FindRoomsLinkedWithUser {
|
||||||
|
|
||||||
|
private final String userId;
|
||||||
|
private final Set<RoomDetails> details;
|
||||||
|
|
||||||
|
private FindRoomsLinkedWithUser(String userId, Set<RoomDetails> details) {
|
||||||
|
this.userId = userId;
|
||||||
|
this.details = details;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull String getUserId() {
|
||||||
|
return userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull Set<RoomDetails> getDetails() {
|
||||||
|
return details;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @NotNull Builder builder() {
|
||||||
|
return new Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Builder {
|
||||||
|
|
||||||
|
private String userId = null;
|
||||||
|
private Set<RoomDetails> details = new HashSet<>();
|
||||||
|
|
||||||
|
private Builder() {}
|
||||||
|
|
||||||
|
@Contract("_ -> this")
|
||||||
|
public @NotNull Builder setUserId(@NotNull UserIdentifier identifier) {
|
||||||
|
userId = identifier.getValue();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Contract("_ -> this")
|
||||||
|
public @NotNull Builder setDetails(@NotNull Set<RoomDetails> details) {
|
||||||
|
this.details = details;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Contract("_ -> this")
|
||||||
|
public @NotNull Builder appendDetail(@NotNull RoomDetails detail) {
|
||||||
|
details.add(detail);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull FindRoomsLinkedWithUser build() {
|
||||||
|
if (userId == null) {
|
||||||
|
throw new NullPointerException("User id is null");
|
||||||
|
}
|
||||||
|
|
||||||
|
return new FindRoomsLinkedWithUser(userId, details);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,81 @@
|
|||||||
|
package ru.dragonestia.picker.api.repository.request.user;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.Contract;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import ru.dragonestia.picker.api.model.user.UserDetails;
|
||||||
|
import ru.dragonestia.picker.api.repository.type.UserIdentifier;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class FindUserById {
|
||||||
|
|
||||||
|
private final String userId;
|
||||||
|
private final Set<UserDetails> details;
|
||||||
|
|
||||||
|
private FindUserById(String userId, Set<UserDetails> details) {
|
||||||
|
this.userId = userId;
|
||||||
|
this.details = details;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull String getUserId() {
|
||||||
|
return userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull Set<UserDetails> getDetails() {
|
||||||
|
return details;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Contract("_ -> new")
|
||||||
|
public static @NotNull FindUserById just(@NotNull UserIdentifier userId) {
|
||||||
|
return builder()
|
||||||
|
.setUserId(userId)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Contract("_ -> new")
|
||||||
|
public static @NotNull FindUserById withAllDetails(@NotNull UserIdentifier userId) {
|
||||||
|
return builder()
|
||||||
|
.setUserId(userId)
|
||||||
|
.setDetails(Arrays.stream(UserDetails.values()).collect(Collectors.toSet()))
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @NotNull Builder builder() {
|
||||||
|
return new Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Builder {
|
||||||
|
|
||||||
|
private String userId = null;
|
||||||
|
private Set<UserDetails> details = new HashSet<>();
|
||||||
|
|
||||||
|
private Builder() {}
|
||||||
|
|
||||||
|
@Contract("_ -> this")
|
||||||
|
public @NotNull Builder setUserId(@NotNull UserIdentifier identifier) {
|
||||||
|
userId = identifier.getValue();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Contract("_ -> this")
|
||||||
|
public @NotNull Builder setDetails(@NotNull Set<UserDetails> details) {
|
||||||
|
this.details = details;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Contract("_ -> this")
|
||||||
|
public @NotNull Builder appendDetail(@NotNull UserDetails detail) {
|
||||||
|
details.add(detail);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull FindUserById build() {
|
||||||
|
if (userId == null) {
|
||||||
|
throw new NullPointerException("User id is null");
|
||||||
|
}
|
||||||
|
|
||||||
|
return new FindUserById(userId, Collections.unmodifiableSet(details));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,84 @@
|
|||||||
|
package ru.dragonestia.picker.api.repository.request.user;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.Contract;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import ru.dragonestia.picker.api.model.user.UserDetails;
|
||||||
|
import ru.dragonestia.picker.api.repository.type.NodeIdentifier;
|
||||||
|
import ru.dragonestia.picker.api.repository.type.RoomIdentifier;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class GetAllUsersFromRoom {
|
||||||
|
|
||||||
|
private final String nodeId;
|
||||||
|
private final String roomId;
|
||||||
|
private final Set<UserDetails> details;
|
||||||
|
|
||||||
|
private GetAllUsersFromRoom(String nodeId, String roomId, Set<UserDetails> details) {
|
||||||
|
this.nodeId = nodeId;
|
||||||
|
this.roomId = roomId;
|
||||||
|
this.details = details;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull String getNodeId() {
|
||||||
|
return nodeId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull String getRoomId() {
|
||||||
|
return roomId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull Set<UserDetails> getDetails() {
|
||||||
|
return details;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @NotNull Builder builder() {
|
||||||
|
return new Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Builder {
|
||||||
|
|
||||||
|
private String nodeId = null;
|
||||||
|
private String roomId = null;
|
||||||
|
private Set<UserDetails> details = new HashSet<>();
|
||||||
|
|
||||||
|
private Builder() {}
|
||||||
|
|
||||||
|
@Contract("_ -> this")
|
||||||
|
public @NotNull Builder setNodeId(@NotNull NodeIdentifier identifier) {
|
||||||
|
nodeId = identifier.getValue();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Contract("_ -> this")
|
||||||
|
public @NotNull Builder setRoomId(@NotNull RoomIdentifier identifier) {
|
||||||
|
roomId = identifier.getValue();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Contract("_ -> this")
|
||||||
|
public @NotNull Builder setDetails(@NotNull Set<UserDetails> details) {
|
||||||
|
this.details = details;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Contract("_ -> this")
|
||||||
|
public @NotNull Builder appendDetail(@NotNull UserDetails detail) {
|
||||||
|
details.add(detail);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull GetAllUsersFromRoom build() {
|
||||||
|
if (nodeId == null) {
|
||||||
|
throw new NullPointerException("Node id is null");
|
||||||
|
}
|
||||||
|
if (roomId == null) {
|
||||||
|
throw new NullPointerException("Room id is null");
|
||||||
|
}
|
||||||
|
|
||||||
|
return new GetAllUsersFromRoom(nodeId, roomId, Collections.unmodifiableSet(details));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,100 @@
|
|||||||
|
package ru.dragonestia.picker.api.repository.request.user;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.Contract;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import ru.dragonestia.picker.api.repository.type.NodeIdentifier;
|
||||||
|
import ru.dragonestia.picker.api.repository.type.RoomIdentifier;
|
||||||
|
import ru.dragonestia.picker.api.repository.type.UserIdentifier;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class LinkUsersWithRoom {
|
||||||
|
|
||||||
|
private final String nodeId;
|
||||||
|
private final String roomId;
|
||||||
|
private final Set<String> users;
|
||||||
|
private final boolean ignoreSlotLimitation;
|
||||||
|
|
||||||
|
private LinkUsersWithRoom(String nodeId, String roomId, Set<String> users, boolean ignoreSlotLimitation) {
|
||||||
|
this.nodeId = nodeId;
|
||||||
|
this.roomId = roomId;
|
||||||
|
this.users = users;
|
||||||
|
this.ignoreSlotLimitation = ignoreSlotLimitation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull String getNodeId() {
|
||||||
|
return nodeId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull String getRoomId() {
|
||||||
|
return roomId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull Set<String> getUsers() {
|
||||||
|
return users;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean ignoreSlotLimitation() {
|
||||||
|
return ignoreSlotLimitation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @NotNull Builder builder() {
|
||||||
|
return new Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Builder {
|
||||||
|
|
||||||
|
private String nodeId = null;
|
||||||
|
private String roomId = null;
|
||||||
|
private Set<UserIdentifier> users = new HashSet<>();
|
||||||
|
private boolean ignoreSlotLimitation = false;
|
||||||
|
|
||||||
|
private Builder() {}
|
||||||
|
|
||||||
|
@Contract("_ -> this")
|
||||||
|
public @NotNull Builder setNodeId(@NotNull NodeIdentifier identifier) {
|
||||||
|
nodeId = identifier.getValue();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Contract("_ -> this")
|
||||||
|
public @NotNull Builder setRoomId(@NotNull RoomIdentifier identifier) {
|
||||||
|
roomId = identifier.getValue();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Contract("_ -> this")
|
||||||
|
public @NotNull Builder setUsers(@NotNull Set<UserIdentifier> users) {
|
||||||
|
this.users = users;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Contract("_ -> this")
|
||||||
|
public @NotNull Builder appendUser(@NotNull UserIdentifier user) {
|
||||||
|
users.add(user);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Contract("_ -> this")
|
||||||
|
public @NotNull Builder setIgnoreSlotLimitation(boolean value) {
|
||||||
|
ignoreSlotLimitation = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull LinkUsersWithRoom build() {
|
||||||
|
if (nodeId == null) {
|
||||||
|
throw new NullPointerException("Node id is null");
|
||||||
|
}
|
||||||
|
if (roomId == null) {
|
||||||
|
throw new NullPointerException("Room id is null");
|
||||||
|
}
|
||||||
|
|
||||||
|
return new LinkUsersWithRoom(nodeId,
|
||||||
|
roomId,
|
||||||
|
users.stream().map(o -> o.getValue()).collect(Collectors.toSet()),
|
||||||
|
ignoreSlotLimitation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,84 @@
|
|||||||
|
package ru.dragonestia.picker.api.repository.request.user;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.Contract;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import ru.dragonestia.picker.api.model.user.UserDetails;
|
||||||
|
import ru.dragonestia.picker.api.repository.type.UserIdentifier;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class SearchUsers {
|
||||||
|
|
||||||
|
private final String searchInput;
|
||||||
|
private final Set<UserDetails> details;
|
||||||
|
|
||||||
|
private SearchUsers(String searchInput, Set<UserDetails> details) {
|
||||||
|
this.searchInput = searchInput;
|
||||||
|
this.details = details;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull String getSearchInput() {
|
||||||
|
return searchInput;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull Set<UserDetails> getDetails() {
|
||||||
|
return details;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Contract("_ -> new")
|
||||||
|
public static @NotNull SearchUsers just(@NotNull UserIdentifier searchInput) {
|
||||||
|
return SearchUsers.builder()
|
||||||
|
.setSearchInput(searchInput)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Contract("_ -> new")
|
||||||
|
public static @NotNull SearchUsers withAllDetails(@NotNull UserIdentifier searchInput) {
|
||||||
|
return SearchUsers.builder()
|
||||||
|
.setSearchInput(searchInput)
|
||||||
|
.setDetails(Arrays.stream(UserDetails.values()).collect(Collectors.toSet()))
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @NotNull Builder builder() {
|
||||||
|
return new Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Builder {
|
||||||
|
|
||||||
|
private String searchInput = null;
|
||||||
|
private Set<UserDetails> details = new HashSet<>();
|
||||||
|
|
||||||
|
private Builder() {}
|
||||||
|
|
||||||
|
@Contract("_ -> this")
|
||||||
|
public @NotNull Builder setSearchInput(@NotNull UserIdentifier input) {
|
||||||
|
searchInput = input.getValue();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Contract("_ -> this")
|
||||||
|
public @NotNull Builder setDetails(@NotNull Set<UserDetails> details) {
|
||||||
|
this.details = details;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Contract("_ -> this")
|
||||||
|
public @NotNull Builder appendDetail(@NotNull UserDetails detail) {
|
||||||
|
details.add(detail);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull SearchUsers build() {
|
||||||
|
if (searchInput == null) {
|
||||||
|
throw new NullPointerException("SearchInput is null");
|
||||||
|
}
|
||||||
|
|
||||||
|
return new SearchUsers(searchInput, Collections.unmodifiableSet(details));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,86 @@
|
|||||||
|
package ru.dragonestia.picker.api.repository.request.user;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.Contract;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import ru.dragonestia.picker.api.repository.type.NodeIdentifier;
|
||||||
|
import ru.dragonestia.picker.api.repository.type.RoomIdentifier;
|
||||||
|
import ru.dragonestia.picker.api.repository.type.UserIdentifier;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class UnlinkUsersFromRoom {
|
||||||
|
|
||||||
|
private final String nodeId;
|
||||||
|
private final String roomId;
|
||||||
|
private final Set<String> users;
|
||||||
|
|
||||||
|
private UnlinkUsersFromRoom(String nodeId, String roomId, Set<String> users) {
|
||||||
|
this.nodeId = nodeId;
|
||||||
|
this.roomId = roomId;
|
||||||
|
this.users = users;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull String getNodeId() {
|
||||||
|
return nodeId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull String getRoomId() {
|
||||||
|
return roomId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull Set<String> getUsers() {
|
||||||
|
return users;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @NotNull Builder builder() {
|
||||||
|
return new Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Builder {
|
||||||
|
|
||||||
|
private String nodeId = null;
|
||||||
|
private String roomId = null;
|
||||||
|
private Set<UserIdentifier> users = new HashSet<>();
|
||||||
|
|
||||||
|
private Builder() {}
|
||||||
|
|
||||||
|
@Contract("_ -> this")
|
||||||
|
public @NotNull Builder setNodeId(@NotNull NodeIdentifier identifier) {
|
||||||
|
nodeId = identifier.getValue();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Contract("_ -> this")
|
||||||
|
public @NotNull Builder setRoomId(@NotNull RoomIdentifier identifier) {
|
||||||
|
roomId = identifier.getValue();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Contract("_ -> this")
|
||||||
|
public @NotNull Builder setUsers(@NotNull Set<UserIdentifier> users) {
|
||||||
|
this.users = users;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Contract("_ -> this")
|
||||||
|
public @NotNull Builder appendUser(@NotNull UserIdentifier user) {
|
||||||
|
users.add(user);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull UnlinkUsersFromRoom build() {
|
||||||
|
if (nodeId == null) {
|
||||||
|
throw new NullPointerException("Node id is null");
|
||||||
|
}
|
||||||
|
if (roomId == null) {
|
||||||
|
throw new NullPointerException("Room id is null");
|
||||||
|
}
|
||||||
|
|
||||||
|
return new UnlinkUsersFromRoom(nodeId,
|
||||||
|
roomId,
|
||||||
|
users.stream().map(o -> o.getValue()).collect(Collectors.toSet()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user