diff options
| author | Georgios Andreadis <g.andreadis@student.tudelft.nl> | 2017-08-22 17:08:55 +0200 |
|---|---|---|
| committer | Georgios Andreadis <g.andreadis@student.tudelft.nl> | 2017-09-23 10:05:44 +0200 |
| commit | 1ddbbd3563af77a218020021ea50a8832900b4db (patch) | |
| tree | 5647f9cfde2de3918eeeac58d6c598bb55e50d82 /src/api | |
| parent | 602c3eb9327a3681f5a220e13b8291bb60643cd7 (diff) | |
Add route logic for construction routes
Diffstat (limited to 'src/api')
| -rw-r--r-- | src/api/routes/datacenters.js | 26 | ||||
| -rw-r--r-- | src/api/routes/paths.js | 30 | ||||
| -rw-r--r-- | src/api/routes/room-types.js | 9 | ||||
| -rw-r--r-- | src/api/routes/rooms.js | 45 | ||||
| -rw-r--r-- | src/api/routes/sections.js | 5 | ||||
| -rw-r--r-- | src/api/routes/simulations.js | 47 | ||||
| -rw-r--r-- | src/api/routes/specifications.js | 57 | ||||
| -rw-r--r-- | src/api/routes/tiles.js | 146 | ||||
| -rw-r--r-- | src/api/routes/token-signin.js (renamed from src/api/routes/auth.js) | 0 | ||||
| -rw-r--r-- | src/api/routes/users.js | 25 | ||||
| -rw-r--r-- | src/api/routes/util.js | 37 | ||||
| -rw-r--r-- | src/api/sagas/objects.js | 10 | ||||
| -rw-r--r-- | src/api/sagas/simulations.js | 6 | ||||
| -rw-r--r-- | src/api/sagas/users.js | 2 |
14 files changed, 378 insertions, 67 deletions
diff --git a/src/api/routes/datacenters.js b/src/api/routes/datacenters.js new file mode 100644 index 00000000..df621a62 --- /dev/null +++ b/src/api/routes/datacenters.js @@ -0,0 +1,26 @@ +import {sendRequest} from "../index"; +import {getById} from "./util"; + +export function getDatacenter(datacenterId) { + return getById("/datacenters/{datacenterId}", {datacenterId}); +} + +export function getRoomsOfDatacenter(datacenterId) { + return getById("/datacenters/{datacenterId}/rooms", {datacenterId}); +} + +export function addRoomToDatacenter(room) { + return sendRequest({ + path: "/datacenters/{datacenterId}/rooms", + method: "POST", + parameters: { + body: { + room + }, + path: { + datacenterId: room.datacenterId + }, + query: {} + } + }); +} diff --git a/src/api/routes/paths.js b/src/api/routes/paths.js new file mode 100644 index 00000000..073cbe7e --- /dev/null +++ b/src/api/routes/paths.js @@ -0,0 +1,30 @@ +import {sendRequest} from "../index"; +import {getById} from "./util"; + +export function getPath(pathId) { + return getById("/paths/{pathId}", {pathId}); +} + +export function getBranchesOfPath(pathId) { + return getById("/paths/{pathId}/branches", {pathId}); +} + +export function branchFromPath(pathId, section) { + return sendRequest({ + path: "/paths/{pathId}/branches", + method: "POST", + parameters: { + body: { + section + }, + path: { + pathId + }, + query: {} + } + }); +} + +export function getSectionsOfPath(pathId) { + return getById("/paths/{pathId}/sections", {pathId}); +} diff --git a/src/api/routes/room-types.js b/src/api/routes/room-types.js new file mode 100644 index 00000000..339896d2 --- /dev/null +++ b/src/api/routes/room-types.js @@ -0,0 +1,9 @@ +import {getAll, getById} from "./util"; + +export function getAvailableRoomTypes() { + return getAll("/room-types"); +} + +export function getAllowedObjectsOfRoomType(name) { + return getById("/room-types/{name}/allowed-objects", {name}); +} diff --git a/src/api/routes/rooms.js b/src/api/routes/rooms.js new file mode 100644 index 00000000..e08cc6e7 --- /dev/null +++ b/src/api/routes/rooms.js @@ -0,0 +1,45 @@ +import {sendRequest} from "../index"; + +export function getRoom(roomId) { + return getById("/rooms/{roomId}", {roomId}); +} + +export function updateRoom(room) { + return sendRequest({ + path: "/rooms/{roomId}", + method: "PUT", + parameters: { + body: { + room + }, + path: { + roomId: room.id + }, + query: {} + } + }); +} + +export function deleteRoom(roomId) { + return deleteById("/rooms/{roomId}", {roomId}); +} + +export function getTilesOfRoom(roomId) { + return getById("/rooms/{roomId}/tiles", {roomId}); +} + +export function addTileToRoom(tile) { + return sendRequest({ + path: "/rooms/{roomId}/tiles", + method: "POST", + parameters: { + body: { + tile + }, + path: { + roomId: tile.roomId + }, + query: {} + } + }); +} diff --git a/src/api/routes/sections.js b/src/api/routes/sections.js new file mode 100644 index 00000000..8d71d768 --- /dev/null +++ b/src/api/routes/sections.js @@ -0,0 +1,5 @@ +import {getById} from "./util"; + +export function getSection(sectionId) { + return getById("/sections/{sectionId}", {sectionId}); +} diff --git a/src/api/routes/simulations.js b/src/api/routes/simulations.js index 3c7c748e..d65460ee 100644 --- a/src/api/routes/simulations.js +++ b/src/api/routes/simulations.js @@ -1,4 +1,9 @@ import {sendRequest} from "../index"; +import {deleteById, getById} from "./util"; + +export function getSimulation(simulationId) { + return getById("/simulations/{simulationId}", {simulationId}); +} export function addSimulation(simulation) { return sendRequest({ @@ -14,20 +19,6 @@ export function addSimulation(simulation) { }); } -export function getSimulation(simulationId) { - return sendRequest({ - path: "/simulations/{simulationId}", - method: "GET", - parameters: { - body: {}, - path: { - simulationId - }, - query: {} - } - }); -} - export function updateSimulation(simulation) { return sendRequest({ path: "/simulations/{simulationId}", @@ -45,29 +36,13 @@ export function updateSimulation(simulation) { } export function deleteSimulation(simulationId) { - return sendRequest({ - path: "/simulations/{simulationId}", - method: "DELETE", - parameters: { - body: {}, - path: { - simulationId - }, - query: {} - } - }); + return deleteById("/simulations/{simulationId}", {simulationId}); } export function getAuthorizationsBySimulation(simulationId) { - return sendRequest({ - path: "/simulations/{simulationId}/authorizations", - method: "GET", - parameters: { - body: {}, - path: { - simulationId - }, - query: {} - } - }) + return getById("/simulations/{simulationId}/authorizations", {simulationId}); +} + +export function getPathsOfSimulation(simulationId) { + return getById("/simulations/{simulationId}/paths", {simulationId}); } diff --git a/src/api/routes/specifications.js b/src/api/routes/specifications.js new file mode 100644 index 00000000..676d9441 --- /dev/null +++ b/src/api/routes/specifications.js @@ -0,0 +1,57 @@ +import {getAll, getById} from "./util"; + +export function getAllCoolingItems() { + return getAll("/specifications/cooling-items"); +} + +export function getCoolingItem(id) { + return getById("/specifications/cooling-items/{id}", {id}); +} + +export function getAllCPUs() { + return getAll("/specifications/cpus"); +} + +export function getCPU(id) { + return getById("/specifications/cpus/{id}", {id}); +} + +export function getAllFailureModels() { + return getAll("/specifications/failure-models"); +} + +export function getFailureModel(id) { + return getById("/specifications/failure-models/{id}", {id}); +} + +export function getAllGPUs() { + return getAll("/specifications/gpus"); +} + +export function getGPU(id) { + return getById("/specifications/gpus/{id}", {id}); +} + +export function getAllMemories() { + return getAll("/specifications/memories"); +} + +export function getMemory(id) { + return getById("/specifications/memories/{id}", {id}); +} + +export function getAllPSUs() { + return getAll("/specifications/psus"); +} + +export function getPSU(id) { + return getById("/specifications/psus/{id}", {id}); +} + +export function getAllStorages() { + return getAll("/specifications/storages"); +} + +export function getStorage(id) { + return getById("/specifications/storages/{id}", {id}); +} diff --git a/src/api/routes/tiles.js b/src/api/routes/tiles.js new file mode 100644 index 00000000..927a074b --- /dev/null +++ b/src/api/routes/tiles.js @@ -0,0 +1,146 @@ +import {sendRequest} from "../index"; +import {deleteById, getById} from "./util"; + +export function getTile(tileId) { + return getById("/tiles/{tileId}", {tileId}); +} + +export function deleteTile(tileId) { + return deleteById("/tiles/{tileId}", {tileId}); +} + +export function getRackByTile(tileId) { + return getTileObject(tileId, "/rack"); +} + +export function addRackToTile(tileId, rack) { + return addTileObject(tileId, {rack}, "/rack"); +} + +export function updateRackOnTile(tileId, rack) { + return updateTileObject(tileId, {rack}, "/rack"); +} + +export function deleteRackFromTile(tileId) { + return deleteTileObject(tileId, "/rack"); +} + +export function getMachinesOfRackByTile(tileId) { + return getById("/tiles/{tileId}/rack/machines", {tileId}); +} + +export function addMachineToRackOnTile(tileId, machine) { + return sendRequest({ + path: "/tiles/{tileId}/rack/machines", + method: "GET", + parameters: { + body: { + machine + }, + path: { + tileId + }, + query: {} + } + }); +} + +export function updateMachineInRackOnTile(tileId, position, machine) { + return sendRequest({ + path: "/tiles/{tileId}/rack/machines/{position}", + method: "PUT", + parameters: { + body: { + machine + }, + path: { + tileId, + position + }, + query: {} + } + }); +} + +export function deleteMachineInRackOnTile(tileId, position) { + return sendRequest({ + path: "/tiles/{tileId}/rack/machines/{position}", + method: "DELETE", + parameters: { + body: {}, + path: { + tileId, + position + }, + query: {} + } + }); +} + +export function getCoolingItemByTile(tileId) { + return getTileObject(tileId, "/cooling-item"); +} + +export function addCoolingItemToTile(tileId, coolingItemId) { + return addTileObject(tileId, {coolingItemId}, "/cooling-item"); +} + +export function updateCoolingItemOnTile(tileId, coolingItemId) { + return updateTileObject(tileId, {coolingItemId}, "/cooling-item"); +} + +export function deleteCoolingItemFromTile(tileId) { + return deleteTileObject(tileId, "/cooling-item"); +} + +export function getPSUByTile(tileId) { + return getTileObject(tileId, "/psu"); +} + +export function addPSUToTile(tileId, psuId) { + return addTileObject(tileId, {psuId}, "/psu"); +} + +export function updatePSUOnTile(tileId, psuId) { + return updateTileObject(tileId, {psuId}, "/psu"); +} + +export function deletePSUFromTile(tileId) { + return deleteTileObject(tileId, "/psu"); +} + +function getTileObject(tileId, endpoint) { + return getById("/tiles/{tileId}" + endpoint, {tileId}); +} + +function addTileObject(tileId, objectBody, endpoint) { + return sendRequest({ + path: "/tiles/{tileId}" + endpoint, + method: "POST", + parameters: { + body: objectBody, + path: { + tileId + }, + query: {} + } + }); +} + +function updateTileObject(tileId, objectBody, endpoint) { + return sendRequest({ + path: "/tiles/{tileId}" + endpoint, + method: "PUT", + parameters: { + body: objectBody, + path: { + tileId + }, + query: {} + } + }); +} + +function deleteTileObject(tileId, endpoint) { + return deleteById("/tiles/{tileId}" + endpoint, {tileId}); +} diff --git a/src/api/routes/auth.js b/src/api/routes/token-signin.js index 76a39572..76a39572 100644 --- a/src/api/routes/auth.js +++ b/src/api/routes/token-signin.js diff --git a/src/api/routes/users.js b/src/api/routes/users.js index c91e07b2..7b931d66 100644 --- a/src/api/routes/users.js +++ b/src/api/routes/users.js @@ -1,4 +1,5 @@ import {sendRequest} from "../index"; +import {deleteById, getById} from "./util"; export function getUserByEmail(email) { return sendRequest({ @@ -62,29 +63,9 @@ export function updateUser(userId, user) { } export function deleteUser(userId) { - return sendRequest({ - path: "/users/{userId}", - method: "DELETE", - parameters: { - body: {}, - path: { - userId - }, - query: {} - } - }); + return deleteById("/users/{userId}", {userId}); } export function getAuthorizationsByUser(userId) { - return sendRequest({ - path: "/users/{userId}/authorizations", - method: "GET", - parameters: { - body: {}, - path: { - userId - }, - query: {} - } - }); + return getById("/users/{userId}/authorizations", {userId}); } diff --git a/src/api/routes/util.js b/src/api/routes/util.js new file mode 100644 index 00000000..ff21d4f4 --- /dev/null +++ b/src/api/routes/util.js @@ -0,0 +1,37 @@ +import {sendRequest} from "../index"; + +export function getAll(path) { + return sendRequest({ + path, + method: "GET", + parameters: { + body: {}, + path: {}, + query: {} + } + }); +} + +export function getById(path, pathObject) { + return sendRequest({ + path, + method: "GET", + parameters: { + body: {}, + path: pathObject, + query: {} + } + }); +} + +export function deleteById(path, pathObject) { + return sendRequest({ + path, + method: "DELETE", + parameters: { + body: {}, + path: pathObject, + query: {} + } + }); +} diff --git a/src/api/sagas/objects.js b/src/api/sagas/objects.js index fd7830b3..98c766ec 100644 --- a/src/api/sagas/objects.js +++ b/src/api/sagas/objects.js @@ -1,5 +1,5 @@ import {call, put, select} from "redux-saga/effects"; -import {addToSimulationStore, addToUserStore} from "../../actions/objects"; +import {addToStore} from "../../actions/objects"; import {getSimulation} from "../routes/simulations"; import {getUser} from "../routes/users"; @@ -9,16 +9,16 @@ const selectors = { authorization: state => state.objects.authorization, }; -function* fetchAndStoreObject(objectType, id, apiCall, addToStore) { +function* fetchAndStoreObject(objectType, id, apiCall) { const objectStore = yield select(selectors[objectType]); if (!objectStore[id]) { const object = yield apiCall; - yield put(addToStore(object)); + yield put(addToStore(objectType, object)); } } export const fetchAndStoreSimulation = (id) => - fetchAndStoreObject("simulation", id, call(getSimulation, id), addToSimulationStore); + fetchAndStoreObject("simulation", id, call(getSimulation, id)); export const fetchAndStoreUser = (id) => - fetchAndStoreObject("user", id, call(getUser, id), addToUserStore); + fetchAndStoreObject("user", id, call(getUser, id),); diff --git a/src/api/sagas/simulations.js b/src/api/sagas/simulations.js index 9c3bd24c..6b7471c0 100644 --- a/src/api/sagas/simulations.js +++ b/src/api/sagas/simulations.js @@ -1,19 +1,19 @@ import {call, put} from "redux-saga/effects"; -import {addToAuthorizationStore, addToSimulationStore} from "../../actions/objects"; +import {addToStore} from "../../actions/objects"; import {addSimulationSucceeded, deleteSimulationSucceeded} from "../../actions/simulations"; import {addSimulation, deleteSimulation} from "../routes/simulations"; export function* onSimulationAdd(action) { try { const simulation = yield call(addSimulation, {name: action.name}); - yield put(addToSimulationStore(simulation)); + yield put(addToStore("simulation", simulation)); const authorization = { simulationId: simulation.id, userId: action.userId, authorizationLevel: "OWN" }; - yield put(addToAuthorizationStore(authorization)); + yield put(addToStore("authorization", authorization)); yield put(addSimulationSucceeded([authorization.userId, authorization.simulationId])); } catch (error) { console.log(error); diff --git a/src/api/sagas/users.js b/src/api/sagas/users.js index c1daab30..d3bc3f5f 100644 --- a/src/api/sagas/users.js +++ b/src/api/sagas/users.js @@ -3,7 +3,7 @@ import {logInSucceeded} from "../../actions/auth"; import {addToAuthorizationStore} from "../../actions/objects"; import {fetchAuthorizationsOfCurrentUserSucceeded} from "../../actions/users"; import {saveAuthLocalStorage} from "../../auth/index"; -import {performTokenSignIn} from "../routes/auth"; +import {performTokenSignIn} from "../routes/token-signin"; import {addUser, getAuthorizationsByUser} from "../routes/users"; import {fetchAndStoreSimulation, fetchAndStoreUser} from "./objects"; |
