-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore:update user_service create new user when user_id not exist
- Loading branch information
jingooo5
committed
Nov 2, 2024
1 parent
8187161
commit 2b861fc
Showing
5 changed files
with
48 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from Database.database import get_db | ||
from Database.models import User | ||
from Service.useritem_service import UserItemService | ||
|
||
|
||
class UserService: | ||
@staticmethod | ||
def get_user_by_id(user_id: str): | ||
with get_db() as db: | ||
return db.query(User).filter(User.user_id == user_id).first() | ||
|
||
@staticmethod | ||
def get_user_or_create(user_id: str, name=None, password="1234"): | ||
user = UserService.get_user_by_id(user_id) | ||
if user is None: | ||
with get_db() as db: | ||
user = User(name=user_id[:8] if name is None else name, password=password) | ||
db.add(user) | ||
db.commit() | ||
db.refresh(user) | ||
UserItemService.init_userItem(user.user_id) | ||
return user |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters