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
775478f1
Commit
775478f1
authored
Nov 24, 2023
by
Мырзабеков Бекайдар
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added priority by task and added filters and search tasks
parent
5b84b68d
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
84 additions
and
2 deletions
+84
-2
ctrl.py
src/app/api/task/ctrl.py
+3
-0
routes.py
src/app/api/task/routes.py
+11
-2
services.py
src/app/api/task/services.py
+4
-0
models.py
src/app/db/models.py
+20
-0
repositories.py
src/app/db/repositories.py
+35
-0
3_20231124055605_update.py
src/migrations/models/3_20231124055605_update.py
+11
-0
No files found.
src/app/api/task/ctrl.py
View file @
775478f1
...
...
@@ -71,3 +71,6 @@ class TaskController(BaseController):
except
common_exc
.
NotFoundException
as
e
:
raise
http_exc
.
HTTPNotFoundException
(
detail
=
str
(
e
))
async
def
search
(
self
,
keywords
:
str
):
return
await
self
.
task_service
.
search_tasks
(
keywords
)
src/app/api/task/routes.py
View file @
775478f1
...
...
@@ -14,8 +14,12 @@ ctrl = TaskController()
@
router
.
get
(
''
)
async
def
get_tasks
(
query
:
TaskBaseSchema
=
fastapi
.
Depends
()):
return
await
ctrl
.
get_list
(
**
query
.
model_dump
(
exclude_none
=
True
))
async
def
get_tasks
(
title
:
str
|
None
=
None
,
status
:
str
|
None
=
None
,
priority
:
str
|
None
=
None
):
return
await
ctrl
.
get_list
(
title
=
title
,
status
=
status
,
priority
=
priority
)
@
router
.
get
(
'/{id}'
)
...
...
@@ -51,3 +55,8 @@ async def add_comment(id: UUID, body: CommentSchema):
@
router
.
delete
(
'/comments/{id}'
)
async
def
delete_comment
(
id
:
UUID
):
return
await
ctrl
.
delete_comment
(
id
)
@
router
.
get
(
'/tasks/search'
)
async
def
search_tasks
(
keywords
:
str
):
return
await
ctrl
.
search
(
keywords
)
src/app/api/task/services.py
View file @
775478f1
...
...
@@ -109,3 +109,7 @@ class TaskService:
async
def
delete_comment
(
self
,
id
:
UUID
):
return
await
self
.
comment_repository
.
delete
(
id
)
async
def
search_tasks
(
self
,
keywords
:
str
):
tasks
=
await
self
.
task_repository
.
search
(
keywords
)
return
[
TaskListSchema
.
model_validate
(
task
)
for
task
in
tasks
]
src/app/db/models.py
View file @
775478f1
from
enum
import
Enum
from
tortoise
import
fields
from
.base
import
BaseModel
...
...
@@ -22,7 +24,14 @@ class Type(BaseModel):
table
=
'types'
class
PriorityEnum
(
str
,
Enum
):
LOW
=
'low'
MEDIUM
=
'medium'
HIGH
=
'high'
class
Task
(
BaseModel
):
title
=
fields
.
CharField
(
max_length
=
255
)
description
=
fields
.
TextField
()
status
=
fields
.
ForeignKeyField
(
...
...
@@ -33,6 +42,7 @@ class Task(BaseModel):
'models.Type'
,
related_name
=
'type_tasks'
,
through
=
'types_tasks'
)
priority
=
fields
.
CharEnumField
(
enum_type
=
PriorityEnum
,
default
=
PriorityEnum
.
LOW
)
def
__str__
(
self
):
return
self
.
title
...
...
@@ -65,3 +75,13 @@ class Comment(BaseModel):
class
Meta
:
table
=
'comments'
class
Category
(
BaseModel
):
name
=
fields
.
CharField
(
max_length
=
255
)
def
__str__
(
self
):
return
self
.
name
class
Meta
(
BaseModel
.
Meta
):
table
=
'categories'
src/app/db/repositories.py
View file @
775478f1
import
tortoise
from
tortoise.expressions
import
Q
from
.models
import
(
Status
,
Type
,
Task
,
User
,
Comment
...
...
@@ -56,6 +57,40 @@ class TypeRepository(BaseRepository):
class
TaskRepository
(
BaseRepository
):
model
=
Task
async
def
get_list
(
self
,
title
:
str
|
None
=
None
,
status
:
str
|
None
=
None
,
priority
:
str
|
None
=
None
):
query
=
self
.
model
if
title
is
not
None
:
query
=
query
.
filter
(
title__icontains
=
title
)
if
status
is
not
None
:
query
=
query
.
filter
(
status__name__icontains
=
status
)
if
priority
is
not
None
:
query
=
query
.
filter
(
priority
=
priority
)
return
await
query
.
all
()
async
def
search
(
self
,
keywords
:
str
):
query
=
self
.
model
search_terms
=
keywords
.
split
()
conditions
=
[
Q
(
title__icontains
=
term
)
|
Q
(
description__icontains
=
term
)
for
term
in
search_terms
]
combined_condition
=
conditions
.
pop
()
for
condition
in
conditions
:
combined_condition
|=
condition
query
=
query
.
filter
(
combined_condition
)
return
await
query
.
all
()
class
UserRepository
(
BaseRepository
):
model
=
User
...
...
src/migrations/models/3_20231124055605_update.py
0 → 100644
View file @
775478f1
from
tortoise
import
BaseDBAsyncClient
async
def
upgrade
(
db
:
BaseDBAsyncClient
)
->
str
:
return
"""
ALTER TABLE "tasks" ADD "priority" VARCHAR(6) NOT NULL DEFAULT 'low';"""
async
def
downgrade
(
db
:
BaseDBAsyncClient
)
->
str
:
return
"""
ALTER TABLE "tasks" DROP COLUMN "priority";"""
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