1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/ihatemoney_ynh.git synced 2024-09-03 19:26:15 +02:00
ihatemoney_ynh/budget/api.py

126 lines
2.8 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
from flask import *
import werkzeug
from models import db, Project, Person, Bill
from utils import for_all_methods
2011-09-11 23:00:32 +02:00
from rest import RESTResource, need_auth # FIXME make it an ext
api = Blueprint("api", __name__, url_prefix="/api")
def check_project(*args, **kwargs):
"""Check the request for basic authentication for a given project.
Return the project if the authorization is good, False otherwise
"""
auth = request.authorization
# project_id should be contained in kwargs and equal to the username
if auth and "project_id" in kwargs and \
auth.username == kwargs["project_id"]:
project = Project.query.get(auth.username)
if project.password == auth.password:
return project
return False
2011-09-11 23:00:32 +02:00
class ProjectHandler(object):
2011-09-11 23:00:32 +02:00
def add(self):
pass
@need_auth(check_project, "project")
def get(self, project):
return "get"
2011-09-11 23:00:32 +02:00
@need_auth(check_project, "project")
def delete(self, project):
return "delete"
2011-09-11 23:00:32 +02:00
@need_auth(check_project, "project")
def update(self, project):
return "update"
class MemberHandler(object):
def get(self, project, member_id):
pass
def list(self, project):
pass
def add(self, project):
pass
def update(self, project, member_id):
pass
def delete(self, project, member_id):
pass
class BillHandler(object):
def get(self, project, member_id):
pass
def list(self, project):
pass
def add(self, project):
pass
def update(self, project, member_id):
pass
def delete(self, project, member_id):
pass
project_resource = RESTResource(
name="project",
route="/project",
app=api,
actions=["add", "update", "delete", "get"],
handler=ProjectHandler())
2011-09-11 23:00:32 +02:00
member_resource = RESTResource(
name="member",
inject_name="project",
route="/project/<project_id>/members",
app=api,
handler=MemberHandler(),
authentifier=check_project)
bill_resource = RESTResource(
name="bill",
inject_name="project",
route="/project/<project_id>/bills",
app=api,
handler=BillHandler(),
authentifier=check_project)
# projects: add, delete, edit, get
# GET /project/<id> → get
# PUT /project/<id> → add & edit
# DELETE /project/<id> → delete
# project members: list, add, delete
# GET /project/<id>/members → list
# POST /project/<id>/members/ → add
# PUT /project/<id>/members/<user_id> → edit
# DELETE /project/<id>/members/<user_id> → delete
# project bills: list, add, delete, edit, get
# GET /project/<id>/bills → list
# GET /project/<id>/bills/<bill_id> → get
# DELETE /project/<id>/bills/<bill_id> → delete
# POST /project/<id>/bills/ → add
# GET, PUT, DELETE: /<id> : Get, update and delete
# GET, POST: / Add & List