Implemented RoomRepository
This commit is contained in:
parent
425fb71f4c
commit
5814119428
@ -59,7 +59,7 @@ public class RoomDefinition implements IRoom {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable Boolean isPersist() {
|
public @NotNull Boolean isPersist() {
|
||||||
return persist;
|
return persist;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
package ru.dragonestia.picker.api.repository;
|
package ru.dragonestia.picker.api.repository;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import ru.dragonestia.picker.api.model.room.IRoom;
|
||||||
import ru.dragonestia.picker.api.model.room.ResponseRoom;
|
import ru.dragonestia.picker.api.model.room.ResponseRoom;
|
||||||
import ru.dragonestia.picker.api.model.room.RoomDefinition;
|
import ru.dragonestia.picker.api.model.room.RoomDefinition;
|
||||||
import ru.dragonestia.picker.api.model.room.ShortResponseRoom;
|
import ru.dragonestia.picker.api.model.room.ShortResponseRoom;
|
||||||
@ -18,6 +19,8 @@ public interface RoomRepository {
|
|||||||
|
|
||||||
void removeRooms(@NotNull RemoveRoomsByIds request);
|
void removeRooms(@NotNull RemoveRoomsByIds request);
|
||||||
|
|
||||||
|
void removeRoom(@NotNull IRoom room);
|
||||||
|
|
||||||
@NotNull List<ShortResponseRoom> allRooms(@NotNull GetAllRooms request);
|
@NotNull List<ShortResponseRoom> allRooms(@NotNull GetAllRooms request);
|
||||||
|
|
||||||
@NotNull Optional<ResponseRoom> find(@NotNull FindRoomById request);
|
@NotNull Optional<ResponseRoom> find(@NotNull FindRoomById request);
|
||||||
|
|||||||
@ -2,26 +2,34 @@ package ru.dragonestia.picker.api.repository.request.room;
|
|||||||
|
|
||||||
import org.jetbrains.annotations.Contract;
|
import org.jetbrains.annotations.Contract;
|
||||||
import org.jetbrains.annotations.NotNull;
|
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.RoomPath;
|
import ru.dragonestia.picker.api.repository.type.RoomPath;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class RemoveRoomsByIds {
|
public class RemoveRoomsByIds {
|
||||||
|
|
||||||
private final Set<RoomPath> paths;
|
private final String nodeId;
|
||||||
|
private final Set<String> roomsIds;
|
||||||
|
|
||||||
private RemoveRoomsByIds(Set<RoomPath> paths) {
|
private RemoveRoomsByIds(String nodeId, Set<String> roomIds) {
|
||||||
this.paths = paths;
|
this.nodeId = nodeId;
|
||||||
|
this.roomsIds = roomIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
public @NotNull Set<RoomPath> getPaths() {
|
public @NotNull String getNodeId() {
|
||||||
return paths;
|
return nodeId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static @NotNull RemoveRoomsByIds just(@NotNull RoomPath path) {
|
public @NotNull Set<String> getRoomsIds() {
|
||||||
return RemoveRoomsByIds.builder().appendPath(path).build();
|
return roomsIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @NotNull RemoveRoomsByIds just(@NotNull NodeIdentifier nodeId, @NotNull RoomIdentifier roomId) {
|
||||||
|
return RemoveRoomsByIds.builder().appendRoomId(path).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static @NotNull Builder builder() {
|
public static @NotNull Builder builder() {
|
||||||
@ -30,24 +38,35 @@ public class RemoveRoomsByIds {
|
|||||||
|
|
||||||
public static class Builder {
|
public static class Builder {
|
||||||
|
|
||||||
private Set<RoomPath> paths = new HashSet<>();
|
private String nodeId = null;
|
||||||
|
private Set<RoomIdentifier> roomsIds;
|
||||||
|
|
||||||
private Builder() {}
|
private Builder() {}
|
||||||
|
|
||||||
@Contract("_ -> this")
|
@Contract("_ -> this")
|
||||||
public @NotNull Builder setPaths(@NotNull Set<RoomPath> paths) {
|
public @NotNull Builder setNodeId(@NotNull NodeIdentifier identifier) {
|
||||||
this.paths = paths;
|
nodeId = identifier.getValue();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Contract("_ -> this")
|
@Contract("_ -> this")
|
||||||
public @NotNull Builder appendPath(@NotNull RoomPath path) {
|
public @NotNull Builder setRoomsIds(@NotNull Set<RoomIdentifier> roomIds) {
|
||||||
paths.add(path);
|
this.roomsIds = roomIds;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Contract("_ -> this")
|
||||||
|
public @NotNull Builder appendRoomId(@NotNull RoomIdentifier roomId) {
|
||||||
|
roomsIds.add(roomId);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public @NotNull RemoveRoomsByIds build() {
|
public @NotNull RemoveRoomsByIds build() {
|
||||||
return new RemoveRoomsByIds(Collections.unmodifiableSet(paths));
|
if (nodeId == null) {
|
||||||
|
throw new NullPointerException("Node id is null");
|
||||||
|
}
|
||||||
|
|
||||||
|
return new RemoveRoomsByIds(nodeId, roomsIds.stream().map(o -> o.getValue()).collect(Collectors.toSet()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -53,6 +53,8 @@ public class NodeRepositoryImpl implements NodeRepository {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeNodesById(@NotNull RemoveNodesByIds data) {
|
public void removeNodesById(@NotNull RemoveNodesByIds data) {
|
||||||
|
if (data.getNodeIds().isEmpty()) return;
|
||||||
|
|
||||||
rest.query("/nodes", HttpMethod.DELETE, params -> {
|
rest.query("/nodes", HttpMethod.DELETE, params -> {
|
||||||
params.put("toDelete", String.join(",", data.getNodeIds()));
|
params.put("toDelete", String.join(",", data.getNodeIds()));
|
||||||
});
|
});
|
||||||
|
|||||||
@ -2,8 +2,12 @@ package ru.dragonestia.picker.api.impl.repository;
|
|||||||
|
|
||||||
import org.jetbrains.annotations.ApiStatus.Internal;
|
import org.jetbrains.annotations.ApiStatus.Internal;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import ru.dragonestia.picker.api.exception.RoomNotFoundException;
|
||||||
import ru.dragonestia.picker.api.impl.RoomPickerClient;
|
import ru.dragonestia.picker.api.impl.RoomPickerClient;
|
||||||
|
import ru.dragonestia.picker.api.impl.util.EnumUtils;
|
||||||
import ru.dragonestia.picker.api.impl.util.RestTemplate;
|
import ru.dragonestia.picker.api.impl.util.RestTemplate;
|
||||||
|
import ru.dragonestia.picker.api.impl.util.type.HttpMethod;
|
||||||
|
import ru.dragonestia.picker.api.model.room.IRoom;
|
||||||
import ru.dragonestia.picker.api.model.room.ResponseRoom;
|
import ru.dragonestia.picker.api.model.room.ResponseRoom;
|
||||||
import ru.dragonestia.picker.api.model.room.RoomDefinition;
|
import ru.dragonestia.picker.api.model.room.RoomDefinition;
|
||||||
import ru.dragonestia.picker.api.model.room.ShortResponseRoom;
|
import ru.dragonestia.picker.api.model.room.ShortResponseRoom;
|
||||||
@ -11,6 +15,8 @@ import ru.dragonestia.picker.api.repository.RoomRepository;
|
|||||||
import ru.dragonestia.picker.api.repository.request.room.FindRoomById;
|
import ru.dragonestia.picker.api.repository.request.room.FindRoomById;
|
||||||
import ru.dragonestia.picker.api.repository.request.room.GetAllRooms;
|
import ru.dragonestia.picker.api.repository.request.room.GetAllRooms;
|
||||||
import ru.dragonestia.picker.api.repository.request.room.RemoveRoomsByIds;
|
import ru.dragonestia.picker.api.repository.request.room.RemoveRoomsByIds;
|
||||||
|
import ru.dragonestia.picker.api.repository.response.RoomInfoResponse;
|
||||||
|
import ru.dragonestia.picker.api.repository.response.RoomListResponse;
|
||||||
import ru.dragonestia.picker.api.repository.type.RoomPath;
|
import ru.dragonestia.picker.api.repository.type.RoomPath;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -27,26 +33,56 @@ public class RoomRepositoryImpl implements RoomRepository {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void saveRoom(@NotNull RoomDefinition definition) {
|
public void saveRoom(@NotNull RoomDefinition definition) {
|
||||||
throw new UnsupportedOperationException("Not implemented");
|
rest.query("/nodes/" + definition.getNodeIdentifier() + "/rooms", HttpMethod.POST, params -> {
|
||||||
|
params.put("roomId", definition.getIdentifier());
|
||||||
|
params.put("slots", Integer.toString(definition.getMaxSlots()));
|
||||||
|
params.put("payload", definition.getPayload());
|
||||||
|
params.put("locked", Boolean.toString(definition.isLocked()));
|
||||||
|
params.put("persist", Boolean.toString(definition.isPersist()));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeRooms(@NotNull RemoveRoomsByIds request) {
|
public void removeRooms(@NotNull RemoveRoomsByIds request) {
|
||||||
throw new UnsupportedOperationException("Not implemented");
|
if (request.getRoomsIds().isEmpty()) return;
|
||||||
|
|
||||||
|
rest.query("/nodes/" + request.getNodeId() + "/rooms", HttpMethod.DELETE, params -> {
|
||||||
|
params.put("toDelete", String.join(",", request.getRoomsIds()));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeRoom(@NotNull IRoom room) {
|
||||||
|
rest.query(
|
||||||
|
"/nodes/%s/rooms/%s".formatted(room.getNodeIdentifier(), room.getIdentifier()),
|
||||||
|
HttpMethod.DELETE,
|
||||||
|
params -> {}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull List<ShortResponseRoom> allRooms(@NotNull GetAllRooms request) {
|
public @NotNull List<ShortResponseRoom> allRooms(@NotNull GetAllRooms request) {
|
||||||
throw new UnsupportedOperationException("Not implemented");
|
return rest.query("/nodes/" + request.getNodeId() + "/rooms", HttpMethod.GET, RoomListResponse.class, params -> {
|
||||||
|
params.put("requiredDetails", EnumUtils.enumSetToString(request.getDetails()));
|
||||||
|
}).rooms();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull Optional<ResponseRoom> find(@NotNull FindRoomById request) {
|
public @NotNull Optional<ResponseRoom> find(@NotNull FindRoomById request) {
|
||||||
throw new UnsupportedOperationException("Not implemented");
|
try {
|
||||||
|
var response = rest.query("/nodes/%s/rooms/%s".formatted(request.getNodeId(), request.getId()), HttpMethod.GET, RoomInfoResponse.class, params -> {
|
||||||
|
params.put("requiredDetails", EnumUtils.enumSetToString(request.getDetails()));
|
||||||
|
});
|
||||||
|
return Optional.of(response.room());
|
||||||
|
} catch (RoomNotFoundException ex) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void lockRoom(@NotNull RoomPath path, boolean value) {
|
public void lockRoom(@NotNull RoomPath path, boolean value) {
|
||||||
throw new UnsupportedOperationException("Not implemented");
|
rest.query("/nodes/%s/rooms/%s/lock".formatted(path.getNodeId(), path.getRoomId()), HttpMethod.PUT, params -> {
|
||||||
|
params.put("newState", Boolean.toString(value));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user