Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
T
task_treker
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
Мырзабеков Бекайдар
task_treker
Commits
6c6de67b
Commit
6c6de67b
authored
Nov 24, 2023
by
Мырзабеков Бекайдар
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added pagination by task list
parent
da8cb704
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
187 additions
and
122 deletions
+187
-122
poetry.lock
poetry.lock
+144
-111
pyproject.toml
pyproject.toml
+1
-0
routes.py
src/app/api/task/routes.py
+12
-4
schemas.py
src/app/api/task/schemas.py
+0
-1
services.py
src/app/api/task/services.py
+7
-2
repositories.py
src/app/db/repositories.py
+23
-4
No files found.
poetry.lock
View file @
6c6de67b
This diff is collapsed.
Click to expand it.
pyproject.toml
View file @
6c6de67b
...
...
@@ -12,6 +12,7 @@ uvicorn = "^0.24.0.post1"
tortoise-orm
=
{extras
=
["asyncodbc"]
,
version
=
"^0.20.0"
}
aerich
=
"^0.7.2"
asyncpg
=
"^0.29.0"
fastapi-pagination
=
"^0.12.12"
...
...
src/app/api/task/routes.py
View file @
6c6de67b
from
uuid
import
UUID
import
fastapi
from
fastapi_pagination
import
Page
,
paginate
from
.schemas
import
(
TaskBaseSchema
,
TaskPostSchema
,
TaskPatchSchema
,
...
...
@@ -18,14 +19,21 @@ async def get_tasks(
title
:
str
|
None
=
None
,
status
:
str
|
None
=
None
,
category
:
str
|
None
=
None
,
priority
:
str
|
None
=
None
priority
:
str
|
None
=
None
,
sort_by
:
str
|
None
=
None
,
page
:
int
=
1
,
size
:
int
=
10
,
):
return
await
ctrl
.
get_list
(
title
=
title
,
status
=
status
,
category
=
category
,
priority
=
priority
title
=
title
,
status
=
status
,
category
=
category
,
priority
=
priority
,
sort_by
=
sort_by
,
page
=
page
,
size
=
size
,
)
@
router
.
get
(
'/{id}'
)
async
def
get_task
(
id
:
UUID
):
return
await
ctrl
.
get
(
id
)
...
...
src/app/api/task/schemas.py
View file @
6c6de67b
...
...
@@ -10,7 +10,6 @@ class TaskBaseSchema(BaseModel):
class
TaskIdSchema
(
BaseModel
):
id
:
UUID
model_config
=
ConfigDict
(
from_attributes
=
True
)
...
...
src/app/api/task/services.py
View file @
6c6de67b
...
...
@@ -6,7 +6,7 @@ from db.repositories import (
)
from
exceptions
import
common
as
common_exc
,
http
as
http_exc
from
db.models
import
Type
,
Status
from
.schemas
import
TaskListSchema
,
CommentSchema
from
.schemas
import
TaskListSchema
class
TaskService
:
...
...
@@ -18,7 +18,12 @@ class TaskService:
async
def
get_task_list
(
self
,
**
kwargs
):
tasks
=
await
self
.
task_repository
.
get_list
(
**
kwargs
)
return
[
TaskListSchema
.
model_validate
(
task
)
for
task
in
tasks
]
return
{
"page"
:
tasks
[
'page'
],
"size"
:
tasks
[
'size'
],
"total"
:
tasks
[
'total'
],
"result"
:
[
TaskListSchema
.
model_validate
(
task
)
for
task
in
tasks
[
'result'
]]
}
async
def
get_task
(
self
,
id
:
UUID
):
task
=
await
self
.
task_repository
.
get
(
id
=
id
)
...
...
src/app/db/repositories.py
View file @
6c6de67b
import
math
import
tortoise
from
tortoise.expressions
import
Q
...
...
@@ -62,9 +64,15 @@ class TaskRepository(BaseRepository):
title
:
str
|
None
=
None
,
status
:
str
|
None
=
None
,
category
:
str
|
None
=
None
,
priority
:
str
|
None
=
None
priority
:
str
|
None
=
None
,
sort_by
:
str
|
None
=
None
,
page
:
int
|
None
=
None
,
size
:
int
|
None
=
None
):
query
=
self
.
model
query
=
self
.
model
.
all
()
offset_min
=
(
page
-
1
)
*
size
offset_max
=
page
*
size
if
title
is
not
None
:
query
=
query
.
filter
(
title__icontains
=
title
)
...
...
@@ -78,9 +86,20 @@ class TaskRepository(BaseRepository):
if
priority
is
not
None
:
query
=
query
.
filter
(
priority
=
priority
)
return
await
query
.
all
()
if
sort_by
is
not
None
:
query
=
query
.
order_by
(
sort_by
)
data
=
await
query
result
=
{
"page"
:
page
,
"size"
:
size
,
"total"
:
math
.
ceil
(
len
(
data
)
/
size
)
-
1
,
"result"
:
data
[
offset_min
:
offset_max
]
}
return
result
async
def
search
(
self
,
keywords
:
str
):
async
def
search
(
self
,
keywords
:
str
):
query
=
self
.
model
search_terms
=
keywords
.
split
()
...
...
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