Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
F
fa_2_article
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
Мырзабеков Бекайдар
fa_2_article
Commits
3254041a
Commit
3254041a
authored
Dec 26, 2023
by
Мырзабеков Бекайдар
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added get token
parent
4d5c5424
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
44 additions
and
1 deletion
+44
-1
routes.py
code/api/article/routes.py
+10
-0
router.py
code/api/router.py
+2
-1
schemas.py
code/api/schemas.py
+7
-0
services.py
code/api/services.py
+23
-0
reqs.txt
reqs.txt
+2
-0
No files found.
code/api/article/routes.py
View file @
3254041a
from
uuid
import
UUID
from
starlette
import
status
import
fastapi
as
fa
from
fastapi.security
import
OAuth2PasswordRequestForm
from
api
import
schemas
from
db.repository
import
ArticleRepository
from
exceptions
import
common
as
common_exc
,
http
as
http_exc
from
.validate
import
is_valid_user
from
..services
import
auth_service
router
=
fa
.
APIRouter
(
prefix
=
'/article'
,
tags
=
[
'article'
])
auth_router
=
fa
.
APIRouter
(
prefix
=
'/auth'
,
tags
=
[
'Auth'
])
repo
=
ArticleRepository
()
...
...
@@ -65,3 +68,10 @@ async def delete_article(id: UUID):
except
common_exc
.
NotFoundExcepton
as
e
:
raise
http_exc
.
HTTPNotFoundException
(
detail
=
str
(
e
))
@
auth_router
.
post
(
'/login'
)
async
def
login
(
form_data
:
OAuth2PasswordRequestForm
=
fa
.
Depends
(),
):
return
await
auth_service
.
login
(
form_data
)
code/api/router.py
View file @
3254041a
...
...
@@ -3,13 +3,14 @@ import fastapi as fa
from
starlette
import
status
from
api.article.routes
import
router
as
article_router
from
api.article.routes
import
router
as
article_router
,
auth_router
as
auth_route
from
adapters
import
MinIOClient
import
settings
router
=
fa
.
APIRouter
(
prefix
=
'/api'
)
router
.
include_router
(
article_router
)
router
.
include_router
(
auth_route
)
@
router
.
get
(
'/greetings'
)
def
get_greetings
():
...
...
code/api/schemas.py
View file @
3254041a
from
uuid
import
UUID
from
dataclasses
import
dataclass
import
pydantic
...
...
@@ -18,3 +19,9 @@ class ArticleGetSchema(pydantic.BaseModel):
class
ArticleUpdateSchema
(
pydantic
.
BaseModel
):
name
:
str
|
None
=
pydantic
.
Field
(
None
)
description
:
str
|
None
=
pydantic
.
Field
(
None
)
@
dataclass
class
LoginRequestModel
:
username
:
str
password
:
str
code/api/services.py
0 → 100644
View file @
3254041a
import
httpx
from
.schemas
import
LoginRequestModel
from
exceptions
import
http
as
http_exc
class
AuthService
:
auth_service_url
=
"http://auth-core-1:8000/api/auth/login"
async
def
login
(
self
,
data
:
LoginRequestModel
):
async
with
httpx
.
AsyncClient
()
as
client
:
response
=
await
client
.
post
(
self
.
auth_service_url
,
data
=
{
"username"
:
data
.
username
,
"password"
:
data
.
password
},
)
if
response
.
status_code
==
200
:
return
response
.
json
()
else
:
raise
http_exc
.
HTTPNotFoundException
(
detail
=
'Incorrect username or password'
)
auth_service
=
AuthService
()
reqs.txt
View file @
3254041a
...
...
@@ -17,6 +17,8 @@ ecdsa==0.18.0
exceptiongroup==1.2.0
fastapi==0.106.0
h11==0.14.0
httpcore==1.0.2
httpx==0.26.0
idna==3.6
iso8601==1.1.0
minio==7.2.0
...
...
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