Write a Simple API that can:
- Create a user and register books that he/she owns
- Transfer book ownership
- Use AWS API Gateway with Lambda functions
- Use Dynamodb as the DB
POST /users
{
// list of book ids this owner owns
"books": ["book_1", "book_2"]
}
{
// generate a unique user id
"user_id": "user_0001",
"books": ["book_1", "book_2"],
}
- User shouldn't be created if:
- "book_ids" contains a book_id that is already owned by another user
GET /users/<user_id>
{
"user_id": "user_0001",
"book": ["book_1", "book_2"],
}
GET /books
{
"books": [
{
"id": "book_1",
"owner": "user_001"
},
{
"id": "book_2",
"owner": "user_001"
},
{
"id": "book_3",
"owner": "user_002"
}
]
}
GET /books/<book_id>
{
"id": "book_1",
"owner": "user_001"
}
POST /transfer
{
"book_id": "book_1",
"from": "user_001",
"to": "user_002"
}
{
"id": "book_1",
"owner": "user_002"
}
- Transfer should fail if:
- book doesn't exist
from
user_id
doesn't match the correct ownerto == from
to
user_id
doesn't exist
Submit the following
- github repository containing:
- all the code for the lambda functions
- script that creates two users and transfers books between them (more test scenarios can be added)
- instructions on how to run the script
- please document your code appropriately