added type annotations to schema

pull/4/head
Blake DeMarcy 2017-03-03 00:08:32 -06:00
parent 103d1d3071
commit cb14cda072
1 changed files with 36 additions and 30 deletions

View File

@ -1,6 +1,7 @@
from src import formatting from src import formatting
from time import time from time import time
def base(): def base():
return { return {
"error": False "error": False
@ -19,49 +20,54 @@ def error(code, description):
result = base() result = base()
result.update({ result.update({
"error": { "error": {
"description": description, "description": description, # string
"code": code "code": code # integer
} }
}) })
return result return result
def user_internal(ID, auth_hash, name, quip, bio, admin): def user_internal(ID, auth_hash, name, quip, bio, admin):
if not quip: quip = ""
if not bio: bio = ""
return { return {
"user_id": ID, "user_id": ID, # string
"quip": quip, "quip": quip, # (possibly empty) string
"name": name, "bio": bio, # (possibly empty) string
"bio": bio, "name": name, # string
"admin": admin, "admin": admin, # boolean
"auth_hash": auth_hash "auth_hash": auth_hash # SHA256 string
} }
def user_external(ID, name, quip, bio, admin): def user_external(ID, name, quip, bio, admin):
if not quip: quip = ""
if not bio: bio = ""
return { return {
"user_id": ID, "user_id": ID, # string
"quip": quip, "quip": quip, # (possibly empty) string
"name": name, "name": name, # string
"bio": bio, "bio": bio, # string
"admin": admin "admin": admin # boolean
} }
def thread(ID, author, body, title, tags): def thread(ID, author, body, title, tags):
if not tags: tags = list()
body = formatting.parse(body, doquotes=False) body = formatting.parse(body, doquotes=False)
now = time() now = time()
return { return {
"thread_id": ID, "thread_id": ID, # string
"post_id": 1, "post_id": 1, # integer
"author": author, "author": author, # string
"body": body, "body": body, # string
"title": title, "title": title, # string
"tags": tags, "tags": tags, # (possibly empty) list of strings
"replies": list(), "replies": list(), # (possibly empty) list of reply objects
"reply_count": 0, "reply_count": 0, # integer
"lastmod": now, "edited": False, # boolean
"edited": False, "lastmod": now, # floating point unix timestamp
"created": now "created": now # floating point unix timestamp
} }
@ -69,10 +75,10 @@ def reply(ID, author, body):
body = formatting.parse(body) body = formatting.parse(body)
now = time() now = time()
return { return {
"post_id": ID, "post_id": ID, # integer
"author": author, "author": author, # string
"body": body, "body": body, # string
"lastmod": now, "edited": False, # boolean
"edited": False, "lastmod": now, # floating point unix timestamp
"created": now "created": now # floating point unix timestamp
} }