nesh170 / asap-inventory-system

This is a concept inventory system for ECE458. It is built by ASAPsolutions
1 stars 0 forks source link

Custom fields #93

Closed nesh170 closed 7 years ago

nesh170 commented 7 years ago

Added Custom Fields 🗡

GET All Fields GET /api/item/field/ HTTP/1.1 Host: localhost:8000 Content-Type: application/json Authorization: Bearer

Response:-

{
  "count": 5,
  "next": null,
  "previous": null,
  "results": [
    {
      "id": 2,
      "name": "restock_info",
      "type": "long_text",
      "private": true
    },
    {
      "id": 3,
      "name": "location",
      "type": "short_text",
      "private": false
    },
    {
      "id": 4,
      "name": "pass",
      "type": "int",
      "private": true
    },
    {
      "id": 5,
      "name": "sensitivity",
      "type": "float",
      "private": false
    },
    {
      "id": 7,
      "name": "lolsda",
      "type": "int",
      "private": false
    }
  ]
}

Create new field POST /api/item/field/ HTTP/1.1 Host: localhost:8000 Content-Type: application/json Authorization: Bearer Types available:- ['int', 'float', 'long_text', 'short_text']

Automatically creates field for all the items in the database

Request:

{
   "name": "lit_field",
   "type": "long_text",
   "private": true
}

Response:

{
  "id": 8,
  "name": "lit_field",
  "type": "long_text",
  "private": true
}

Delete a field DELETE /api/item/field/7 HTTP/1.1 Host: localhost:8000 Content-Type: application/json Authorization: Bearer

Returns Response.status = status.HTTP_204_No_Content if success

Update type_field for an item PATCH /api/item/field/'type'/ HTTP/1.1 Host: localhost:8000 Content-Type: application/json Authorization: Bearer type=['int','float','longtext','shorttext']

Request:

    {
      "value": 5
    }

Response:

{
  "id": 7,
  "item": 5,
  "field": "pass",
  "value": 5,
  "field_id": 4,
  "item_id": 5
}

Get detailed Item view (this is updated to include the tags, it does not show private fields if non admin) GET /api/item/5 HTTP/1.1 Host: localhost:8000 Content-Type: application/json Authorization: Bearer

Response:

{
  "id": 5,
  "name": "iPhone 7",
  "quantity": 4,
  "model_number": null,
  "description": null,
  "tags": [],
  "int_fields": [
    {
      "id": 7,
      "item": 5,
      "field": "pass",
      "value": 5,
      "field_id": 4,
      "item_id": 5
    }
  ],
  "float_fields": [
    {
      "id": 4,
      "item": 5,
      "field": "sensitivity",
      "value": 1.2343,
      "field_id": 5,
      "item_id": 5
    }
  ],
  "short_text_fields": [
    {
      "id": 4,
      "item": 5,
      "field": "location",
      "value": null,
      "field_id": 3,
      "item_id": 5
    }
  ],
  "long_text_fields": [
    {
      "id": 5,
      "item": 5,
      "field": "restock_info",
      "value": "Uber Lit",
      "field_id": 2,
      "item_id": 5
    },
    {
      "id": 8,
      "item": 5,
      "field": "lit_field",
      "value": null,
      "field_id": 8,
      "item_id": 5
    }
  ]
}