initial project

parents
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
media/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
.python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
data/
.idea
This diff is collapsed.
[tool.poetry]
name = "fast-api-hw-4"
version = "0.1.0"
description = ""
authors = ["beka <beka1990.30.10@gmail.com>"]
readme = "README.md"
[tool.poetry.dependencies]
python = "^3.10"
uvicorn = "^0.24.0.post1"
fastapi = "^0.104.1"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
import fastapi
from pydantic import BaseModel
router = fastapi.APIRouter(prefix='/api')
words = [
{"id": 1, "name": "Баг"}, {"id": 2, "name": "Задача"}, {"id": 3, "name": "Тикет"}, {"id": 4, "name": "Приоритет"},
{"id": 5, "name": "Отчёт об ошибке"}
]
class Task(BaseModel):
name: str
@router.get('/tasks')
async def tasks():
return words
@router.get('/tasks/{id_}')
async def get_task(id_: int):
for word in words:
if word['id'] == id_:
return word
return {"error": "Задача не найдена"}
@router.post('/tasks')
async def create_task(task: Task):
id_ = len(words) + 1
task = {"id": id_, "name": task.name}
words.append(task)
return task
@router.put('/tasks/{id_}')
async def update_task(id_: int, task: Task):
for word in words:
if word['id'] == id_:
word['name'] = task.name
return word
return {"error": "Задача не найдена"}
app = fastapi.FastAPI()
app.include_router(router)
if __name__ == '__main__':
import uvicorn
uvicorn.run('main:app', host='localhost', port=8000, reload=True)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment