Stock - Pan-Lang/backend GitHub Wiki
Stock
Endpoint
https://us-central1-pan-lang.cloudfunctions.net/stock
GET
Expects a request with a query of:
{
pantry: pantry_id
}
Return Codes and Object Results
200 OK
- Gets all stock for a pantry. Each stock item has these properties:
{
_id: id of the fooditem
count: # of items left in stock
spanish: spanish translation
french: french translation
....
chinese: chinese translation
timestamp: timestamp when it was last updated
}
422 UNPROCESSABLE ENTITY
- A result body with the message "Error getting documents" and the error. Occurs when the database has an error and the stock cannot be found within the database
POST
Expects a request with a body of:
{
pantry: pantry_id
name: Item Name
count: initial count
}
Return Codes and Object Results
200 OK
- Returns when the stock object is successfully placed in the database. Translation will be done by the backend.
422 UNPROCESSABLE ENTITY
- Returns when this item already exists in the database
500 SERVER ERROR
- Returns when the database throws an unexpected error and cannot place the object in the database
PUT
Expects a request with a body of:
{
pantry: pantry_id
_id: fooditem id
newCount: new item count
}
Return Codes and Object Results
204 OK
- Stock object in the database gets updated to the new count
422 UNPROCESSABLE ENTITY
- Returns when there is something wrong with the pantry id
Firebase Translate
Upon entry of an English stock item (with input field called name
) into the stock
collection, the Translate extension will create an output field called translated
and add it to stock
:
{
name: "beans"
translated:
es: "frijoles"
fr: "des haricots"
zh-CN: "豆子"
}