Skip to content

Commit

Permalink
fix(storage-server)!: rename route /all to /storage
Browse files Browse the repository at this point in the history
  • Loading branch information
alimd committed Dec 17, 2022
1 parent a65e6bd commit 2df46a9
Showing 9 changed files with 33 additions and 36 deletions.
2 changes: 1 addition & 1 deletion services/storage-server/demo.http
Original file line number Diff line number Diff line change
@@ -55,7 +55,7 @@ GET {{apiUrl}}/{{apiVersion}}/keys?storage=comments/page1
Authorization: Bearer {{token}}

### Get all data
GET {{apiUrl}}/{{apiVersion}}/all?storage=comments/page1
GET {{apiUrl}}/{{apiVersion}}/storage?name=comments/page1
Authorization: Bearer {{token}}

### === Test other routes and errors ===
2 changes: 1 addition & 1 deletion services/storage-server/src/index.ts
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ import './route/has.js';
import './route/patch.js';
import './route/delete.js';
import './route/keys.js';
import './route/all.js';
import './route/storage.js';
import {logger} from './config.js';

logger.logOther('..:: Alwatr Storage Nanoservice API ::..');
24 changes: 0 additions & 24 deletions services/storage-server/src/route/all.ts

This file was deleted.

4 changes: 2 additions & 2 deletions services/storage-server/src/route/delete.ts
Original file line number Diff line number Diff line change
@@ -15,9 +15,9 @@ async function removeDocument(connection: AlwatrConnection): Promise<void> {
const param = connection.requireQueryParams<{storage: string; id: string}>({storage: 'string', id: 'string'});
if (param === null) return;

const storage = storageProvider.get({name: param.storage});
const storageEngine = storageProvider.get({name: param.storage});

if (storage.delete(param.id) === true) {
if (storageEngine.delete(param.id) === true) {
connection.reply({
ok: true,
data: {},
4 changes: 2 additions & 2 deletions services/storage-server/src/route/get.ts
Original file line number Diff line number Diff line change
@@ -25,9 +25,9 @@ function getDocument(connection: AlwatrConnection): void {
const params = connection.requireQueryParams<{storage: string; id: string}>({storage: 'string', id: 'string'});
if (params == null) return;

const storage = storageProvider.get({name: params.storage});
const storageEngine = storageProvider.get({name: params.storage});

const document = storage.get(params.id, true);
const document = storageEngine.get(params.id, true);

if (document == null) {
return connection.reply({
4 changes: 2 additions & 2 deletions services/storage-server/src/route/has.ts
Original file line number Diff line number Diff line change
@@ -15,10 +15,10 @@ async function has(connection: AlwatrConnection): Promise<void> {
const params = connection.requireQueryParams<{storage: string; id: string}>({storage: 'string', id: 'string'});
if (params == null) return;

const storage = storageProvider.get({name: params.storage});
const storageEngine = storageProvider.get({name: params.storage});

connection.reply({
ok: true,
data: {has: storage.has(params.id)},
data: {has: storageEngine.has(params.id)},
});
}
4 changes: 2 additions & 2 deletions services/storage-server/src/route/keys.ts
Original file line number Diff line number Diff line change
@@ -15,10 +15,10 @@ async function getStorageKeys(connection: AlwatrConnection): Promise<void> {
const params = connection.requireQueryParams<{storage: string}>({storage: 'string'});
if (params == null) return;

const storage = storageProvider.get({name: params.storage});
const storageEngine = storageProvider.get({name: params.storage});

connection.reply({
ok: true,
data: {keys: storage.keys},
data: {keys: storageEngine.keys},
});
}
4 changes: 2 additions & 2 deletions services/storage-server/src/route/patch.ts
Original file line number Diff line number Diff line change
@@ -27,10 +27,10 @@ async function updateDocument(connection: AlwatrConnection): Promise<void> {
});
}

const storage = storageProvider.get({name: param.storage});
const storageEngine = storageProvider.get({name: param.storage});

connection.reply({
ok: true,
data: storage.set(document, true),
data: storageEngine.set(document, true),
});
}
21 changes: 21 additions & 0 deletions services/storage-server/src/route/storage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {config, logger} from '../config.js';
import {nanoServer} from '../lib/nano-server.js';
import {storageProvider} from '../lib/storage-provider.js';

import type {AlwatrConnection} from '@alwatr/nano-server';

nanoServer.route('GET', '/storage', getStorage);

async function getStorage(connection: AlwatrConnection): Promise<void> {
logger.logMethod('getStorage');

const token = connection.requireToken(config.nanoServer.accessToken);
if (token == null) return;

const params = connection.requireQueryParams<{name: string}>({name: 'string'});
if (params == null) return;

const storageEngine = storageProvider.get({name: params.name});

connection.reply(storageEngine._storage);
}

0 comments on commit 2df46a9

Please sign in to comment.