Skip to content

Commit

Permalink
Update Reame with Endpoint documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmadabdulnasir committed Jun 16, 2022
1 parent 8354a61 commit 9f81994
Show file tree
Hide file tree
Showing 3 changed files with 175 additions and 6 deletions.
169 changes: 169 additions & 0 deletions backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,172 @@ There are `@TODO` comments throughout the `./backend/src`. We recommend tackling

1. `./src/auth/auth.py`
2. `./src/api.py`


## Endpoint Documentation

### GET `/drinks`
- Request arguments: None.
- Response: An object with these keys:
- `drinks`: Contains a object of `id` and `recipe:list of key value pairs`.

```json
{
"drinks": [
{
"id": 1,
"recipe": [
{
"color": "blue",
"parts": 1
}
],
"title": "water"
},
{
"id": 2,
"recipe": [
{
"color": "yellow",
"parts": 1
}
],
"title": "Tuwo"
},
{
"id": 3,
"recipe": [
{
"color": "brown",
"parts": 1
}
],
"title": "Miya"
},
{
"id": 4,
"recipe": [
{
"color": "ash",
"parts": 1
}
],
"title": "Cola"
}
],
"success": true
}
```


### GET `/drinks-detail`
- Require Authentication.
- Response: An object with these keys:
- `drinks`: Contains a object of `id` and `recipe:list of key value pairs`.

```json
{
"drinks": [
{
"id": 1,
"recipe": [
{
"color": "blue",
"name": "water",
"parts": 1
}
],
"title": "water"
},
{
"id": 2,
"recipe": [
{
"color": "blue",
"parts": 1
}
],
"title": "Tuwo"
}
],
"success": true
}
```

### POST `/drinks`
- Require Authentication.
- Request Body:
- `title` (char) - The Title
- `recipe` (list) - list containing objects of recipe
- Request Body SAMPLE:
```json
{
"title": "Cola",
"recipe": [
{
"color": "ash",
"parts": 1
}
]
}
```
- Response: An object with these keys:
- `drinks`: Contains a object of `id` and `recipe:list of key value pairs`.
```json
{
"drinks": [
{
"id": 4,
"recipe": [
{
"color": "ash",
"parts": 1
}
],
"title": "Cola"
}
],
"success": true
}
```

### PATCH `/drinks/<int:id>`
- Require Authentication.
- Request Argument:
- `id` (int) ID of the Intended drink to update
- Request Body:
- Object with key value pair of what to update
- Response:
- Returns the updated instance and success flag

```json
{
"drinks": [
{
"id": 2,
"recipe": [
{
"color": "yellow",
"parts": 1
}
],
"title": "Sabon title"
}
],
"success": true
}
```


### DELETE `/drinks/<int:id>`
- Require Authentication.
- Request Argument:
- `id` (int) ID of the Intended drink to update
- Response:
- Returns the delete instance id and success flag
```json
{
"delete": 4,
"success": true
}
```
12 changes: 6 additions & 6 deletions backend/src/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
def drink_list():
# Get all the drinks from db
"""
@TODO implement endpoint
@DONE implement endpoint
GET /drinks
it should be a public endpoint
it should contain only the drink.short() data representation
Expand All @@ -41,7 +41,7 @@ def drink_list():
@requires_auth("get:drinks-detail")
def drink_list_detail(payload):
"""
@TODO implement endpoint
@DONE implement endpoint
GET /drinks-detail
it should require the 'get:drinks-detail' permission
it should contain the drink.long() data representation
Expand All @@ -57,7 +57,7 @@ def drink_list_detail(payload):
@requires_auth("post:drinks")
def drink_create(payload):
"""
@TODO implement endpoint
@DONE implement endpoint
POST /drinks
it should create a new row in the drinks table
it should require the 'post:drinks' permission
Expand All @@ -83,7 +83,7 @@ def drink_create(payload):
@requires_auth("patch:drinks")
def drink_update(payload, id):
"""
@TODO implement endpoint
@DONE implement endpoint
PATCH /drinks/<id>
where <id> is the existing model id
it should respond with a 404 error if <id> is not found
Expand All @@ -96,7 +96,7 @@ def drink_update(payload, id):
# Get the body
body = request.get_json()

# Get the Drink with requested Id
# filter Drink with requested Id
drink = Drink.query.filter(Drink.id == id).one_or_none()

# abort, drink not found
Expand Down Expand Up @@ -137,7 +137,7 @@ def drink_delete(payload, id):
returns status code 200 and json {"success": True, "delete": id} where id is the id of the deleted record
or appropriate status code indicating reason for failure
"""
# Get the Drink with requested Id
# filter Drink with requested Id
drink = Drink.query.filter(Drink.id == id).one_or_none()

# abort when drink not found
Expand Down
Binary file modified backend/src/database/database.db
Binary file not shown.

0 comments on commit 9f81994

Please sign in to comment.