Skip to content

Commit 037c032

Browse files
authored
Release 0.0.0 (#4)
* default routes /docs, /redoc and /openapi.json work. * Tidy Up 1 (#3) readme is updated with an instruction how to start * gitignore is updated. * Readme is updated with dev's information about maintenance. mypy is run. * excluding 3.11 due to error with installing of uvloop battery. longintrepr.h: No such file or directory * excluding 3.10 due to error with installing of uvloop battery. error: command '/usr/bin/gcc' failed with exit code 1 || Failed building wheel for uvloop * requirements are updated.
1 parent 57232e4 commit 037c032

8 files changed

+154
-7
lines changed

.gitignore

+19
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,23 @@
11

22
.idea/
3+
venv/
34
__pycache__/
5+
.mypy_cache/
46
*.pyc
7+
build/
8+
.env
9+
/autogenerated-structure-template/app/core/__init__.py
10+
/autogenerated-structure-template/app/core/config.py
11+
/autogenerated-structure-template/app/__init__.py
12+
/autogenerated-structure-template/app/database.py
13+
/autogenerated-structure-template/app/main.py
14+
/autogenerated-structure-template/tests/__init__.py
15+
/autogenerated-structure-template/.gitignore
16+
/autogenerated-structure-template/.pre-commit-config.yaml
17+
/autogenerated-structure-template/docker-compose.yaml
18+
/autogenerated-structure-template/Dockerfile
19+
/autogenerated-structure-template/gino-fastapi-layout.svg
20+
/autogenerated-structure-template/LICENSE
21+
/autogenerated-structure-template/README.md
22+
/autogenerated-structure-template/requirements.txt
23+
/autogenerated-structure-template/setup.cfg

README.md

+74-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,73 @@
1+
# URLer - Uniform Resource Locator shortener.
2+
3+
## How to start
4+
5+
Use python 3.9 or 3.10.
6+
7+
Create virtual environment
8+
```bash
9+
pip3 install virtualenv
10+
python3 -m virtualenv venv -p python3
11+
source venv/bin/activate
12+
```
13+
Install dependencies
14+
```bash
15+
pip install -r requirements.txt
16+
```
17+
The module `uvloop==0.14.0` is not being installed with python 3.11 due to an error `Could not build wheels for uvloop`.
18+
But it works with 3.10.
19+
20+
Create `.env` file in the root of project:
21+
```bash
22+
PROJECT_NAME='Your-name-for-this-project'
23+
```
24+
e.g. set a name `PROJECT_NAME='URLer'`.
25+
26+
**Run server**
27+
```bash
28+
uvicorn src.main:app --host 127.0.0.1 --port 8080
29+
```
30+
_Note: 0.0.0.0 may not work in Safari browser_
31+
32+
## How to test
33+
Open any link in any browser
34+
35+
* Swagger http://127.0.0.1:8080/docs
36+
* ReDoc http://127.0.0.1:8080/redoc
37+
* OpenAPI documentation (json) http://127.0.0.1:8080/openapi.json
38+
39+
## A tidy up and a health check
40+
41+
Install additional "developer's" requirements
42+
```bash
43+
pip install -r requirements-dev.txt
44+
```
45+
46+
A linter
47+
```bash
48+
ruff src
49+
```
50+
51+
A linter's fixing tool
52+
```bash
53+
ruff src --fix
54+
```
55+
56+
A formatter
57+
```bash
58+
ruff format src
59+
```
60+
61+
A default 'health-checking' linter
62+
```bash
63+
flake8 src
64+
```
65+
66+
A static type checker tool
67+
```bash
68+
mypy src
69+
```
70+
171
# Проектное задание четвёртого спринта
272

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

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

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

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

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

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

52122
<details>
53123
<summary> Описание изменений </summary>

pyproject.toml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[tool.pytest.ini_options]
2+
addopts = '-sv'
3+
pythonpath = '.'
4+
5+
[tool.ruff.lint]
6+
extend-select=['I']
7+
8+
[tool.ruff.format]
9+
quote-style='single'

requirements-dev.txt

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
flake8
3+
mypy
4+
ruff
5+
watchgod==0.8.2

requirements.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

2-
fastapi==0.79.0
3-
orjson==3.4.1
2+
fastapi==0.93.0
43
pydantic==1.9.0
4+
python-dotenv==1.0.1
55
uvicorn==0.18.2
6-
uvloop==0.14.0; sys_platform != "win32" and implementation_name == "cpython"
6+
uvloop==0.17.0; sys_platform != "win32" and implementation_name == "cpython"

src/__init__.py

Whitespace-only changes.

src/core/config.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""
2+
Run through console:
3+
4+
uvicorn src.main:app --host 127.0.0.1 --port 8080
5+
additional notes are in the `../README.md` file
6+
"""
7+
from pathlib import Path
8+
9+
from pydantic import BaseSettings
10+
11+
BASE_DIR = Path.cwd().parent.parent
12+
# print('BASE_DIR', BASE_DIR)
13+
14+
15+
class AppSettings(BaseSettings):
16+
# Don't use this name, set any name in '.env' file.
17+
PROJECT_NAME: str = "Default app's name"
18+
19+
class Config:
20+
env_file = '.env'
21+
22+
23+
app_settings = AppSettings()

src/main.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""
2+
Routs which work "from the box":
3+
4+
docs_url: "/docs" - Swagger
5+
redoc_url: "/redoc" - ReDoc
6+
openapi_url: "/openapi.json" - OpenAPI documentation
7+
"""
8+
from fastapi import FastAPI
9+
10+
from src.core import config
11+
12+
13+
def get_application():
14+
_app = FastAPI(
15+
title=config.app_settings.PROJECT_NAME,
16+
)
17+
18+
return _app
19+
20+
21+
app = get_application()

0 commit comments

Comments
 (0)