Skip to content
This repository has been archived by the owner on Jan 21, 2024. It is now read-only.

Commit

Permalink
feat: create projects and datasets
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahd-3hd committed Jan 21, 2024
1 parent 28f8e03 commit 5ab6342
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 2 deletions.
25 changes: 25 additions & 0 deletions src/controllers/dataset.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { NextFunction, Request, Response } from "express";
import { DatasetModel } from "../models/Dataset.model";

export const createDataset = async (
req: Request,
res: Response,
next: NextFunction
) => {
try {
const { name, workspace, project } = req.body;

const dataset = await DatasetModel.create({
name,
workspace,
project,
});

res.status(201).json({
dataset,
message: "Dataset created",
});
} catch (error) {
next(error);
}
};
24 changes: 24 additions & 0 deletions src/controllers/project.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { NextFunction, Request, Response } from "express";
import { ProjectModel } from "../models/Project.model";

export const createProject = async (
req: Request,
res: Response,
next: NextFunction
) => {
try {
const { name, workspace } = req.body;

const project = await ProjectModel.create({
name,
workspace,
});

res.status(201).json({
project,
message: "Project created",
});
} catch (error) {
next(error);
}
};
2 changes: 0 additions & 2 deletions src/controllers/workspace.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ export const createWorkspace = async (
const { userid } = req.headers;
const { name } = req.body;

console.log(userid);

const workspace = await WorkspaceModel.create({
name,
owner: parseInt(userid as string),
Expand Down
7 changes: 7 additions & 0 deletions src/middlewares/schemas/createDataset.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { z } from "zod";

export const createDatasetSchema = z.object({
name: z.string(),
workspace: z.number(),
project: z.number(),
});
6 changes: 6 additions & 0 deletions src/middlewares/schemas/createProject.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { z } from "zod";

export const createProjectSchema = z.object({
name: z.string(),
workspace: z.number(),
});
10 changes: 10 additions & 0 deletions src/routers/dataset.router.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Router } from "express";
import { validate } from "../middlewares/validate";
import { createDataset } from "../controllers/dataset.controller";
import { createDatasetSchema } from "../middlewares/schemas/createDataset.schema";

const router = Router();

router.post("", validate(createDatasetSchema), createDataset);

export default router;
7 changes: 7 additions & 0 deletions src/routers/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import { Router } from "express";
import workspaceRouter from "./workspace.router";
import projectRouter from "./project.router";
import datasetRouter from "./dataset.router";

const router = Router();

// /api/v1/workspace
router.use("/workspace", workspaceRouter);

// /api/v1/project
router.use("/project", projectRouter);

// /api/v1/dataset
router.use("/dataset", datasetRouter);
export default router;
10 changes: 10 additions & 0 deletions src/routers/project.router.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Router } from "express";
import { createProject } from "../controllers/project.controller";
import { validate } from "../middlewares/validate";
import { createProjectSchema } from "../middlewares/schemas/createProject.schema";

const router = Router();

router.post("", validate(createProjectSchema), createProject);

export default router;

0 comments on commit 5ab6342

Please sign in to comment.