food logger context tips
This commit is contained in:
@@ -36,6 +36,17 @@ INVENTORY = {'type': 'object', 'properties': {
|
||||
'product_id': {'type': 'string', 'format': 'uuid'}, 'quantity': {'type': 'integer', 'minimum': 1},
|
||||
'location': {'type': 'string'}, 'category': {'type': 'string'}, 'notes': {'type': 'string'},
|
||||
'opened': {'type': 'boolean'}, 'best_before': {'type': ['string', 'null'], 'format': 'date'},
|
||||
'remaining_amount': {'type': ['string', 'null'], 'description': 'Only for one opened package with known size'},
|
||||
}}
|
||||
PRODUCT = {'type': 'object', 'required': ['name'], 'properties': {
|
||||
'name': {'type': 'string', 'maxLength': 255}, 'brand': {'type': 'string', 'maxLength': 255},
|
||||
'barcode': {'type': ['string', 'null']}, 'package_quantity': {'type': ['string', 'number', 'null']},
|
||||
'package_unit': {'type': ['string', 'null'], 'enum': ['g', 'ml', None]},
|
||||
'nutrition_per_100': {'type': ['object', 'null']}, 'source': {'type': 'string', 'enum': ['manual']},
|
||||
}}
|
||||
GROCERIES = {'type': 'object', 'required': ['items'], 'properties': {
|
||||
'items': {'type': 'array', 'minItems': 1, 'maxItems': 20, 'items': {'type': 'object'}},
|
||||
'create_missing_products': {'type': 'boolean'},
|
||||
}}
|
||||
UPLOAD = {'type': 'object', 'required': ['image'], 'properties': {
|
||||
'image': {'type': 'string', 'format': 'binary'}, 'caption': {'type': 'string'},
|
||||
@@ -51,6 +62,10 @@ def schema(request):
|
||||
'paths': {
|
||||
'/food/today/': {'get': operation('Food log for an optional local calendar date, defaulting to today', 'food:read')},
|
||||
'/food/products/': {'get': operation('Search own food products', 'food:read')},
|
||||
'/food/products/lookup/': {'get': operation('Look up local and optional Open Food Facts product candidates', 'food:read')},
|
||||
'/food/products/create/': {'post': operation('Create or reuse an owned manual food product', 'food:write', PRODUCT)},
|
||||
'/food/products/import/': {'post': operation('Import a selected Open Food Facts barcode', 'food:write',
|
||||
{'type': 'object', 'required': ['barcode'], 'properties': {'barcode': {'type': 'string'}}})},
|
||||
'/food/log/': {'post': operation('Create food log entry', 'food:write', ENTRY)},
|
||||
'/food/log/{id}/': {
|
||||
'get': operation('Read own entry', 'food:read'),
|
||||
@@ -64,6 +79,8 @@ def schema(request):
|
||||
'get': operation('Search own inventory', 'inventory:read'),
|
||||
'post': operation('Create inventory item', 'inventory:write', INVENTORY),
|
||||
},
|
||||
'/kitchen/import-groceries/': {'post': operation('Import up to 20 groceries with per-item results',
|
||||
'inventory:write + food:write', GROCERIES)},
|
||||
'/kitchen/items/{id}/': {
|
||||
'get': operation('Read own inventory item', 'inventory:read'),
|
||||
'patch': operation('Update own inventory item', 'inventory:write', INVENTORY),
|
||||
@@ -82,6 +99,16 @@ def schema(request):
|
||||
'description': 'Local calendar date; defaults to today in the user time zone.',
|
||||
'schema': {'type': 'string', 'format': 'date'},
|
||||
}]
|
||||
document['paths']['/food/products/lookup/']['get']['parameters'] = [
|
||||
{'name': name, 'in': 'query', 'required': False, 'schema': schema} for name, schema in (
|
||||
('query', {'type': 'string'}), ('barcode', {'type': 'string'}), ('brand', {'type': 'string'}),
|
||||
('package_quantity', {'type': 'number'}), ('package_unit', {'type': 'string', 'enum': ['g', 'ml']}),
|
||||
('limit', {'type': 'integer', 'minimum': 1, 'maximum': 20}),
|
||||
('include_open_food_facts', {'type': 'boolean'}))]
|
||||
document['paths']['/kitchen/import-groceries/']['post']['parameters'] = [{
|
||||
'name': 'Idempotency-Key', 'in': 'header', 'required': True,
|
||||
'schema': {'type': 'string', 'maxLength': 128},
|
||||
}]
|
||||
document['paths']['/food/attachments/{id}/file/']['get']['responses']['200'] = {
|
||||
'description': 'Owned image bytes',
|
||||
'content': {mime: {'schema': {'type': 'string', 'format': 'binary'}}
|
||||
|
||||
Reference in New Issue
Block a user