Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
F
fast_api_hw_4
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Мырзабеков Бекайдар
fast_api_hw_4
Commits
963b6a06
Commit
963b6a06
authored
Nov 11, 2023
by
Мырзабеков Бекайдар
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added delete task endpoint
parent
fa1b4264
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
10 deletions
+22
-10
main.py
src/app/main.py
+22
-10
No files found.
src/app/main.py
View file @
963b6a06
...
...
@@ -4,10 +4,12 @@ from pydantic import BaseModel
router
=
fastapi
.
APIRouter
(
prefix
=
'/api'
)
words
=
[
class
Tasks
:
tasks
=
[
{
"id"
:
1
,
"name"
:
"Баг"
},
{
"id"
:
2
,
"name"
:
"Задача"
},
{
"id"
:
3
,
"name"
:
"Тикет"
},
{
"id"
:
4
,
"name"
:
"Приоритет"
},
{
"id"
:
5
,
"name"
:
"Отчёт об ошибке"
}
]
]
class
Task
(
BaseModel
):
...
...
@@ -16,12 +18,12 @@ class Task(BaseModel):
@
router
.
get
(
'/tasks'
)
async
def
tasks
():
return
word
s
return
Tasks
.
task
s
@
router
.
get
(
'/tasks/{id_}'
)
async
def
get_task
(
id_
:
int
):
for
word
in
word
s
:
for
word
in
Tasks
.
task
s
:
if
word
[
'id'
]
==
id_
:
return
word
return
{
"error"
:
"Задача не найдена"
}
...
...
@@ -29,21 +31,31 @@ async def get_task(id_: int):
@
router
.
post
(
'/tasks'
)
async
def
create_task
(
task
:
Task
):
id_
=
len
(
word
s
)
+
1
id_
=
len
(
Tasks
.
task
s
)
+
1
task
=
{
"id"
:
id_
,
"name"
:
task
.
name
}
word
s
.
append
(
task
)
Tasks
.
task
s
.
append
(
task
)
return
task
@
router
.
put
(
'/tasks/{id_}'
)
async
def
update_task
(
id_
:
int
,
task
:
Task
):
for
word
in
word
s
:
for
word
in
Tasks
.
task
s
:
if
word
[
'id'
]
==
id_
:
word
[
'name'
]
=
task
.
name
return
word
return
{
"error"
:
"Задача не найдена"
}
@
router
.
delete
(
'/tasks/{id_}'
)
async
def
delete_task
(
id_
:
int
):
for
word
in
Tasks
.
tasks
:
if
word
[
'id'
]
==
id_
:
Tasks
.
tasks
.
remove
(
word
)
return
{
"message"
:
"Задача успешно удалена"
}
return
{
"error"
:
"Задача не найдена"
}
app
=
fastapi
.
FastAPI
()
app
.
include_router
(
router
)
...
...
@@ -51,4 +63,4 @@ app.include_router(router)
if
__name__
==
'__main__'
:
import
uvicorn
uvicorn
.
run
(
'main:app'
,
host
=
'
localhost
'
,
port
=
8000
,
reload
=
True
)
uvicorn
.
run
(
'main:app'
,
host
=
'
0.0.0.0
'
,
port
=
8000
,
reload
=
True
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment