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

feat: new active projects api for export tool #6153

Merged
merged 6 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 5 additions & 2 deletions backend/api/projects/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -1185,7 +1185,7 @@ def get(self):
default: Token sessionTokenHere==
- name: interval
in: path
description: Time interval to get active project
description: Time interval in hours to get active project
required: false
type: integer
default: 24
Expand All @@ -1197,6 +1197,9 @@ def get(self):
500:
description: Internal Server Error
"""
interval = int(request.args.get("interval", 24))
interval = request.args.get("interval", "24")
if not interval.isdigit():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 and <=24 restrict user to extract more than 24 hour active projects

return {"Error": "Interval must be a number greater than 0"}, 400
interval = int(interval)
projects_dto = ProjectService.get_active_projects(interval)
return projects_dto, 200
4 changes: 2 additions & 2 deletions backend/services/project_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from cachetools import TTLCache, cached
from flask import current_app
import geojson
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone

from backend.exceptions import NotFound
from backend.models.dtos.mapping_dto import TaskDTOs
Expand Down Expand Up @@ -620,7 +620,7 @@ def send_email_on_project_progress(project_id):

@staticmethod
def get_active_projects(interval):
action_date = datetime.now() - timedelta(hours=interval)
action_date = datetime.now(timezone.utc) - timedelta(hours=interval)
result = (
TaskHistory.query.with_entities(TaskHistory.project_id)
.distinct()
Expand Down
Loading