Skip to content

Commit

Permalink
Add create_project function to project service
Browse files Browse the repository at this point in the history
  • Loading branch information
Only-bottle committed Dec 6, 2024
1 parent b0038e7 commit b83ab56
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
15 changes: 9 additions & 6 deletions app/api/v1/endpoints/project.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from typing import Optional
from uuid import uuid4

from fastapi import APIRouter
from fastapi import APIRouter, Depends
from sqlalchemy.orm import Session

from app.api.deps import api_key_header
from app.api.v1.schemas.project import (
ExperimentStatus,
ModelSummary,
Expand All @@ -15,21 +17,22 @@
ProjectsResponse,
ProjectSummaryPayload,
)
from app.services.project import project_service
from netspresso.utils.db.session import get_db

router = APIRouter()


@router.post("", response_model=ProjectResponse)
def create_project(
*,
db: Session = Depends(get_db),
api_key: str = Depends(api_key_header),
request_body: ProjectCreate,
) -> ProjectResponse:
project = project_service.create_project(db=db, project_name=request_body.project_name, api_key=api_key)

project = ProjectSummaryPayload(
project_id=str(uuid4()),
project_name=request_body.project_name,
user_id=str(uuid4()),
)
project = ProjectSummaryPayload.model_validate(project)

return ProjectResponse(data=project)

Expand Down
19 changes: 19 additions & 0 deletions app/services/project.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
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


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)

project = netspresso.create_project(project_name=project_name)

return project


project_service = ProjectService()

0 comments on commit b83ab56

Please sign in to comment.