-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Base design for the intended REST api functions
- Loading branch information
1 parent
7ebe079
commit 76b1d24
Showing
7 changed files
with
378 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
}; | ||
testEnvironment: 'node' | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
"watch": ["src"], | ||
"ext": "ts", | ||
"exec": "node --inspect -r ts-node/register ./src/server.ts" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
import { Type } from '@sinclair/typebox'; | ||
import { FastifyPluginCallback, FastifyRequest } from 'fastify'; | ||
import { NewProduction, Production, SdpOffer, SdpAnswer } from './models'; | ||
|
||
const apiProductions: FastifyPluginCallback = (fastify, opts, next) => { | ||
fastify.post<{ | ||
Body: typeof NewProduction; | ||
Reply: typeof Production; | ||
}>( | ||
'/production', | ||
{ | ||
schema: { | ||
description: 'Create a new Production resource.', | ||
body: NewProduction, | ||
response: { | ||
200: Production | ||
} | ||
} | ||
}, | ||
async (request, reply) => { | ||
try { | ||
//prod = new Production(name, [line1, line2, line3]) | ||
//Production construction will make calls to smb and set up each line. | ||
} catch (err) { | ||
//error handling | ||
} | ||
} | ||
); | ||
|
||
fastify.get<{ | ||
Params: { id: string }; | ||
Reply: any; | ||
}>( | ||
'/production', | ||
{ | ||
schema: { | ||
description: 'Retrieves all Production resource.', | ||
response: { | ||
200: Type.Array(Production) | ||
} | ||
} | ||
}, | ||
async (request, reply) => { | ||
try { | ||
//request logic | ||
} catch (err) { | ||
//error handling | ||
} | ||
} | ||
); | ||
|
||
fastify.get<{ | ||
Params: { id: string }; | ||
Reply: any; | ||
}>( | ||
'/productions/:id', | ||
{ | ||
schema: { | ||
description: 'Retrieves a Production resource.', | ||
response: { | ||
200: Production | ||
} | ||
} | ||
}, | ||
async (request, reply) => { | ||
try { | ||
//request logic | ||
} catch (err) { | ||
//error handling | ||
} | ||
} | ||
); | ||
|
||
fastify.delete<{ | ||
Params: { id: string }; | ||
Reply: string; | ||
}>( | ||
'/productions/:id', | ||
{ | ||
schema: { | ||
description: 'Delete a Production resource.', | ||
response: { | ||
200: Type.Object({ | ||
message: Type.Literal('removed') | ||
}) | ||
} | ||
} | ||
}, | ||
async (request, reply) => { | ||
try { | ||
//request logic | ||
} catch (err) { | ||
//error handling | ||
} | ||
} | ||
); | ||
|
||
fastify.post<{ | ||
Params: { id: string; name: string }; | ||
Body: typeof SdpOffer; | ||
Reply: typeof SdpAnswer; | ||
}>( | ||
'/productions/:id/lines/:name', | ||
{ | ||
schema: { | ||
description: 'Join a Production line.', | ||
body: SdpOffer, | ||
response: { | ||
200: SdpAnswer | ||
} | ||
} | ||
}, | ||
async (request, reply) => { | ||
try { | ||
//Generate SDP, and anything other information required to set up a connection. | ||
} catch (err) { | ||
//error handling | ||
} | ||
} | ||
); | ||
|
||
next(); | ||
}; |
Oops, something went wrong.