This repository was archived by the owner on Feb 7, 2023. It is now read-only.
File tree Expand file tree Collapse file tree
contracts/forum-contracts/src/contracts/requests Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import { createPostContract } from '@swarmion-starter/forum-contracts' ;
2+ import {
3+ getHandlerPath ,
4+ LambdaFunction ,
5+ } from '@swarmion-starter/serverless-helpers' ;
6+
7+ const config : LambdaFunction = {
8+ environment : { } ,
9+ handler : getHandlerPath ( __dirname ) ,
10+ events : [ createPostContract . trigger ] ,
11+ } ;
12+
13+ export default config ;
Original file line number Diff line number Diff line change 1+ {
2+ "pathParameters" : { "threadId" : " fooBar" },
3+ "body" : { "content" : " Hello, I am Swarmion!" }
4+ }
Original file line number Diff line number Diff line change 1+ import { handler } from './handler' ;
2+
3+ describe ( 'createPost handler' , ( ) => {
4+ it ( 'should return a post with the created content' , async ( ) => {
5+ const postContent = 'Hello from Swarmion' ;
6+
7+ const { content } = await handler ( {
8+ pathParameters : { threadId : 'blob' } ,
9+ body : { content : postContent } ,
10+ } ) ;
11+
12+ expect ( content ) . toEqual ( postContent ) ;
13+ } ) ;
14+ } ) ;
Original file line number Diff line number Diff line change 1+ import { createPostContract } from '@swarmion-starter/forum-contracts' ;
2+ import { applyHttpMiddlewares } from '@swarmion-starter/serverless-helpers' ;
3+
4+ export const handler = createPostContract . handler ( async event => {
5+ const { threadId } = event . pathParameters ;
6+ const { content } = event . body ;
7+
8+ await Promise . resolve ( { threadId } ) ;
9+
10+ return {
11+ id : 'myFirstPost' ,
12+ createdAt : '2021-10-25T12:12:00Z' ,
13+ editedAt : null ,
14+ content,
15+ authorId : 'author2' ,
16+ } ;
17+ } ) ;
18+
19+ export const main = applyHttpMiddlewares ( handler , {
20+ inputSchema : createPostContract . inputSchema ,
21+ } ) ;
Original file line number Diff line number Diff line change 1+ import createPost from './createPost/config' ;
12import getThreadAndPosts from './getThreadAndPosts/config' ;
23
3- export const functions = { getThreadAndPosts } ;
4+ export const functions = { getThreadAndPosts, createPost } ;
Original file line number Diff line number Diff line change 1+ import { ApiGatewayContract } from '@swarmion/serverless-contracts' ;
2+
3+ import { postEntitySchema } from 'contracts/entities' ;
4+
5+ const pathParametersSchema = {
6+ type : 'object' ,
7+ properties : {
8+ threadId : { type : 'string' } ,
9+ } ,
10+ required : [ 'threadId' ] ,
11+ additionalProperties : false ,
12+ } as const ;
13+
14+ const bodySchema = {
15+ type : 'object' ,
16+ properties : {
17+ content : { type : 'string' } ,
18+ } ,
19+ required : [ 'content' ] ,
20+ additionalProperties : false ,
21+ } as const ;
22+
23+ export const createPostContract = new ApiGatewayContract ( {
24+ id : 'forum-createPost' ,
25+ path : '/forum/thread/{threadId}' ,
26+ method : 'POST' ,
27+ integrationType : 'httpApi' ,
28+ pathParametersSchema,
29+ queryStringParametersSchema : undefined ,
30+ bodySchema,
31+ headersSchema : undefined ,
32+ outputSchema : postEntitySchema ,
33+ } ) ;
Original file line number Diff line number Diff line change 11export * from './getThreadWithPosts' ;
2+ export * from './createPost' ;
You can’t perform that action at this time.
0 commit comments