Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
financial-system
Project
Project
Details
Activity
Releases
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
xianyang
financial-system
Commits
a079804c
Commit
a079804c
authored
Feb 08, 2023
by
xianyang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化db
parent
2eaa91cb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
22 deletions
+14
-22
__init__.py
app/__init__.py
+11
-1
views.py
app/api/users/views.py
+3
-21
No files found.
app/__init__.py
View file @
a079804c
import
pymysql
import
pymysql
pymysql
.
install_as_MySQLdb
()
pymysql
.
install_as_MySQLdb
()
from
core.storage.db
import
SessionLocal
def
get_db
():
db
=
SessionLocal
()
try
:
yield
db
finally
:
db
.
close
()
app/api/users/views.py
View file @
a079804c
from
app
import
get_db
from
typing
import
List
from
typing
import
List
from
fastapi
import
Depends
,
APIRouter
,
HTTPException
,
FastAPI
from
fastapi.security
import
OAuth2PasswordRequestForm
from
sqlalchemy.orm
import
Session
from
sqlalchemy.orm
import
Session
import
models
from
app.api.users
import
crud
,
schemas
from
app.api.users
import
crud
,
schemas
from
core.storage.db
import
SessionLocal
from
fastapi
import
Depends
,
APIRouter
,
HTTPException
from
libs.result_format
import
HttpResultResponse
,
HttpMessage
from
libs.result_format
import
HttpResultResponse
,
HttpMessage
router
=
APIRouter
()
router
=
APIRouter
()
def
get_db
():
db
=
SessionLocal
()
try
:
yield
db
finally
:
db
.
close
()
# @router.post("/", response_model=schemas.User)
# def create_user(user: schemas.UserCreate, db: Session = Depends(get_db)):
# db_user = crud.get_user_by_email(db, email=user.email)
# if db_user:
# raise HTTPException(status_code=400, detail="Email already registered")
# return crud.create_user(db=db, user=user)
@
router
.
get
(
"/"
,
response_model
=
List
[
schemas
.
User
])
@
router
.
get
(
"/"
,
response_model
=
List
[
schemas
.
User
])
def
read_users
(
skip
:
int
=
0
,
limit
:
int
=
100
,
db
:
Session
=
Depends
(
get_db
)):
def
read_users
(
skip
:
int
=
0
,
limit
:
int
=
100
,
db
:
Session
=
Depends
(
get_db
)):
users
=
crud
.
get_users
(
db
,
skip
=
skip
,
limit
=
limit
)
users
=
crud
.
get_users
(
db
,
skip
=
skip
,
limit
=
limit
)
...
@@ -57,7 +39,7 @@ def login():
...
@@ -57,7 +39,7 @@ def login():
# access_token_expires = timedelta(minutes=config.ACCESS_TOKEN_EXPIRE_MINUTES)
# access_token_expires = timedelta(minutes=config.ACCESS_TOKEN_EXPIRE_MINUTES)
return
{
return
{
"token_type"
:
"bearer"
,
"token_type"
:
"bearer"
}
}
...
...
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