diff --git a/client-api/src/main/java/ru/dragonestia/picker/api/repository/UserRepository.java b/client-api/src/main/java/ru/dragonestia/picker/api/repository/UserRepository.java index c23a626..29b42a6 100644 --- a/client-api/src/main/java/ru/dragonestia/picker/api/repository/UserRepository.java +++ b/client-api/src/main/java/ru/dragonestia/picker/api/repository/UserRepository.java @@ -1,26 +1,23 @@ package ru.dragonestia.picker.api.repository; -import ru.dragonestia.picker.api.model.room.ResponseRoom; -import ru.dragonestia.picker.api.model.room.RoomDetails; +import org.jetbrains.annotations.NotNull; import ru.dragonestia.picker.api.model.room.ShortResponseRoom; 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.Set; public interface UserRepository { - void linkWithRoom(ResponseRoom room, Collection users, boolean force); + void linkUsersWithRoom(@NotNull LinkUsersWithRoom request); - void unlinkFromRoom(ResponseRoom room, Collection users); + void unlinkUsersFromRoom(@NotNull UnlinkUsersFromRoom request); - List all(ResponseRoom room, Set details); + @NotNull List getAllUsersFormRoom(@NotNull GetAllUsersFromRoom request); - List search(String input, Set details); + @NotNull List searchUsers(@NotNull SearchUsers request); - ResponseUser find(String userId, Set details); + @NotNull ResponseUser findUserById(@NotNull FindUserById request); - List getLinkedRoomsWithUsers(ResponseUser user, Set roomDetails); + @NotNull List findRoomsLinkedWithUser(@NotNull FindRoomsLinkedWithUser request); } diff --git a/client-api/src/main/java/ru/dragonestia/picker/api/repository/request/user/FindRoomsLinkedWithUser.java b/client-api/src/main/java/ru/dragonestia/picker/api/repository/request/user/FindRoomsLinkedWithUser.java new file mode 100644 index 0000000..1266520 --- /dev/null +++ b/client-api/src/main/java/ru/dragonestia/picker/api/repository/request/user/FindRoomsLinkedWithUser.java @@ -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 details; + + private FindRoomsLinkedWithUser(String userId, Set details) { + this.userId = userId; + this.details = details; + } + + public @NotNull String getUserId() { + return userId; + } + + public @NotNull Set getDetails() { + return details; + } + + public static @NotNull Builder builder() { + return new Builder(); + } + + public static class Builder { + + private String userId = null; + private Set 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 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); + } + } +} diff --git a/client-api/src/main/java/ru/dragonestia/picker/api/repository/request/user/FindUserById.java b/client-api/src/main/java/ru/dragonestia/picker/api/repository/request/user/FindUserById.java new file mode 100644 index 0000000..48a0941 --- /dev/null +++ b/client-api/src/main/java/ru/dragonestia/picker/api/repository/request/user/FindUserById.java @@ -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 details; + + private FindUserById(String userId, Set details) { + this.userId = userId; + this.details = details; + } + + public @NotNull String getUserId() { + return userId; + } + + public @NotNull Set 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 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 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)); + } + } +} diff --git a/client-api/src/main/java/ru/dragonestia/picker/api/repository/request/user/GetAllUsersFromRoom.java b/client-api/src/main/java/ru/dragonestia/picker/api/repository/request/user/GetAllUsersFromRoom.java new file mode 100644 index 0000000..4a4ba3b --- /dev/null +++ b/client-api/src/main/java/ru/dragonestia/picker/api/repository/request/user/GetAllUsersFromRoom.java @@ -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 details; + + private GetAllUsersFromRoom(String nodeId, String roomId, Set 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 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 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 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)); + } + } +} diff --git a/client-api/src/main/java/ru/dragonestia/picker/api/repository/request/user/LinkUsersWithRoom.java b/client-api/src/main/java/ru/dragonestia/picker/api/repository/request/user/LinkUsersWithRoom.java new file mode 100644 index 0000000..8e889d2 --- /dev/null +++ b/client-api/src/main/java/ru/dragonestia/picker/api/repository/request/user/LinkUsersWithRoom.java @@ -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 users; + private final boolean ignoreSlotLimitation; + + private LinkUsersWithRoom(String nodeId, String roomId, Set 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 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 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 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); + } + } +} diff --git a/client-api/src/main/java/ru/dragonestia/picker/api/repository/request/user/SearchUsers.java b/client-api/src/main/java/ru/dragonestia/picker/api/repository/request/user/SearchUsers.java new file mode 100644 index 0000000..f6fa71f --- /dev/null +++ b/client-api/src/main/java/ru/dragonestia/picker/api/repository/request/user/SearchUsers.java @@ -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 details; + + private SearchUsers(String searchInput, Set details) { + this.searchInput = searchInput; + this.details = details; + } + + public @NotNull String getSearchInput() { + return searchInput; + } + + public @NotNull Set 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 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 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)); + } + } +} diff --git a/client-api/src/main/java/ru/dragonestia/picker/api/repository/request/user/UnlinkUsersFromRoom.java b/client-api/src/main/java/ru/dragonestia/picker/api/repository/request/user/UnlinkUsersFromRoom.java new file mode 100644 index 0000000..46a7151 --- /dev/null +++ b/client-api/src/main/java/ru/dragonestia/picker/api/repository/request/user/UnlinkUsersFromRoom.java @@ -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 users; + + private UnlinkUsersFromRoom(String nodeId, String roomId, Set 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 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 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 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())); + } + } +}