Skip to content

Commit

Permalink
Added types for notebookimage and status
Browse files Browse the repository at this point in the history
Updated with REST api notebook image endpoints and new notebook image types.
  • Loading branch information
dlabaj committed Mar 18, 2022
1 parent f34a2bb commit 660f6a3
Show file tree
Hide file tree
Showing 5 changed files with 190 additions and 4 deletions.
60 changes: 60 additions & 0 deletions backend/src/routes/api/notebook/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { FastifyInstance, FastifyReply, FastifyRequest } from 'fastify';
import {
addNotebook,
deleteNotebook,
getNotebook,
getNotebooks,
updateNotebook,
} from './notebooksUtils';

export default async (fastify: FastifyInstance): Promise<void> => {
fastify.get('/', async (request: FastifyRequest, reply: FastifyReply) => {
return getNotebooks(fastify)
.then((res) => {
return res;
})
.catch((res) => {
reply.send(res);
});
});

fastify.get('/:notebook', async (request: FastifyRequest, reply: FastifyReply) => {
return getNotebook(fastify, request)
.then((res) => {
return res;
})
.catch((res) => {
reply.send(res);
});
});

fastify.delete('/:notebook', async (request: FastifyRequest, reply: FastifyReply) => {
return deleteNotebook(fastify, request)
.then((res) => {
return res;
})
.catch((res) => {
reply.send(res);
});
});

fastify.put('/:notebook', async (request: FastifyRequest, reply: FastifyReply) => {
return updateNotebook(fastify, request)
.then((res) => {
return res;
})
.catch((res) => {
reply.send(res);
});
});

fastify.post('/', async (request: FastifyRequest, reply: FastifyReply) => {
return addNotebook(fastify, request)
.then((res) => {
return res;
})
.catch((res) => {
reply.send(res);
});
});
};
86 changes: 86 additions & 0 deletions backend/src/routes/api/notebook/notebooksUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { FastifyRequest } from 'fastify';
import { KubeFastifyInstance, Notebook } from '../../../types';

export const getNotebooks = async (
fastify: KubeFastifyInstance,
): Promise<{ notebooks: Notebook[]; error: string }> => {
const notebooks: Notebook[] = [];
// const coreV1Api = fastify.kube.coreV1Api;
// const namespace = fastify.kube.namespace;
try {
return { notebooks: notebooks, error: null };
} catch (e) {
if (e.response?.statusCode !== 404) {
fastify.log.error('Unable to retrieve notebook image(s): ' + e.toString());
return { notebooks: null, error: 'Unable to retrieve notebook image(s): ' + e.message };
}
}
};

export const getNotebook = async (
fastify: KubeFastifyInstance,
request: FastifyRequest,
): Promise<{ notebooks: Notebook; error: string }> => {
const notebook: Notebook = {
name: '',
repo: '',
};
// const coreV1Api = fastify.kube.coreV1Api;
// const namespace = fastify.kube.namespace;
try {
return { notebooks: notebook, error: null };
} catch (e) {
if (e.response?.statusCode !== 404) {
fastify.log.error('Unable to retrieve notebook image(s): ' + e.toString());
return { notebooks: null, error: 'Unable to retrieve notebook image(s): ' + e.message };
}
}
};

export const addNotebook = async (
fastify: KubeFastifyInstance,
request: FastifyRequest,
): Promise<{ success: boolean; error: string }> => {
// const coreV1Api = fastify.kube.coreV1Api;
// const namespace = fastify.kube.namespace;
try {
return { success: true, error: null };
} catch (e) {
if (e.response?.statusCode !== 404) {
fastify.log.error('Unable to add notebook image: ' + e.toString());
return { success: false, error: 'Unable to add notebook image: ' + e.message };
}
}
};

export const deleteNotebook = async (
fastify: KubeFastifyInstance,
request: FastifyRequest,
): Promise<{ success: boolean; error: string }> => {
// const coreV1Api = fastify.kube.coreV1Api;
// const namespace = fastify.kube.namespace;
try {
return { success: true, error: null };
} catch (e) {
if (e.response?.statusCode !== 404) {
fastify.log.error('Unable to update notebook image: ' + e.toString());
return { success: false, error: 'Unable to update notebook image: ' + e.message };
}
}
};

export const updateNotebook = async (
fastify: KubeFastifyInstance,
request: FastifyRequest,
): Promise<{ success: boolean; error: string }> => {
// const coreV1Api = fastify.kube.coreV1Api;
// const namespace = fastify.kube.namespace;
try {
return { success: true, error: null };
} catch (e) {
if (e.response?.statusCode !== 404) {
fastify.log.error('Unable to update notebook image: ' + e.toString());
return { success: false, error: 'Unable to update notebook image: ' + e.message };
}
}
};
4 changes: 0 additions & 4 deletions backend/src/routes/api/status/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ type groupObjResponse = {
users: string[];
};

type groupObjResponse = {
users: string[];
};

const status = async (
fastify: KubeFastifyInstance,
request: FastifyRequest,
Expand Down
22 changes: 22 additions & 0 deletions backend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,25 @@ export type BuildStatus = {
status: BUILD_PHASE;
timestamp?: string;
};

export enum NotebookStatus {
VALIDITING,
SUCCESS,
FAILED
}

export type Notebook = {
name: string;
repo: string;
description?: string;
status?: NotebookStatus;
user?: string;
uploaded?: Date;
visible?: boolean;
packages?: NotebookPackage[];
}

export type NotebookPackage = {
name: string;
version :string;
}
22 changes: 22 additions & 0 deletions frontend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,25 @@ export type BuildStatus = {
status: BUILD_PHASE;
timestamp: string;
};

export enum NotebookStatus {
VALIDITING,
SUCCESS,
FAILED,
}

export type Notebook = {
name: string;
repo: string;
description?: string;
status?: NotebookStatus;
user?: string;
uploaded?: Date;
visible?: boolean;
packages?: NotebookPackage[];
};

export type NotebookPackage = {
name: string;
version: string;
};

0 comments on commit 660f6a3

Please sign in to comment.