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
5f097349
Commit
5f097349
authored
Dec 04, 2023
by
Мырзабеков Бекайдар
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added integrated authentication
parent
6727f5eb
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
105 additions
and
17 deletions
+105
-17
routes.py
src/app/api/category/routes.py
+13
-3
dependencies.py
src/app/api/dependencies.py
+41
-0
routes.py
src/app/api/status/routes.py
+13
-3
routes.py
src/app/api/task/routes.py
+24
-8
routes.py
src/app/api/type/routes.py
+14
-3
No files found.
src/app/api/category/routes.py
View file @
5f097349
...
...
@@ -4,6 +4,7 @@ import fastapi
from
.schemas
import
CategoryBaseSchema
from
.ctrl
import
CategoryController
from
..dependencies
import
get_current_user
router
=
fastapi
.
APIRouter
(
prefix
=
'/categories'
,
tags
=
[
'Category'
])
...
...
@@ -21,15 +22,24 @@ async def get_category(id: UUID):
@
router
.
post
(
''
)
async
def
create_category
(
body
:
CategoryBaseSchema
):
async
def
create_category
(
body
:
CategoryBaseSchema
,
current_user
:
str
=
fastapi
.
Depends
(
get_current_user
)
):
return
await
ctrl
.
create
(
**
body
.
model_dump
(
exclude_none
=
True
))
@
router
.
patch
(
'/{id}'
)
async
def
update_category
(
id
:
UUID
,
body
:
CategoryBaseSchema
):
async
def
update_category
(
id
:
UUID
,
body
:
CategoryBaseSchema
,
current_user
:
str
=
fastapi
.
Depends
(
get_current_user
)
):
return
await
ctrl
.
update
(
id
,
**
body
.
model_dump
(
exclude_none
=
True
))
@
router
.
delete
(
'/{id}'
)
async
def
delete_category
(
id
:
UUID
):
async
def
delete_category
(
id
:
UUID
,
current_user
:
str
=
fastapi
.
Depends
(
get_current_user
)
):
return
await
ctrl
.
delete
(
id
)
src/app/api/dependencies.py
0 → 100644
View file @
5f097349
import
os
import
fastapi
as
fa
from
fastapi
import
Depends
,
HTTPException
,
status
from
jose
import
jwt
,
JWTError
SECRET_KEY
=
os
.
getenv
(
'SECRET_KEY'
)
ALGORITHM
=
os
.
getenv
(
'ALGORITHM'
)
def
get_token
(
token
:
str
=
fa
.
Header
(
...
)):
return
token
def
authenticate_user
(
token
:
str
=
Depends
(
get_token
)):
credentials_exception
=
HTTPException
(
status_code
=
status
.
HTTP_401_UNAUTHORIZED
,
detail
=
"Could not validate credentials"
,
headers
=
{
"WWW-Authenticate"
:
"Bearer"
},
)
try
:
payload
=
jwt
.
decode
(
token
,
SECRET_KEY
,
algorithms
=
[
ALGORITHM
])
username
:
str
=
payload
.
get
(
"sub"
)
if
username
is
None
:
raise
credentials_exception
return
username
except
JWTError
:
raise
credentials_exception
def
get_current_user
(
username
:
str
=
Depends
(
authenticate_user
)):
if
username
==
"johndoe"
or
username
==
'janedoe'
:
return
username
else
:
raise
HTTPException
(
status_code
=
status
.
HTTP_401_UNAUTHORIZED
,
detail
=
"Not authorized"
,
headers
=
{
"WWW-Authenticate"
:
"Bearer"
},
)
src/app/api/status/routes.py
View file @
5f097349
...
...
@@ -4,6 +4,7 @@ import fastapi
from
.schemas
import
StatusBaseSchema
from
.ctrl
import
StatusController
from
..dependencies
import
get_current_user
router
=
fastapi
.
APIRouter
(
prefix
=
'/statuses'
,
tags
=
[
'Status'
])
...
...
@@ -21,15 +22,24 @@ async def get_status(id: UUID):
@
router
.
post
(
''
)
async
def
create_status
(
body
:
StatusBaseSchema
):
async
def
create_status
(
body
:
StatusBaseSchema
,
current_user
:
str
=
fastapi
.
Depends
(
get_current_user
)
):
return
await
ctrl
.
create
(
**
body
.
model_dump
(
exclude_none
=
True
))
@
router
.
patch
(
'/{id}'
)
async
def
update_status
(
id
:
UUID
,
body
:
StatusBaseSchema
):
async
def
update_status
(
id
:
UUID
,
body
:
StatusBaseSchema
,
current_user
:
str
=
fastapi
.
Depends
(
get_current_user
)
):
return
await
ctrl
.
update
(
id
,
**
body
.
model_dump
(
exclude_none
=
True
))
@
router
.
delete
(
'/{id}'
)
async
def
delete_status
(
id
:
UUID
):
async
def
delete_status
(
id
:
UUID
,
current_user
:
str
=
fastapi
.
Depends
(
get_current_user
)
):
return
await
ctrl
.
delete
(
id
)
src/app/api/task/routes.py
View file @
5f097349
from
uuid
import
UUID
import
fastapi
from
fastapi_pagination
import
Page
,
paginate
from
.schemas
import
(
TaskBaseSchema
,
TaskPostSchema
,
TaskPatchSchema
,
CommentSchema
TaskPostSchema
,
TaskPatchSchema
,
CommentSchema
)
from
.ctrl
import
TaskController
from
..dependencies
import
get_current_user
router
=
fastapi
.
APIRouter
(
prefix
=
'/tasks'
,
tags
=
[
'Task'
])
...
...
@@ -40,17 +39,27 @@ async def get_task(id: UUID):
@
router
.
post
(
''
)
async
def
create_task
(
body
:
TaskPostSchema
):
async
def
create_task
(
body
:
TaskPostSchema
,
current_user
:
str
=
fastapi
.
Depends
(
get_current_user
)
):
return
await
ctrl
.
create
(
**
body
.
model_dump
(
exclude_none
=
True
))
@
router
.
patch
(
'/{id}'
)
async
def
update_task
(
id
:
UUID
,
body
:
TaskPatchSchema
):
async
def
update_task
(
id
:
UUID
,
body
:
TaskPatchSchema
,
current_user
:
str
=
fastapi
.
Depends
(
get_current_user
)
):
return
await
ctrl
.
update
(
id
,
**
body
.
model_dump
(
exclude_none
=
True
))
@
router
.
delete
(
'/{id}'
)
async
def
delete_task
(
id
:
UUID
):
async
def
delete_task
(
id
:
UUID
,
current_user
:
str
=
fastapi
.
Depends
(
get_current_user
)
):
return
await
ctrl
.
delete
(
id
)
...
...
@@ -60,12 +69,19 @@ async def get_comments(id: UUID):
@
router
.
post
(
'/{id}/comments'
)
async
def
add_comment
(
id
:
UUID
,
body
:
CommentSchema
):
async
def
add_comment
(
id
:
UUID
,
body
:
CommentSchema
,
current_user
:
str
=
fastapi
.
Depends
(
get_current_user
)
):
return
await
ctrl
.
add_comment
(
id
,
**
body
.
model_dump
(
exclude_none
=
True
))
@
router
.
delete
(
'/comments/{id}'
)
async
def
delete_comment
(
id
:
UUID
):
async
def
delete_comment
(
id
:
UUID
,
current_user
:
str
=
fastapi
.
Depends
(
get_current_user
)
):
return
await
ctrl
.
delete_comment
(
id
)
...
...
src/app/api/type/routes.py
View file @
5f097349
...
...
@@ -4,6 +4,7 @@ import fastapi
from
.schemas
import
TypeBaseSchema
from
.ctrl
import
TypeController
from
..dependencies
import
get_current_user
router
=
fastapi
.
APIRouter
(
prefix
=
'/types'
,
tags
=
[
'Type'
])
...
...
@@ -21,15 +22,25 @@ async def get_type(id: UUID):
@
router
.
post
(
''
)
async
def
create_type
(
body
:
TypeBaseSchema
):
async
def
create_type
(
body
:
TypeBaseSchema
,
current_user
:
str
=
fastapi
.
Depends
(
get_current_user
)
):
return
await
ctrl
.
create
(
**
body
.
model_dump
(
exclude_none
=
True
))
@
router
.
patch
(
'/{id}'
)
async
def
update_type
(
id
:
UUID
,
body
:
TypeBaseSchema
):
async
def
update_type
(
id
:
UUID
,
body
:
TypeBaseSchema
,
current_user
:
str
=
fastapi
.
Depends
(
get_current_user
)
):
return
await
ctrl
.
update
(
id
,
**
body
.
model_dump
(
exclude_none
=
True
))
@
router
.
delete
(
'/{id}'
)
async
def
delete_type
(
id
:
UUID
):
async
def
delete_type
(
id
:
UUID
,
current_user
:
str
=
fastapi
.
Depends
(
get_current_user
)
):
return
await
ctrl
.
delete
(
id
)
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