Skip to content

DR0P-database/AvitoApprenticeship

Repository files navigation

BannersAPP

This is a service that allows you to show banners to users, depending on the required fic and tag of the user, as well as manage banners and their associated tags and fic. The service uses PostgreSql, FastAPI, Redis (stores data about user banners for 5 minutes).

Setup

git clone https://github.com/DR0P-database/AvitoApprenticeship.git
cd AvitoApprenticeship
docker compose build
docker compose up

Usage

X-Token and users

If you make a request without a token in the header or the token is not equal to "user_token" and "admin_token", the application will return errors:

{ "detail": "Пользователь не авторизован" }

{ "detail": "Пользователь не имеет доступа" }

Add banner

curl -X 'POST' 'http://127.0.0.1:8000/banner/' -H 'accept: application/json' -H 'x-token: admin_token' -H 'Content-Type: application/json' -d '{
    "tag_ids": [
      5,6
    ],
    "feature_id": 7,
    "content": {"text":"qwerty"},
    "is_active": true
  }'
image

All parametrs required and list of tag_ids must be not empty, token must be "admin_token"

If all right response will be with status code 201:

{ "banner_id": 1 }

If same banner already exists will be returned status code 400:

{ "detail": "Похожий баннер уже есть" }

Uncorrect data type in requests

If you enter an invalid data type in the query, you will get an error 400:

{ "error": "Некорректные данные" }

Get banner by feature/tag

curl -X 'GET' 'http://127.0.0.1:8000/banner/?feature_id=7&tag_id=1' -H 'accept: application/json' -H 'x-token: admin_token'
image

Respnse will be with status 200: image

Get user_banner

curl -X 'GET' 'http://127.0.0.1:8000/user_banner/?feature_id=1&tag_id=7&use_last_revision=true' -H 'accept: application/json' -H 'x-token: user_token'

"feature_id" and "tag_id" is required

Response will be with status code 200:

image

If banner not found return code 404:

{ "detail": "Баннер для не найден" }

Patch banner

Use method PATCH and url 'http://127.0.0.1:8000/banner/{id}' where id is int banner id when add banner

image

All fields required, tag_ids must be not_empty

If all right response will be with status 200:

{ "detail": "OK" }

If same banner already exists return will be code 400:

{ "detail": "Похожий баннер уже есть" }

Delete banner

Use method DELETE and url 'http://127.0.0.1:8000/banner/{id}' where id is int banner id when add banner

curl -X 'DELETE' 'http://127.0.0.1:8000/banner/1' -H 'x-token: admin_token'

If all right response will be status 204:

Else status or 404:

{ "detail": "Баннер для тэга не найден" }

Issues and solutions

  1. You cannot add a new banner with a feature and a tag if such a banner with a feature and a tag from the list already exists. For example, there is a banner with a feature 2 tags [1,2,3], then it will not be possible to add a banner with feature 2 and tags [1,5,6] or [1,2] or [3,4,5]. You will only be able to add a banner with an existing feature that has tags that do not overlap. Also in PATCH method of banner.

  2. Does a banner have to have at least one tag? -- On the service, when creating and patching a banner, the list of tags should not be empty.

  3. What if requests are from a token that is not a 'user_token' or 'admin_token' -- the Application thinks it is not authorized.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published