definition rent endpoint

This commit is contained in:
Cayo Puigdefabregas 2020-11-16 20:32:28 +01:00
parent 71f860cef0
commit 8acca4d2cf
6 changed files with 37 additions and 6 deletions

View File

@ -14,6 +14,7 @@ from ereuse_devicehub.resources.device import definitions
from ereuse_devicehub.resources.documents import documents
from ereuse_devicehub.resources.enums import PriceSoftware
from ereuse_devicehub.resources.versions import versions
from ereuse_devicehub.resources.rent import definitions as rent_def
class DevicehubConfig(Config):
@ -27,7 +28,8 @@ class DevicehubConfig(Config):
import_resource(proof),
import_resource(documents),
import_resource(inventory),
import_resource(versions)),
import_resource(versions),
import_resource(rent_def)),
)
PASSWORD_SCHEMES = {'pbkdf2_sha256'} # type: Set[str]
DB_USER = config('DB_USER', 'dhub')

View File

@ -228,11 +228,6 @@ class DonateDef(ActionDef):
SCHEMA = schemas.Donate
class RentDef(ActionDef):
VIEW = None
SCHEMA = schemas.Rent
class MakeAvailable(ActionDef):
VIEW = None
SCHEMA = schemas.MakeAvailable

View File

@ -0,0 +1,34 @@
from typing import Callable, Iterable, Tuple
from flask import g
from flask.json import jsonify
from ereuse_devicehub.resources import action as act
from ereuse_devicehub.resources.action.models import Rent
from ereuse_devicehub.resources.device.models import Device
from teal.resource import Converters, Resource, View
from ereuse_devicehub import auth
from ereuse_devicehub.query import things_response
class RentingView(View):
@auth.Auth.requires_auth
def get(self, id):
return super().get(id)
@auth.Auth.requires_auth
def post(self):
""" Create one rent """
return jsonify('ok')
def find(self, args: dict):
rents = Rent.query.filter() \
.order_by(Rent.created.desc()) \
.paginate(per_page=200)
return things_response(
self.schema.dump(rents.items, many=True, nested=0),
rents.page, rents.per_page, rents.total, rents.prev_num, rents.next_num
)
class RentDef(Resource):
VIEW = RentingView
SCHEMA = act.schemas.Rent

View File

View File