Skip to content

goretsky-integration/unit-routes-database

Repository files navigation

Unit's routes Database

Сервис хранит информацию о всех подключенных юнитах, а также информацию о маршрутах отчетов/уведомлений.


Терминология:

  • Unit - точка продаж/пиццерия.
  • Chat ID - уникальный идентификатор чата в Telegram.
  • Маршрут - связка chat ID, юнита и типа отчета.

Management Commands

To run management command, use

python manage.py {command}

Commands:

  • init_account_roles - add all account roles.
  • init_report_types - add all report types.

API Reference

Units

Get all units

  GET /units/
Query Parameter Type Description
limit int Optional. Default is 100
offset int Optional. Default is 0

Response

{
  "units": [
    {
      "id": 1,
      "name": "Москва 1-1",
      "uuid": "b8e7c2a9-563f-4011-b531-3974efc36a48",
      "office_manager_account_name": "om_account_msk_1",
      "dodo_is_api_account_name": "api_account_msk_1",
      "region": "Москва 1"
    }
  ],
  "is_end_of_list_reached": true
}

Get unit by name

  GET /units/name/${unit_name}/
Path Parameter Type Description
unit_name string Required. Unit name

Response

{
  "id": 1,
  "name": "Москва 1-1",
  "uuid": "b8e7c2a9-563f-4011-b531-3974efc36a48",
  "office_manager_account_name": "om_account_msk_1",
  "dodo_is_api_account_name": "api_account_msk_1",
  "region": "Москва 1"
}

Get all regions

  GET /units/regions/
Query Parameter Type Description
limit int Optional. Default is 100
offset int Optional. Default is 0

Response

{
  "regions": [
    {
      "id": 1,
      "name": "Москва 1"
    }
  ],
  "is_end_of_list_reached": true
}

Telegram chats

Get all Telegram chats

GET /telegram-chats/
Query Parameter Type Description
limit int Optional. Default is 100
offset int Optional. Default is 0

Response

{
  "telegram_chats": [
    {
      "title": "Eldos",
      "chat_id": 123456
    }
  ],
  "is_end_of_list_reached": true
}

Create Telegram chat

POST /telegram-chats/

Body

{
  "chat_id": 123456,
  "type": "PRIVATE",
  "title": "Eldos",
  "username": null
}
Body Type Description
chat_id int User/Group Telegram ID
type enum Choices: PRIVATE/GROUP
title string Chat title
username string Optional. This field may be omitted.

Response status codes:

  • 201 - Created.
  • 400 - Invalid field in the body.
  • 409 - Chat already exists.

Get all chat types

GET /telegram-chats/chat-types/

Response

[
  "PRIVATE",
  "GROUP"
]

Get Telegram chat

GET /telegram-chats/${chat_id}/
Path Parameter Type Description
chat_id int Telegram chat ID

Response

{
  "chat_id": 12345,
  "username": "",
  "title": "hello",
  "type": "Private"
}

Update Telegram chat

PUT /telegram-chats/${chat_id}/
Path Parameter Type Description
chat_id int Telegram chat ID

Response status codes:

  • 204 - Updated.
  • 400 - Invalid request.
  • 404 - Chat not found.

Report types

Get all report types

GET /report-types/
Query Parameter Type Description
limit int Optional. Default is 100
offset int Optional. Default is 0

Response

{
  "report_types": [
    {
      "id": 16,
      "name": "CANCELED_ORDERS",
      "verbose_name": "Отмены заказов"
    }
  ],
  "is_end_of_list_reached": false
}

Get all statistics report types

GET /report-types/statistics/
Query Parameter Type Description
limit int Optional. Default is 100
offset int Optional. Default is 0

Response

{
  "report_types": [
    {
      "id": 777,
      "name": "BONUS_SYSTEM",
      "verbose_name": "Бонусная система"
    }
  ],
  "is_end_of_list_reached": true
}

Report routes

Get report routes units

GET /report-routes/units/
Query Parameter Type Description
chat_id int Telegram chat ID
report_type_id int Report type ID
limit int Optional. Default is 100
offset int Optional. Default is 0

Response

{
  "unit_ids": [
    1,
    2,
    3
  ],
  "is_end_of_list_reached": true
}

Get report routes telegram chats

GET /report-routes/telegram-chats/
Query Parameter Type Description
unit_id int Unit ID
report_type_id int Report type ID
limit int Optional. Default is 100
offset int Optional. Default is 0

Response

{
  "chat_ids": [
    1,
    2,
    3
  ],
  "is_end_of_list_reached": true
}

Create report route

POST /report-routes/

Body

{
  "report_type_id": 0,
  "chat_id": 0,
  "unit_ids": [
    1,
    2,
    3
  ]
}

Response status codes

  • 201 - Created
  • 400 - Bad request
  • 403 - Permission to units/report type denied
  • 404 - Chat/report type/units do not exist
  • 409 - Report type already exists

Delete report type

DELETE /report-routes/
Query Parameter Type Description
chat_id int Chat ID
report_type_id int Report type ID
unit_ids list[int] List of unit IDs

Response status codes

  • 204 - Deleted

Roles

Get user role regions

GET /users/{$chat_id}/regions/
Query Parameter Type Description
limit int Optional. Default is 100
offset int Optional. Default is 0

Response

{
  "regions": [
    {
      "id": 1,
      "name": "Москва 1"
    }
  ],
  "is_end_of_list_reached": true
}

Get user role units

GET /users/{$chat_id}/units/
Query Parameter Type Description
limit int Optional. Default is 100
offset int Optional. Default is 0
region_id int Optional. Filter by region ID

Response

{
  "units": [
    {
      "id": 1,
      "name": "Москва 1-1",
      "uuid": "000d3a00-b0dc-80d9-11e6-b24faa1bca9f"
    }
  ],
  "is_end_of_list_reached": true
}

Get user role report types

GET /users/{$chat_id}/report-types/
Query Parameter Type Description
limit int Optional. Default is 100
offset int Optional. Default is 0

Response

{
  "report_types": [
    {
      "id": 1,
      "name": "CANCELED_ORDERS",
      "verbose_name": "Отмены заказов"
    }
  ],
  "is_end_of_list_reached": true
}

Set user role

PATCH /users/{$chat_id}/access-code/

Body

{
  "access_code": "your access code"
}

Response status codes

  • 204 - Updated
  • 404 - User/role is not found