Browse Source

[REF] emc_api: method order,denormalize schemas

pull/71/head
robin.keunen 4 years ago
parent
commit
db3eb93771
  1. 4
      easy_my_coop_api/controllers/controllers.py
  2. 7
      easy_my_coop_api/readme/ROADMAP.rst
  3. 6
      easy_my_coop_api/services/ping_service.py
  4. 64
      easy_my_coop_api/services/schemas.py
  5. 24
      easy_my_coop_api/services/subscription_request_service.py

4
easy_my_coop_api/controllers/controllers.py

@ -18,7 +18,7 @@ class UserController(main.RestController):
auth="public",
csrf=False,
)
def test(self, _service_name, _id=None, **params):
def test(self, _service_name):
return self._process_method(
_service_name, "test", _id=_id, params=params
_service_name, "test", _id=None, params=None,
)

7
easy_my_coop_api/readme/ROADMAP.rst

@ -0,0 +1,7 @@
The API should generate and use an external id for records instead
of odoo's generated id. It would make importing and export data as
well as migrating across versions easier.
One way would be to use uuid but the default BaseRESTController
routes would need to be rewritten: they only take integer as ids.
Another way is to define a sequence per model.

6
easy_my_coop_api/services/ping_service.py

@ -16,12 +16,12 @@ class PingService(Component):
Ping services (test the api)
"""
def test(self):
return {"message": _("Called ping on ping API")}
def search(self):
return {"message": _("Called search on ping API")}
def test(self):
return {"message": _("Called ping on ping API")}
def _validator_test(self):
return {}

64
easy_my_coop_api/services/schemas.py

@ -15,14 +15,22 @@ def date_validator(field, value, error):
)
# todo consistency: S_SR_GET, S_SR_RETURN_GET, S_SR_POST ...
# and denormalize dict rather than updating them
S_SUBSCRIPTION_REQUEST_GET = {"_id": {"type": "integer"}}
S_SUBSCRIPTION_REQUEST_BASE = {
"name": {"type": "string", "required": True, "empty": False},
S_SUBSCRIPTION_REQUEST_RETURN_GET = {
"id": {"type": "integer", "required": True},
"email": {"type": "string", "required": True, "empty": False},
"name": {"type": "string", "required": True, "empty": False},
"date": {"type": "string", "required": True, "empty": False},
"state": {"type": "string", "required": True, "empty": False},
"ordered_parts": {"type": "integer", "required": True},
"share_product": {
"type": "dict",
"schema": {
"id": {"type": "integer", "required": True},
"name": {"type": "string", "required": True, "empty": False},
},
},
"address": {
"type": "dict",
"schema": {
@ -35,25 +43,37 @@ S_SUBSCRIPTION_REQUEST_BASE = {
"lang": {"type": "string", "required": True, "empty": False},
}
S_SUBSCRIPTION_REQUEST_GET = {
**S_SUBSCRIPTION_REQUEST_BASE,
**{
"id": {"type": "integer", "required": True},
"date": {"type": "string", "required": True, "empty": False},
"state": {"type": "string", "required": True, "empty": False},
"share_product": {
S_SUBSCRIPTION_REQUEST_SEARCH = {
"date_from": {"type": "string", "check_with": date_validator},
"date_to": {"type": "string", "check_with": date_validator},
}
S_SUBSCRIPTION_REQUEST_RETURN_SEARCH = {
"count": {"type": "integer", "required": True},
"rows": {
"type": "list",
"schema": {
"type": "dict",
"schema": {
"id": {"type": "integer", "required": True},
"name": {"type": "string", "required": True, "empty": False},
},
"schema": S_SUBSCRIPTION_REQUEST_RETURN_GET,
},
},
}
S_SUBSCRIPTION_REQUEST_CREATE = {
**S_SUBSCRIPTION_REQUEST_BASE,
**{"share_product": {"type": "integer", "required": True}},
"name": {"type": "string", "required": True, "empty": False},
"email": {"type": "string", "required": True, "empty": False},
"ordered_parts": {"type": "integer", "required": True},
"share_product": {"type": "integer", "required": True},
"address": {
"type": "dict",
"schema": {
"street": {"type": "string", "required": True, "empty": False},
"zip_code": {"type": "string", "required": True, "empty": False},
"city": {"type": "string", "required": True, "empty": False},
"country": {"type": "string", "required": True, "empty": False},
},
},
"lang": {"type": "string", "required": True, "empty": False},
}
S_SUBSCRIPTION_REQUEST_UPDATE = {
@ -73,11 +93,3 @@ S_SUBSCRIPTION_REQUEST_UPDATE = {
"lang": {"type": "string"},
"share_product": {"type": "integer"},
}
S_SUBSCRIPTION_REQUEST_LIST = {
"count": {"type": "integer", "required": True},
"rows": {
"type": "list",
"schema": {"type": "dict", "schema": S_SUBSCRIPTION_REQUEST_GET},
},
}

24
easy_my_coop_api/services/subscription_request_service.py

@ -16,7 +16,8 @@ _logger = logging.getLogger(__name__)
class SubscriptionRequestService(Component):
_inherit = "base.rest.service"
_name = "subscription.request.services"
_usage = "subscription_request" # service_name
# service_name todo subscription-request
_usage = "subscription_request"
_collection = "emc.services"
_description = """
Subscription requests
@ -137,34 +138,25 @@ class SubscriptionRequestService(Component):
return params
def _validator_get(self):
return {"_id": {"type": "integer"}}
return schemas.S_SUBSCRIPTION_REQUEST_GET
def _validator_return_get(self):
return schemas.S_SUBSCRIPTION_REQUEST_GET
return schemas.S_SUBSCRIPTION_REQUEST_RETURN_GET
def _validator_search(self):
return {
"date_from": {
"type": "string",
"check_with": schemas.date_validator,
},
"date_to": {
"type": "string",
"check_with": schemas.date_validator,
},
}
return schemas.S_SUBSCRIPTION_REQUEST_SEARCH
def _validator_return_search(self):
return schemas.S_SUBSCRIPTION_REQUEST_LIST
return schemas.S_SUBSCRIPTION_REQUEST_RETURN_SEARCH
def _validator_create(self):
return schemas.S_SUBSCRIPTION_REQUEST_CREATE
def _validator_return_create(self):
return schemas.S_SUBSCRIPTION_REQUEST_GET
return schemas.S_SUBSCRIPTION_REQUEST_RETURN_GET
def _validator_update(self):
return schemas.S_SUBSCRIPTION_REQUEST_UPDATE
def _validator_return_update(self):
return schemas.S_SUBSCRIPTION_REQUEST_GET
return schemas.S_SUBSCRIPTION_REQUEST_RETURN_GET
Loading…
Cancel
Save