Skip to content

Commit

Permalink
solve backend inconsistencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Polický committed Dec 11, 2023
1 parent 65deec4 commit 382953c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 106 deletions.
100 changes: 37 additions & 63 deletions services/backend/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
import { getDefaultConfiguration } from "./routes/configuration";
import {getDefaultConfiguration} from "./routes/configuration";
import express from "express";
import { PrismaClient } from "@prisma/client";
import { PrismaClient } from '@prisma/client';
import {
addSpecification,
cloneSpecification,
deleteSpecification,
garbageCollection,
importSpecifications,
listSpecifications,
modifySpecification,
addSpecification,
cloneSpecification,
deleteSpecification, garbageCollection, importSpecifications,
listSpecifications,
modifySpecification
} from "./routes/specification";
import { readStore, writeStore } from "./routes/store";
import { LocalStoreModel } from "./models/local-store-model";
import { createDataPsm, deleteDataPsm } from "./routes/dataPsm";
import {readStore, writeStore} from "./routes/store";
import {LocalStoreModel} from "./models/local-store-model";
import {createDataPsm, deleteDataPsm} from "./routes/dataPsm";
import cors from "cors";
import bodyParser from "body-parser";
import { generateBikeshedRoute } from "./routes/bikeshed";
import { DataSpecificationModel } from "./models/data-specification-model";
import { DataSpecificationWithStores } from "@dataspecer/backend-utils/interfaces";
import { convertLocalStoresToHttpStores } from "./utils/local-store-to-http-store";
import {DataSpecificationModel} from "./models/data-specification-model";
import {DataSpecificationWithStores} from "@dataspecer/backend-utils/interfaces";
import {convertLocalStoresToHttpStores} from "./utils/local-store-to-http-store";
import configuration from "./configuration";
import {HttpStoreDescriptor, StoreDescriptor } from "@dataspecer/backend-utils/store-descriptor";
import {HttpStoreDescriptor, StoreDescriptor} from "@dataspecer/backend-utils/store-descriptor";
import {PackageModel} from "./models/package-model";
import {
createPackage, createSemanticModel,
Expand All @@ -31,8 +29,6 @@ import {
updatePackage
} from "./routes/packages";
import {LocalStoreDescriptor} from "./models/local-store-descriptor";
import { asyncHandler } from "./utils/async-handler";
import { getPackage, writePackage } from "./routes/package";

// Create models

Expand All @@ -41,11 +37,11 @@ export const prismaClient = new PrismaClient();
export const dataSpecificationModel = new DataSpecificationModel(storeModel, prismaClient,"https://ofn.gov.cz/data-specification/{}");
export const packageModel = new PackageModel(storeModel, prismaClient);

export const storeApiUrl = configuration.host + "/store/{}";
export const storeApiUrl = configuration.host + '/store/{}';

let basename = new URL(configuration.host).pathname;
if (basename.endsWith("/")) {
basename = basename.slice(0, -1);
if (basename.endsWith('/')) {
basename = basename.slice(0, -1);
}

export function convertStores(stores: LocalStoreDescriptor[]): StoreDescriptor[] {
Expand All @@ -64,32 +60,19 @@ export function replaceStoreDescriptorsInDataSpecification<T extends DataSpecifi

const application = express();
application.use(cors());
application.use(bodyParser.json({ limit: configuration.payloadSizeLimit }));
application.use(
bodyParser.urlencoded({
extended: false,
limit: configuration.payloadSizeLimit,
})
);
application.use(
bodyParser.urlencoded({
extended: true,
limit: configuration.payloadSizeLimit,
})
);

application.get(basename + "/data-specification", listSpecifications);
application.post(basename + "/data-specification", addSpecification);
application.post(basename + "/data-specification/clone", cloneSpecification);
application.delete(basename + "/data-specification", deleteSpecification);
application.put(basename + "/data-specification", modifySpecification);
application.post(
basename + "/data-specification/garbage-collection",
garbageCollection
);

application.post(basename + "/data-specification/data-psm", createDataPsm);
application.delete(basename + "/data-specification/data-psm", deleteDataPsm);
application.use(bodyParser.json({limit: configuration.payloadSizeLimit}));
application.use(bodyParser.urlencoded({ extended: false, limit: configuration.payloadSizeLimit }));
application.use(bodyParser.urlencoded({ extended: true, limit: configuration.payloadSizeLimit }));

application.get(basename + '/data-specification', listSpecifications);
application.post(basename + '/data-specification', addSpecification);
application.post(basename + '/data-specification/clone', cloneSpecification);
application.delete(basename + '/data-specification', deleteSpecification);
application.put(basename + '/data-specification', modifySpecification);
application.post(basename + '/data-specification/garbage-collection', garbageCollection);

application.post(basename + '/data-specification/data-psm', createDataPsm);
application.delete(basename + '/data-specification/data-psm', deleteDataPsm);

application.post(basename + '/import', importSpecifications);

Expand All @@ -104,27 +87,18 @@ application.post(basename + '/packages/semantic-models', createSemanticModel);

// Configuration

application.get(basename + "/default-configuration", getDefaultConfiguration);
application.get(basename + '/default-configuration', getDefaultConfiguration);

// API for reading and writing store content.

application.get(basename + "/store/:storeId", readStore);
application.put(basename + "/store/:storeId", writeStore);
application.get(basename + '/store/:storeId', readStore);
application.put(basename + '/store/:storeId', writeStore);

// API for generators

application.post(
basename + "/transformer/bikeshed",
bodyParser.text({ type: "*/*", limit: configuration.payloadSizeLimit }),
generateBikeshedRoute
);

application.get(basename + "/packages", getPackage);
application.post(basename + "/packages", writePackage);
application.post(basename + '/transformer/bikeshed', bodyParser.text({type:"*/*", limit: configuration.payloadSizeLimit}), generateBikeshedRoute);

application.listen(Number(configuration.port), () => {
console.log(`Server is listening on port ${Number(configuration.port)}.`);
console.log(
`Try ${configuration.host}/data-specification for a list of data specifications. (should return "[]" for new instances) Hmm?`
);
});
console.log(`Server is listening on port ${Number(configuration.port)}.`);
console.log(`Try ${configuration.host}/data-specification for a list of data specifications. (should return "[]" for new instances)`);
});
42 changes: 0 additions & 42 deletions services/backend/src/routes/package.ts

This file was deleted.

2 changes: 1 addition & 1 deletion services/backend/src/routes/packages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,4 @@ export const createSemanticModel = asyncHandler(async (request: express.Request,
models.push(storeDescriptor);
await packageModel.setSemanticModels(packageId, models);
response.send(storeDescriptor);
});
});

0 comments on commit 382953c

Please sign in to comment.