Implemented RoomRepository
This commit is contained in:
parent
425fb71f4c
commit
5814119428
@ -59,7 +59,7 @@ public class RoomDefinition implements IRoom {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Boolean isPersist() {
|
||||
public @NotNull Boolean isPersist() {
|
||||
return persist;
|
||||
}
|
||||
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package ru.dragonestia.picker.api.repository;
|
||||
|
||||
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.RoomDefinition;
|
||||
import ru.dragonestia.picker.api.model.room.ShortResponseRoom;
|
||||
@ -18,6 +19,8 @@ public interface RoomRepository {
|
||||
|
||||
void removeRooms(@NotNull RemoveRoomsByIds request);
|
||||
|
||||
void removeRoom(@NotNull IRoom room);
|
||||
|
||||
@NotNull List<ShortResponseRoom> allRooms(@NotNull GetAllRooms 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.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 java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class RemoveRoomsByIds {
|
||||
|
||||
private final Set<RoomPath> paths;
|
||||
private final String nodeId;
|
||||
private final Set<String> roomsIds;
|
||||
|
||||
private RemoveRoomsByIds(Set<RoomPath> paths) {
|
||||
this.paths = paths;
|
||||
private RemoveRoomsByIds(String nodeId, Set<String> roomIds) {
|
||||
this.nodeId = nodeId;
|
||||
this.roomsIds = roomIds;
|
||||
}
|
||||
|
||||
public @NotNull Set<RoomPath> getPaths() {
|
||||
return paths;
|
||||
public @NotNull String getNodeId() {
|
||||
return nodeId;
|
||||
}
|
||||
|
||||
public static @NotNull RemoveRoomsByIds just(@NotNull RoomPath path) {
|
||||
return RemoveRoomsByIds.builder().appendPath(path).build();
|
||||
public @NotNull Set<String> getRoomsIds() {
|
||||
return roomsIds;
|
||||
}
|
||||
|
||||
public static @NotNull RemoveRoomsByIds just(@NotNull NodeIdentifier nodeId, @NotNull RoomIdentifier roomId) {
|
||||
return RemoveRoomsByIds.builder().appendRoomId(path).build();
|
||||
}
|
||||
|
||||
public static @NotNull Builder builder() {
|
||||
@ -30,24 +38,35 @@ public class RemoveRoomsByIds {
|
||||
|
||||
public static class Builder {
|
||||
|
||||
private Set<RoomPath> paths = new HashSet<>();
|
||||
private String nodeId = null;
|
||||
private Set<RoomIdentifier> roomsIds;
|
||||
|
||||
private Builder() {}
|
||||
|
||||
@Contract("_ -> this")
|
||||
public @NotNull Builder setPaths(@NotNull Set<RoomPath> paths) {
|
||||
this.paths = paths;
|
||||
public @NotNull Builder setNodeId(@NotNull NodeIdentifier identifier) {
|
||||
nodeId = identifier.getValue();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Contract("_ -> this")
|
||||
public @NotNull Builder appendPath(@NotNull RoomPath path) {
|
||||
paths.add(path);
|
||||
public @NotNull Builder setRoomsIds(@NotNull Set<RoomIdentifier> roomIds) {
|
||||
this.roomsIds = roomIds;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Contract("_ -> this")
|
||||
public @NotNull Builder appendRoomId(@NotNull RoomIdentifier roomId) {
|
||||
roomsIds.add(roomId);
|
||||
return this;
|
||||
}
|
||||
|
||||
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
|
||||
public void removeNodesById(@NotNull RemoveNodesByIds data) {
|
||||
if (data.getNodeIds().isEmpty()) return;
|
||||
|
||||
rest.query("/nodes", HttpMethod.DELETE, params -> {
|
||||
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.NotNull;
|
||||
import ru.dragonestia.picker.api.exception.RoomNotFoundException;
|
||||
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.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.RoomDefinition;
|
||||
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.GetAllRooms;
|
||||
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 java.util.List;
|
||||
@ -27,26 +33,56 @@ public class RoomRepositoryImpl implements RoomRepository {
|
||||
|
||||
@Override
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
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