version digest view
This commit is contained in:
parent
e656ab4e64
commit
9848c8db9a
|
@ -3,20 +3,20 @@ from frog_api import views
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path("projects/", views.ProjectView.as_view()),
|
path("projects/", views.ProjectView.as_view()),
|
||||||
path(
|
# re_path(
|
||||||
"data/",
|
# "data/(?P<project>.+)/(?P<version>.+)/(?P<category>.+)/$",
|
||||||
views.RootDigestView.as_view(),
|
# views.EntryView.as_view(),
|
||||||
|
# ),
|
||||||
|
re_path(
|
||||||
|
"data/(?P<project>.+)/(?P<version>.+)/$",
|
||||||
|
views.VersionDigestView.as_view(),
|
||||||
),
|
),
|
||||||
re_path(
|
re_path(
|
||||||
"data/(?P<project>.+)/$",
|
"data/(?P<project>.+)/$",
|
||||||
views.ProjectDigestView.as_view(),
|
views.ProjectDigestView.as_view(),
|
||||||
),
|
),
|
||||||
# re_path(
|
path(
|
||||||
# "data/(?P<project>.+)/(?P<version>.+)/$",
|
"data/",
|
||||||
# views.EntryView.as_view(),
|
views.RootDigestView.as_view(),
|
||||||
# ),
|
),
|
||||||
# re_path(
|
|
||||||
# "data/(?P<project>.+)/(?P<version>.+)/(?P<category>.+)/$",
|
|
||||||
# views.EntryView.as_view(),
|
|
||||||
# ),
|
|
||||||
]
|
]
|
||||||
|
|
|
@ -32,16 +32,18 @@ def get_latest_entry(project, version, category) -> Optional[Entry]:
|
||||||
).first()
|
).first()
|
||||||
|
|
||||||
|
|
||||||
|
def get_entry_json(entry) -> dict:
|
||||||
|
entry_data = TerseEntrySerializer(entry).data
|
||||||
|
entry_data["measures"] = {m["type"]: m["value"] for m in entry_data["measures"]}
|
||||||
|
return entry_data
|
||||||
|
|
||||||
|
|
||||||
def get_versions_digest_for_project(project) -> dict:
|
def get_versions_digest_for_project(project) -> dict:
|
||||||
versions = {}
|
versions = {}
|
||||||
for version in Version.objects.filter(project__slug=project):
|
for version in Version.objects.filter(project__slug=project):
|
||||||
entry = get_latest_entry(project, version.slug, "total")
|
entry = get_latest_entry(project, version.slug, "total")
|
||||||
if entry is not None:
|
if entry is not None:
|
||||||
entry_data = TerseEntrySerializer(entry).data
|
versions[version.slug] = get_entry_json(entry)
|
||||||
entry_data["measures"] = {
|
|
||||||
m["type"]: m["value"] for m in entry_data["measures"]
|
|
||||||
}
|
|
||||||
versions[version.slug] = entry_data
|
|
||||||
return versions
|
return versions
|
||||||
|
|
||||||
|
|
||||||
|
@ -74,8 +76,10 @@ class ProjectDigestView(APIView):
|
||||||
Return the most recent entry for overall progress for each version of a project.
|
Return the most recent entry for overall progress for each version of a project.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if Project.objects.get(slug=project) is None:
|
if not Project.objects.filter(slug=project).exists():
|
||||||
return Response(status=status.HTTP_404_NOT_FOUND)
|
return Response(
|
||||||
|
f"Project {project} not found", status=status.HTTP_404_NOT_FOUND
|
||||||
|
)
|
||||||
|
|
||||||
projects = {}
|
projects = {}
|
||||||
|
|
||||||
|
@ -84,3 +88,29 @@ class ProjectDigestView(APIView):
|
||||||
projects[project] = versions
|
projects[project] = versions
|
||||||
|
|
||||||
return Response({"progress": projects})
|
return Response({"progress": projects})
|
||||||
|
|
||||||
|
|
||||||
|
class VersionDigestView(APIView):
|
||||||
|
"""
|
||||||
|
API endpoint that returns the most recent entry for a version of a project.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def get(self, request, project, version):
|
||||||
|
"""
|
||||||
|
Return the most recent entry for overall progress for a version of a project.
|
||||||
|
"""
|
||||||
|
|
||||||
|
if not Project.objects.filter(slug=project).exists():
|
||||||
|
return Response(
|
||||||
|
f"Project {project} not found", status=status.HTTP_404_NOT_FOUND
|
||||||
|
)
|
||||||
|
|
||||||
|
if not Version.objects.filter(slug=version, project__slug=project).exists():
|
||||||
|
return Response(
|
||||||
|
f"Version {version} not found", status=status.HTTP_404_NOT_FOUND
|
||||||
|
)
|
||||||
|
|
||||||
|
entry = get_latest_entry(project, version, "total")
|
||||||
|
entry_json = get_entry_json(entry)
|
||||||
|
|
||||||
|
return Response(entry_json)
|
||||||
|
|
Loading…
Reference in New Issue