-
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.
Merge branch 'main' of https://github.com/Uni-dthon/mirisa_server
- Loading branch information
Showing
6 changed files
with
50 additions
and
28 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
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