Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 0.0.0 #4

Merged
merged 8 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@

.idea/
venv/
__pycache__/
.mypy_cache/
*.pyc
build/
.env
/autogenerated-structure-template/app/core/__init__.py
/autogenerated-structure-template/app/core/config.py
/autogenerated-structure-template/app/__init__.py
/autogenerated-structure-template/app/database.py
/autogenerated-structure-template/app/main.py
/autogenerated-structure-template/tests/__init__.py
/autogenerated-structure-template/.gitignore
/autogenerated-structure-template/.pre-commit-config.yaml
/autogenerated-structure-template/docker-compose.yaml
/autogenerated-structure-template/Dockerfile
/autogenerated-structure-template/gino-fastapi-layout.svg
/autogenerated-structure-template/LICENSE
/autogenerated-structure-template/README.md
/autogenerated-structure-template/requirements.txt
/autogenerated-structure-template/setup.cfg
78 changes: 74 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,73 @@
# URLer - Uniform Resource Locator shortener.

## How to start

Use python 3.9 or 3.10.

Create virtual environment
```bash
pip3 install virtualenv
python3 -m virtualenv venv -p python3
source venv/bin/activate
```
Install dependencies
```bash
pip install -r requirements.txt
```
The module `uvloop==0.14.0` is not being installed with python 3.11 due to an error `Could not build wheels for uvloop`.
But it works with 3.10.

Create `.env` file in the root of project:
```bash
PROJECT_NAME='Your-name-for-this-project'
```
e.g. set a name `PROJECT_NAME='URLer'`.

**Run server**
```bash
uvicorn src.main:app --host 127.0.0.1 --port 8080
```
_Note: 0.0.0.0 may not work in Safari browser_

## How to test
Open any link in any browser

* Swagger http://127.0.0.1:8080/docs
* ReDoc http://127.0.0.1:8080/redoc
* OpenAPI documentation (json) http://127.0.0.1:8080/openapi.json

## A tidy up and a health check

Install additional "developer's" requirements
```bash
pip install -r requirements-dev.txt
```

A linter
```bash
ruff src
```

A linter's fixing tool
```bash
ruff src --fix
```

A formatter
```bash
ruff format src
```

A default 'health-checking' linter
```bash
flake8 src
```

A static type checker tool
```bash
mypy src
```

# Проектное задание четвёртого спринта

Спроектируйте и реализуйте сервис для создания сокращённой формы передаваемых URL и анализа активности их использования.
Expand Down Expand Up @@ -35,7 +105,7 @@ GET /<shorten-url-id>/status?[full-info]&[max-result=10]&[offset=0]

Метод принимает в качестве параметра идентификатор сокращённого URL и возвращает информацию о количестве переходов, совершенных по ссылке.

В ответе может содержаться как общее количество совершенных переходов, так и дополнительная детализированная информация о каждом переходе (наличие **query**-параметра **full-info** и параметров пагинации):
В ответе может содержаться как **общее количество совершенных переходов**, так и дополнительная детализированная информация о каждом переходе (наличие **query**-параметра **full-info** и параметров пагинации):
- дата и время перехода/использования ссылки;
- информация о клиенте, выполнившем запрос;

Expand All @@ -44,10 +114,10 @@ GET /<shorten-url-id>/status?[full-info]&[max-result=10]&[offset=0]

## Дополнительные требования (отметьте [Х] выбранные пункты):

- [ ] (1 балл) Реализуйте метод `GET /ping`, который возвращает информацию о статусе доступности БД.
- [ ] (1 балл) Реализуйте возможность «удаления» сохранённого URL. Запись должна остаться, но помечаться как удалённая. При попытке получения полного URL возвращать ответ с кодом `410 Gone`.
- [x] (1 балл) Реализуйте метод `GET /ping`, который возвращает информацию о статусе доступности БД.
- [x] (1 балл) Реализуйте возможность «удаления» сохранённого URL. Запись должна остаться, но помечаться как удалённая. При попытке получения полного URL возвращать ответ с кодом `410 Gone`.
- [ ] (2 балла) Реализуйте middlware, блокирующий доступ к сервису из запрещённых подсетей (black list).
- [ ] (2 балла) Реализуйте возможность передавать ссылки пачками (batch upload).
- [x] (2 балла) Реализуйте возможность передавать ссылки пачками (batch upload).

<details>
<summary> Описание изменений </summary>
Expand Down
9 changes: 9 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[tool.pytest.ini_options]
addopts = '-sv'
pythonpath = '.'

[tool.ruff.lint]
extend-select=['I']

[tool.ruff.format]
quote-style='single'
5 changes: 5 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

flake8
mypy
ruff
watchgod==0.8.2
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

fastapi==0.79.0
orjson==3.4.1
fastapi==0.93.0
pydantic==1.9.0
python-dotenv==1.0.1
uvicorn==0.18.2
uvloop==0.14.0; sys_platform != "win32" and implementation_name == "cpython"
uvloop==0.17.0; sys_platform != "win32" and implementation_name == "cpython"
Empty file added src/__init__.py
Empty file.
23 changes: 23 additions & 0 deletions src/core/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""
Run through console:

uvicorn src.main:app --host 127.0.0.1 --port 8080
additional notes are in the `../README.md` file
"""
from pathlib import Path

from pydantic import BaseSettings

BASE_DIR = Path.cwd().parent.parent
# print('BASE_DIR', BASE_DIR)


class AppSettings(BaseSettings):
# Don't use this name, set any name in '.env' file.
PROJECT_NAME: str = "Default app's name"

class Config:
env_file = '.env'


app_settings = AppSettings()
21 changes: 21 additions & 0 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""
Routs which work "from the box":

docs_url: "/docs" - Swagger
redoc_url: "/redoc" - ReDoc
openapi_url: "/openapi.json" - OpenAPI documentation
"""
from fastapi import FastAPI

from src.core import config


def get_application():
_app = FastAPI(
title=config.app_settings.PROJECT_NAME,
)

return _app


app = get_application()