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
300cf36e
Commit
300cf36e
authored
Feb 07, 2023
by
xianyang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化代码
parent
1095519a
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
71 additions
and
8 deletions
+71
-8
crud.py
app/api/users/crud.py
+37
-0
schemas.py
app/api/users/schemas.py
+17
-0
views.py
app/api/users/views.py
+2
-8
__init__.py
models/__init__.py
+0
-0
users.py
models/users.py
+15
-0
No files found.
app/api/users/crud.py
0 → 100644
View file @
300cf36e
from
sqlalchemy.orm
import
Session
from
app.api.users
import
schemas
from
models
import
users
as
models
def
get_user
(
db
:
Session
,
user_id
:
int
):
return
db
.
query
(
models
.
User
)
.
filter
(
models
.
User
.
id
==
user_id
)
.
first
()
def
get_user_by_email
(
db
:
Session
,
email
:
str
):
return
db
.
query
(
models
.
User
)
.
filter
(
models
.
User
.
email
==
email
)
.
first
()
def
get_users
(
db
:
Session
,
skip
:
int
=
0
,
limit
:
int
=
100
):
return
db
.
query
(
models
.
User
)
.
offset
(
skip
)
.
limit
(
limit
)
.
all
()
def
create_user
(
db
:
Session
,
user
:
schemas
.
UserCreate
):
fake_hashed_password
=
user
.
password
+
"notreallyhashed"
db_user
=
models
.
User
(
email
=
user
.
email
,
hashed_password
=
fake_hashed_password
)
db
.
add
(
db_user
)
db
.
commit
()
db
.
refresh
(
db_user
)
return
db_user
def
get_items
(
db
:
Session
,
skip
:
int
=
0
,
limit
:
int
=
100
):
return
db
.
query
(
models
.
Item
)
.
offset
(
skip
)
.
limit
(
limit
)
.
all
()
def
create_user_item
(
db
:
Session
,
item
:
schemas
.
ItemCreate
,
user_id
:
int
):
db_item
=
models
.
Item
(
**
item
.
dict
(),
owner_id
=
user_id
)
db
.
add
(
db_item
)
db
.
commit
()
db
.
refresh
(
db_item
)
return
db_item
\ No newline at end of file
app/api/users/schemas.py
0 → 100644
View file @
300cf36e
from
pydantic
import
BaseModel
class
UserBase
(
BaseModel
):
email
:
str
class
UserCreate
(
UserBase
):
password
:
str
class
User
(
UserBase
):
id
:
int
is_active
:
bool
class
Config
:
orm_mode
=
True
\ No newline at end of file
app/api/users/views.py
View file @
300cf36e
...
@@ -2,7 +2,8 @@ from typing import List
...
@@ -2,7 +2,8 @@ from typing import List
from
fastapi
import
Depends
,
APIRouter
,
HTTPException
,
FastAPI
from
fastapi
import
Depends
,
APIRouter
,
HTTPException
,
FastAPI
from
sqlalchemy.orm
import
Session
from
sqlalchemy.orm
import
Session
from
app.users
import
crud
,
models
,
schemas
from
app.api.users
import
crud
,
schemas
from
models
import
users
from
core.storage.db
import
SessionLocal
from
core.storage.db
import
SessionLocal
...
@@ -48,13 +49,6 @@ def create_item_for_user(
...
@@ -48,13 +49,6 @@ def create_item_for_user(
return
crud
.
create_user_item
(
db
=
db
,
item
=
item
,
user_id
=
user_id
)
return
crud
.
create_user_item
(
db
=
db
,
item
=
item
,
user_id
=
user_id
)
# @router.get("/items", response_model=schemas.Item)
# def createm_for_user(
# user_id: int, item: schemas.ItemCreate, db: Session = Depends(get_db)
# ):
# return {'message': 'Hello demo Applications!'}
@
router
.
get
(
"/items"
,
tags
=
[
'GET'
,
'POST'
])
@
router
.
get
(
"/items"
,
tags
=
[
'GET'
,
'POST'
])
def
ceshi
():
def
ceshi
():
return
{
'message'
:
'Hello demo Adsadsadsadsadaspplications!'
}
return
{
'message'
:
'Hello demo Adsadsadsadsadaspplications!'
}
mod
ule
s/__init__.py
→
mod
el
s/__init__.py
View file @
300cf36e
File moved
models/users.py
0 → 100644
View file @
300cf36e
from
sqlalchemy
import
Boolean
,
Column
,
ForeignKey
,
Integer
,
String
from
sqlalchemy.orm
import
relationship
from
core.storage.db
import
Base
class
User
(
Base
):
__tablename__
=
"users"
id
=
Column
(
Integer
,
primary_key
=
True
,
index
=
True
)
email
=
Column
(
String
,
unique
=
True
,
index
=
True
)
hashed_password
=
Column
(
String
)
is_active
=
Column
(
Boolean
,
default
=
True
)
items
=
relationship
(
"Item"
,
back_populates
=
"owner"
)
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