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:
|
functions:
|
||||||
hello:
|
hello:
|
||||||
handler: handlers/hello/get.hello
|
handler: handlers/courses/get.default
|
||||||
events:
|
events:
|
||||||
- http:
|
- http:
|
||||||
path: hello
|
path: courses
|
||||||
method: get
|
method: get
|
||||||
|
cors: true
|
||||||
|
|
||||||
# The following are a few example events you can configure
|
# The following are a few example events you can configure
|
||||||
# NOTE: Please make sure to change your handler code to work with those events
|
# NOTE: Please make sure to change your handler code to work with those events
|
||||||
@@ -107,6 +108,20 @@ functions:
|
|||||||
# NewOutput:
|
# NewOutput:
|
||||||
# Description: "Description for the output"
|
# Description: "Description for the output"
|
||||||
# Value: "Some output value"
|
# 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:
|
plugins:
|
||||||
- serverless-offline
|
- serverless-offline
|
||||||
@@ -25,7 +25,7 @@ const queryByID = async (tableName, idKeyName, id) => {
|
|||||||
// querying by id can be used when we are querying a table
|
// 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
|
// that has a sortKey, but we don't need to use the sortKey
|
||||||
const res = await dynamoClient.query({
|
const res = await dynamoClient.query({
|
||||||
TableName: "gt_answers",
|
TableName: tableName,
|
||||||
KeyConditionExpression: "#id = :idValue",
|
KeyConditionExpression: "#id = :idValue",
|
||||||
ExpressionAttributeNames: {
|
ExpressionAttributeNames: {
|
||||||
"#id": idKeyName,
|
"#id": idKeyName,
|
||||||
|
|||||||
@@ -1,29 +1,12 @@
|
|||||||
const answerSchema = {
|
// const answerSchema = {
|
||||||
"type": "object",
|
// "type": "object",
|
||||||
"properties": {
|
// "properties": {
|
||||||
"user_id": {"type": "string"},
|
// "user_id": {"type": "string"},
|
||||||
"question_id": {"type": "string"},
|
// "question_id": {"type": "string"},
|
||||||
"is_correct": {"type": "boolean"}
|
// "is_correct": {"type": "boolean"}
|
||||||
},
|
// },
|
||||||
"required": ["user_id", "question_id", "is_correct"]
|
// "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"]
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
answerSchema,
|
answerSchema,
|
||||||
|
|||||||
Reference in New Issue
Block a user