-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add retrieving project list to project service
- Loading branch information
1 parent
0f20365
commit d44d6b3
Showing
3 changed files
with
39 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,45 @@ | ||
from typing import List, Optional | ||
|
||
from sqlalchemy.orm import Session | ||
|
||
from app.services.user import user_service | ||
from netspresso.netspresso import NetsPresso | ||
from netspresso.utils.db.models.project import Project | ||
from netspresso.utils.db.repositories.base import Order | ||
from netspresso.utils.db.repositories.project import project_repository | ||
|
||
|
||
class ProjectService: | ||
def create_project(self, db: Session, project_name: str, api_key: str) -> Project: | ||
user = user_service.get_user_by_api_key(db=db, api_key=api_key) | ||
|
||
netspresso = NetsPresso(email=user.email, password=user.password) | ||
netspresso = user_service.build_netspresso_with_api_key(db=db, api_key=api_key) | ||
|
||
project = netspresso.create_project(project_name=project_name) | ||
|
||
return project | ||
|
||
def check_project_duplication(self, db: Session, project_name: str, api_key: str) -> bool: | ||
user = user_service.get_user_by_api_key(db=db, api_key=api_key) | ||
|
||
netspresso = NetsPresso(email=user.email, password=user.password) | ||
netspresso = user_service.build_netspresso_with_api_key(db=db, api_key=api_key) | ||
|
||
is_duplicated = project_repository.is_project_name_duplicated( | ||
db=db, project_name=project_name, user_id=netspresso.user_info.user_id | ||
) | ||
|
||
return is_duplicated | ||
|
||
def get_projects( | ||
self, *, db: Session, start: Optional[int], size: Optional[int], order: Order, api_key: str | ||
) -> List[Project]: | ||
netspresso = user_service.build_netspresso_with_api_key(db=db, api_key=api_key) | ||
|
||
projects = project_repository.get_all_by_user_id( | ||
db=db, user_id=netspresso.user_info.user_id, start=start, size=size, order=order | ||
) | ||
|
||
return projects | ||
|
||
def count_project_by_user_id(self, *, db: Session, api_key: str) -> int: | ||
netspresso = user_service.build_netspresso_with_api_key(db=db, api_key=api_key) | ||
|
||
return project_repository.count_by_user_id(db=db, user_id=netspresso.user_info.user_id) | ||
|
||
|
||
project_service = ProjectService() |
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