Skip to content

Commit

Permalink
Merge pull request #6713 from hotosm/fastapi-refactor
Browse files Browse the repository at this point in the history
interests and license deletion message and cron service
  • Loading branch information
prabinoid authored Jan 24, 2025
2 parents 98b2bb3 + 1921714 commit 6eb2efb
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 12 deletions.
12 changes: 0 additions & 12 deletions backend/models/postgis/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -814,18 +814,6 @@ async def get_all_tasks(project_id: int, db: Database):
rows = await db.fetch_all(query=query, values=values)
return rows

# @staticmethod
# def get_tasks_by_status(project_id: int, status: str):
# "Returns all tasks filtered by status in a project"
# return (
# session.query(Task)
# .filter(
# Task.project_id == project_id,
# Task.task_status == TaskStatus[status].value,
# )
# .all()
# )

@staticmethod
async def get_tasks_by_status(project_id: int, status: str, db: Database):
"""
Expand Down
31 changes: 31 additions & 0 deletions backend/services/interests_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,37 @@ async def get_all_interests(db: Database) -> InterestsListDTO:

@staticmethod
async def delete(interest_id: int, db: Database):
check_user_association_query = """
SELECT 1
FROM user_interests
WHERE interest_id = :interest_id
LIMIT 1;
"""

user_associated = await db.fetch_one(
check_user_association_query, {"interest_id": interest_id}
)
if user_associated:
raise HTTPException(
status_code=500,
detail="Interest is associated with a user and cannot be deleted.",
)

check_project_association_query = """
SELECT 1
FROM project_interests
WHERE interest_id = :interest_id
LIMIT 1;
"""
project_associated = await db.fetch_one(
check_project_association_query, {"interest_id": interest_id}
)
if project_associated:
raise HTTPException(
status_code=500,
detail="Interest is associated with a project and cannot be deleted.",
)

query = """
DELETE FROM interests
WHERE id = :interest_id;
Expand Down
13 changes: 13 additions & 0 deletions backend/services/license_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ async def update_license(
@staticmethod
async def delete_license(license_id: int, db: Database):
"""Delete specified license"""
check_query = """
SELECT 1
FROM projects
WHERE license_id = :license_id
LIMIT 1;
"""
associated = await db.fetch_one(check_query, {"license_id": license_id})
if associated:
raise HTTPException(
status_code=500,
detail="Cannot delete the license as it is associated with a project.",
)

query = """
DELETE FROM licenses
WHERE id = :license_id;
Expand Down
24 changes: 24 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,30 @@ services:
networks:
- tm-net

tm-cron-jobs:
image: ghcr.io/hotosm/tasking-manager/backend:main
build:
context: .
command: ["python", "backend/cron_jobs.py"]
depends_on:
tm-db:
condition: service_healthy
env_file:
- tasking-manager.env
environment:
- PYTHONPATH=/usr/src/app
deploy:
replicas: 1
resources:
limits:
cpus: "0.5"
memory: 256M
reservations:
cpus: "0.2"
memory: 128M
networks:
- tm-net

traefik:
image: traefik:v2.10
restart: always
Expand Down

0 comments on commit 6eb2efb

Please sign in to comment.