WIP on courses get function
This commit is contained in:
15
handlers/courses/get.js
Normal file
15
handlers/courses/get.js
Normal file
@@ -0,0 +1,15 @@
|
||||
const {createResponse} = require('../../helpers');
|
||||
const db = require('../../services/db');
|
||||
|
||||
module.exports.default = async () => {
|
||||
try {
|
||||
const courses = await db.get('eg_courses', {});
|
||||
|
||||
return createResponse(200, {
|
||||
courses: courses
|
||||
})
|
||||
} catch (err) {
|
||||
const statusCode = (err && err.statusCode) || 500;
|
||||
return createResponse(statusCode, err.message || err);
|
||||
}
|
||||
};
|
||||
@@ -1,14 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
module.exports.hello = async (event, context) => {
|
||||
return {
|
||||
statusCode: 200,
|
||||
body: JSON.stringify({
|
||||
message: 'Go Serverless v1.0! Your function executed successfully!',
|
||||
input: event,
|
||||
}),
|
||||
};
|
||||
|
||||
// Use this code if you don't use the http event with the LAMBDA-PROXY integration
|
||||
// return { message: 'Go Serverless v1.0! Your function executed successfully!', event };
|
||||
};
|
||||
@@ -57,11 +57,12 @@ provider:
|
||||
|
||||
functions:
|
||||
hello:
|
||||
handler: handlers/hello/get.hello
|
||||
handler: handlers/courses/get.default
|
||||
events:
|
||||
- http:
|
||||
path: hello
|
||||
path: courses
|
||||
method: get
|
||||
cors: true
|
||||
|
||||
# The following are a few example events you can configure
|
||||
# NOTE: Please make sure to change your handler code to work with those events
|
||||
@@ -107,6 +108,20 @@ functions:
|
||||
# NewOutput:
|
||||
# Description: "Description for the output"
|
||||
# Value: "Some output value"
|
||||
resources:
|
||||
coursesTable:
|
||||
Type: AWS::DynamoDB::Table
|
||||
Properties:
|
||||
TableName: eg_courses
|
||||
AttributeDefinitions:
|
||||
- AttributeName: name
|
||||
AttributeType: s
|
||||
KeySchema:
|
||||
- AttributeName: name
|
||||
KeyType: HASH
|
||||
Tags:
|
||||
- Key: app
|
||||
Value: ecs-grader
|
||||
|
||||
plugins:
|
||||
- serverless-offline
|
||||
@@ -25,7 +25,7 @@ const queryByID = async (tableName, idKeyName, id) => {
|
||||
// querying by id can be used when we are querying a table
|
||||
// that has a sortKey, but we don't need to use the sortKey
|
||||
const res = await dynamoClient.query({
|
||||
TableName: "gt_answers",
|
||||
TableName: tableName,
|
||||
KeyConditionExpression: "#id = :idValue",
|
||||
ExpressionAttributeNames: {
|
||||
"#id": idKeyName,
|
||||
|
||||
@@ -1,29 +1,12 @@
|
||||
const answerSchema = {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"user_id": {"type": "string"},
|
||||
"question_id": {"type": "string"},
|
||||
"is_correct": {"type": "boolean"}
|
||||
},
|
||||
"required": ["user_id", "question_id", "is_correct"]
|
||||
};
|
||||
|
||||
const userSchema = {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {"type": "string"},
|
||||
"score": {"type": "number"}
|
||||
},
|
||||
"required": ["user_id", "question_id", "is_correct"]
|
||||
};
|
||||
|
||||
const loginFollowUpSchema = {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"accessToken": {"type": "string"}
|
||||
},
|
||||
"required": ["accessToken"]
|
||||
};
|
||||
// const answerSchema = {
|
||||
// "type": "object",
|
||||
// "properties": {
|
||||
// "user_id": {"type": "string"},
|
||||
// "question_id": {"type": "string"},
|
||||
// "is_correct": {"type": "boolean"}
|
||||
// },
|
||||
// "required": ["user_id", "question_id", "is_correct"]
|
||||
// };
|
||||
|
||||
module.exports = {
|
||||
answerSchema,
|
||||
|
||||
Reference in New Issue
Block a user