Alter 3 files
Update `README.md` Update `endpoints.py` Add `paths.py`
This commit is contained in:
parent
f75dde9ac7
commit
e2f8c087d9
3 changed files with 89 additions and 4 deletions
|
@ -1 +1,58 @@
|
|||
# Duck Pond backend
|
||||
# Duck Pond backend
|
||||
|
||||
## Endpoints
|
||||
|
||||
### GET `/entries`
|
||||
|
||||
Gets a list of all the duck ponds in the database.
|
||||
|
||||
### POST `/entries/<id>/new`
|
||||
|
||||
Creates a new duck pond entry.
|
||||
|
||||
JSON body arguments:
|
||||
* `name` - reqiured
|
||||
* `location` - required, in the form
|
||||
```json
|
||||
{
|
||||
"lat": -1.2345,
|
||||
"long": 33.56643
|
||||
}
|
||||
```
|
||||
* `imageURL`
|
||||
|
||||
Votes will be initialised as zero.
|
||||
|
||||
Return sample:
|
||||
|
||||
```json
|
||||
{
|
||||
"id": "uuid"
|
||||
}
|
||||
```
|
||||
|
||||
### PATCH `/entries/<id>`
|
||||
|
||||
Updates an entry with the ID `id`.
|
||||
|
||||
JSON body arguments:
|
||||
* `name`
|
||||
* `location`
|
||||
* `imageURL`
|
||||
* `votes`
|
||||
|
||||
### GET `/entries/<id>`
|
||||
|
||||
Gets the JSON of the pond.
|
||||
|
||||
```json
|
||||
{
|
||||
"id": "uuid",
|
||||
"name": "The Pondiest Pond",
|
||||
"location": {
|
||||
"lat": -1.2345,
|
||||
"long": 33.56643
|
||||
},
|
||||
"imageURL": "https://example.com"
|
||||
}
|
||||
```
|
|
@ -1,6 +1,7 @@
|
|||
import flask
|
||||
|
||||
import db
|
||||
import paths
|
||||
|
||||
class Endpoints:
|
||||
db: db.DB
|
||||
|
@ -8,7 +9,32 @@ class Endpoints:
|
|||
def __init__(self, app: flask.Flask, database: db.DB):
|
||||
self.db = database
|
||||
|
||||
app.add_url_rule("/", view_func=self.index)
|
||||
app.add_url_rule(paths.ENTRIES, view_func=self.list_entries, methods=["GET"])
|
||||
app.add_url_rule(paths.GET_ENTRY, view_func=self.get_entry, methods=["GET"])
|
||||
|
||||
def index(self):
|
||||
return "<h2>Hello world</h2>"
|
||||
def list_entries(self):
|
||||
# TODO: populate from databaase
|
||||
|
||||
return flask.jsonify([{
|
||||
"id": "203fc6a0-9587-41a4-9862-e1b72039b98b",
|
||||
"name": "Birmingham Duck Pond",
|
||||
"location": {
|
||||
"lat": -1.2345,
|
||||
"long": 33.4567
|
||||
},
|
||||
"imageURL": "https://example.com/image.png"
|
||||
}, {
|
||||
"id": "b140e048-ea2c-4827-b670-ef41ba48c56d",
|
||||
"name": "Northwich Duck Pond",
|
||||
"location": {
|
||||
"lat": -3.2345,
|
||||
"long": 25.4567
|
||||
},
|
||||
"imageURL": "https://example.com/image.png"
|
||||
}])
|
||||
|
||||
def get_entry(self, id: str):
|
||||
return flask.jsonify({
|
||||
"id": id,
|
||||
"TODO": "TODO"
|
||||
})
|
2
backend/duckpond/paths.py
Normal file
2
backend/duckpond/paths.py
Normal file
|
@ -0,0 +1,2 @@
|
|||
ENTRIES = "/entries"
|
||||
GET_ENTRY = "/entry/<id>"
|
Reference in a new issue