Skip to content

Commit

Permalink
Merge pull request #221 from Rakshitha-D/connector_list
Browse files Browse the repository at this point in the history
#OBS-I145: Connector Read api
  • Loading branch information
HarishGangula authored Aug 1, 2024
2 parents 5fe497b + bed4798 commit 508c9b2
Show file tree
Hide file tree
Showing 6 changed files with 549 additions and 94 deletions.
226 changes: 192 additions & 34 deletions api-service/postman-collection/updated_v2_collection.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ResponseHandler } from "../../helpers/ResponseHandler";
import httpStatus from "http-status";
import { connectorService } from "../../services/ConnectorService";

const defaultFields = ["id", "connector_id", "name", "type", "category", "version", "description", "technology", "runtime", "licence", "owner", "iconurl", "status", "created_by", "updated_by", "created_date", "updated_date"];
const defaultFields = ["id", "connector_id", "name", "type", "category", "version", "description", "technology", "runtime", "licence", "owner", "iconurl", "status", "created_by", "updated_by", "created_date", "updated_date", "live_date"];

const validateRequest = (req: Request) => {
const isRequestValid: Record<string, any> = schemaValidation(req.body, ConnectorListSchema)
Expand Down
22 changes: 22 additions & 0 deletions api-service/src/controllers/ConnectorsRead/ConnectorsRead.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Request, Response } from "express";
import { obsrvError } from "../../types/ObsrvError";
import { ResponseHandler } from "../../helpers/ResponseHandler";
import httpStatus from "http-status";
import { connectorService } from "../../services/ConnectorService";
import _ from "lodash";

const defaultFields = ["id", "connector_id", "name", "type", "category", "version", "description", "licence", "owner", "iconurl", "status", "ui_spec", "created_by", "updated_by", "created_date", "updated_date", "live_date"];

const connectorsRead = async (req: Request, res: Response) => {
const { id } = req.params;
const { mode } = req.query;
const isEditMode = _.toLower(_.toString(mode)) === "edit"
const status = isEditMode ? "Draft" : "Live"
const connector = await connectorService.getConnector({ id, status }, defaultFields)
if (!connector) {
throw obsrvError("", "CONNECTOR_NOT_FOUND", `Connector not found: ${id}`, "NOT_FOUND", 404);
}
ResponseHandler.successResponse(req, res, { status: httpStatus.OK, data: connector });
}

export default connectorsRead;
2 changes: 2 additions & 0 deletions api-service/src/routes/Router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import datasetReset from "../controllers/DatasetReset/DatasetReset";
import DatasetExport from "../controllers/DatasetExport/DatasetExport";
import DatasetCopy from "../controllers/DatasetCopy/DatasetCopy";
import ConnectorsList from "../controllers/ConnectorsList/ConnectorsList";
import ConnectorsRead from "../controllers/ConnectorsRead/ConnectorsRead";
import DatasetImport from "../controllers/DatasetImport/DatasetImport";

export const router = express.Router();
Expand All @@ -51,6 +52,7 @@ router.post("/datasets/dataschema", setDataToRequestObject("api.datasets.datasch
router.get("/datasets/export/:dataset_id", setDataToRequestObject("api.datasets.export"), onRequest({ entity: Entity.Management }), DatasetExport);
router.post("/datasets/copy", setDataToRequestObject("api.datasets.copy"), onRequest({ entity: Entity.Management }), DatasetCopy);
router.post("/connectors/list", setDataToRequestObject("api.connectors.list"), onRequest({ entity: Entity.Management }), ConnectorsList);
router.get("/connectors/read/:id", setDataToRequestObject("api.connectors.read"), onRequest({entity: Entity.Management }), ConnectorsRead);
router.post("/datasets/import", setDataToRequestObject("api.datasets.import"), onRequest({ entity: Entity.Management }), DatasetImport);

//Wrapper Service
Expand Down
6 changes: 5 additions & 1 deletion api-service/src/services/ConnectorService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ import { ConnectorRegistry } from "../models/ConnectorRegistry";

class ConnectorService {

findConnectors = async (where?: Record<string, any>, attributes?: string[]): Promise<any> => {
findConnectors = (where?: Record<string, any>, attributes?: string[]): Promise<any> => {
return ConnectorRegistry.findAll({ where, attributes, raw: true });
}

getConnector = (where?: Record<string, any>, attributes?: string[]): Promise<any> => {
return ConnectorRegistry.findOne({ where, attributes, raw: true });
}

}

export const connectorService = new ConnectorService();
Loading

0 comments on commit 508c9b2

Please sign in to comment.