Skip to content

Instantly share code, notes, and snippets.

@yoheioka
Last active November 23, 2019 02:07
Show Gist options
  • Save yoheioka/1c91c97cee7d8c7b3c2842161c645952 to your computer and use it in GitHub Desktop.
Save yoheioka/1c91c97cee7d8c7b3c2842161c645952 to your computer and use it in GitHub Desktop.

Task:

Write a Simple API that can:

  • Create a user and register books that he/she owns
  • Transfer book ownership

Requirements:

  • Use AWS API Gateway with Lambda functions
  • Use Dynamodb as the DB

Basic API requirements:

1. Initializing a user

Endpoint:

POST /users

Request Body:

{
    // list of book ids this owner owns
    "books": ["book_1", "book_2"]
}

Response:

{
    // generate a unique user id
    "user_id": "user_0001",
    "books": ["book_1", "book_2"],
}

Exception:

  • User shouldn't be created if:
    • "book_ids" contains a book_id that is already owned by another user

2. Get User

Endpoint:

GET /users/<user_id>

Response:

{
    "user_id": "user_0001",
    "book": ["book_1", "book_2"],
}

3. Get all books

Endpoint:

GET /books

Response:

{
    "books": [
        {
            "id": "book_1",
            "owner": "user_001"
        },
        {
            "id": "book_2",
            "owner": "user_001"
        },
        {
            "id": "book_3",
            "owner": "user_002"
        }
    ]
}

4. Get a specific book

Endpoint:

GET /books/<book_id>

Response:

{
    "id": "book_1",
    "owner": "user_001"
}

5. Transfer book ownership

Endpoint:

POST /transfer

Request Body:

{
    "book_id": "book_1",
    "from": "user_001",
    "to": "user_002"
}

Response:

{
    "id": "book_1",
    "owner": "user_002"
}

Exception:

  • Transfer should fail if:
    • book doesn't exist
    • from user_id doesn't match the correct owner
    • to == from
    • to user_id doesn't exist

Submission:

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment