Merge branch 'backend' of https://github.com/he1d1/duck-pond into backend
This commit is contained in:
commit
2dc6c761ed
2 changed files with 22 additions and 6 deletions
|
@ -13,7 +13,7 @@ class Entry:
|
|||
image_url: Optional[str]
|
||||
|
||||
def validate(self, only_populated_fields=False) -> Tuple[bool, str]:
|
||||
if self.name == "" and not only_populated_fields:
|
||||
if (self.name == "" or self.name is None) and not only_populated_fields:
|
||||
return False, "name cannot be empty"
|
||||
|
||||
if self.votes < 0:
|
||||
|
@ -25,6 +25,9 @@ class Entry:
|
|||
except Exception:
|
||||
return False, "invalid URL"
|
||||
|
||||
if self.location_lat is None or self.location_long is None:
|
||||
return False, "missing locations"
|
||||
|
||||
return True, ""
|
||||
|
||||
def as_dict(self) -> Dict:
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
from re import A
|
||||
from typing import *
|
||||
import urllib
|
||||
import uuid
|
||||
import flask
|
||||
from dataclasses import dataclass
|
||||
|
||||
import db
|
||||
import paths
|
||||
|
@ -21,7 +18,7 @@ class Endpoints:
|
|||
app.add_url_rule(paths.CREATE_ENTRY, view_func=self.create_entry, methods=["POST"])
|
||||
|
||||
def list_entries(self):
|
||||
# TODO: populate from databaase
|
||||
# TODO: populate from databaase
|
||||
|
||||
a = db.Entry("203fc6a0-9587-41a4-9862-e1b72039b98b", "Birmingham Duck Pond", -1.2345, 33.4567, 0, None)
|
||||
b = db.Entry("b140e048-ea2c-4827-b670-ef41ba48c56d", "Northwich Duck Pond", -3.2345, 25.4567, 0, None)
|
||||
|
@ -44,9 +41,25 @@ class Endpoints:
|
|||
if body is None:
|
||||
return "no JSON body", 400
|
||||
|
||||
# TODO: validate inputs
|
||||
coordinates = body.get("location", None)
|
||||
if coordinates is None:
|
||||
return "missing location", 400
|
||||
|
||||
new_entry = db.Entry(
|
||||
uuid.uuid4(),
|
||||
body.get("name"),
|
||||
coordinates.get("lat"),
|
||||
coordinates.get("long"),
|
||||
0,
|
||||
body.get("imageURL"))
|
||||
|
||||
validation_result, error_text = new_entry.validate()
|
||||
|
||||
if not validation_result:
|
||||
return flask.abort(400, error_text)
|
||||
|
||||
# TODO: store in database
|
||||
# TODO: Form responses
|
||||
|
||||
return flask.jsonify({
|
||||
"id": uuid.uuidv4()
|
||||
|
|
Reference in a new issue