Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uuid in read project and total_task in generate-log #978

Merged
merged 4 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/backend/app/projects/project_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -2821,3 +2821,13 @@ def is_valid_coordinate(coord):
if not is_valid_coordinate(first_coordinate):
log.error(error_message)
raise HTTPException(status_code=400, detail=error_message)


def get_tasks_count(db: Session, project_id: int):
db_task = (
db.query(db_models.DbProject)
.filter(db_models.DbProject.id == project_id)
.first()
)
task_count = len(db_task.tasks)
return task_count
5 changes: 4 additions & 1 deletion src/backend/app/projects/project_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ async def read_project_summaries(
async def read_project(project_id: int, db: Session = Depends(database.get_db)):
project = project_crud.get_project_by_id(db, project_id)
if project:
project.project_uuid = uuid.uuid4()
return project
else:
raise HTTPException(status_code=404, detail="Project not found")
Expand Down Expand Up @@ -222,8 +223,8 @@ async def create_project(
project = project_crud.create_project_with_project_info(
db, project_info, odkproject["id"]
)

if project:
project.project_uuid = uuid.uuid4()
return project
else:
raise HTTPException(status_code=404, detail="Project not found")
Expand Down Expand Up @@ -800,8 +801,10 @@ async def generate_log(
last_50_logs = filtered_logs[-50:]

logs = "\n".join(last_50_logs)
task_count = project_crud.get_tasks_count(db, project_id)
return {
"status": task_status.name,
"total_tasks": task_count,
"message": task_message,
"progress": extract_completion_count,
"logs": logs,
Expand Down
2 changes: 2 additions & 0 deletions src/backend/app/projects/project_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# along with FMTM. If not, see <https:#www.gnu.org/licenses/>.
#

import uuid
from typing import List, Optional, Union

from geojson_pydantic import Feature as GeojsonFeature
Expand Down Expand Up @@ -132,4 +133,5 @@ class ProjectBase(BaseModel):


class ProjectOut(ProjectBase):
project_uuid: uuid.UUID
pass