mirror of
https://github.com/decompals/frogress.git
synced 2025-12-16 00:17:04 +00:00
0.3.0: Bug-fixes & cleanup (#34)
Add 'description' to entry Fixes #26, fixes #25 General cleanup
This commit is contained in:
@@ -7,14 +7,14 @@ class NonexistentProjectException(APIException):
|
||||
status_code = status.HTTP_404_NOT_FOUND
|
||||
|
||||
def __init__(self, project: str):
|
||||
super().__init__(f"Project {project} not found")
|
||||
super().__init__(f"Project {project} does not exist")
|
||||
|
||||
|
||||
class NonexistentVersionException(APIException):
|
||||
status_code = status.HTTP_404_NOT_FOUND
|
||||
|
||||
def __init__(self, project: str, version: str):
|
||||
super().__init__(f"Version '{version}' for project '{project}' not found")
|
||||
super().__init__(f"Version '{version}' for project '{project}' does not exist")
|
||||
|
||||
|
||||
class NonexistentCategoryException(APIException):
|
||||
@@ -22,12 +22,12 @@ class NonexistentCategoryException(APIException):
|
||||
|
||||
def __init__(self, project: str, version: str, category: str):
|
||||
super().__init__(
|
||||
f"Category '{category}' not found for project '{project}', version '{version}'"
|
||||
f"Category '{category}' does not exist for project '{project}', version '{version}'"
|
||||
)
|
||||
|
||||
|
||||
class NoEntriesException(APIException):
|
||||
status_code = status.HTTP_404_NOT_FOUND
|
||||
class EmptyCategoryException(APIException):
|
||||
status_code = status.HTTP_400_BAD_REQUEST
|
||||
|
||||
def __init__(self, project: str, version: str, category: str):
|
||||
super().__init__(
|
||||
|
||||
18
frog_api/migrations/0011_entry_description.py
Normal file
18
frog_api/migrations/0011_entry_description.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 4.2.1 on 2023-05-25 15:59
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("frog_api", "0010_alter_entry_category_alter_project_discord_and_more"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="entry",
|
||||
name="description",
|
||||
field=models.TextField(blank=True),
|
||||
),
|
||||
]
|
||||
@@ -73,6 +73,7 @@ class Entry(models.Model):
|
||||
category = models.ForeignKey(Category, on_delete=models.CASCADE)
|
||||
timestamp = models.IntegerField()
|
||||
git_hash = models.CharField(max_length=40)
|
||||
description = models.TextField(blank=True)
|
||||
|
||||
class Meta:
|
||||
verbose_name_plural = "Entries"
|
||||
|
||||
@@ -42,4 +42,5 @@ class EntrySerializer(serializers.HyperlinkedModelSerializer):
|
||||
"timestamp",
|
||||
"git_hash",
|
||||
"measures",
|
||||
"description",
|
||||
]
|
||||
|
||||
@@ -13,7 +13,13 @@ from frog_api.cache import (
|
||||
invalidate_entries_cache,
|
||||
set_entries_cache,
|
||||
)
|
||||
from frog_api.exceptions import InvalidDataException, NoEntriesException
|
||||
from frog_api.exceptions import (
|
||||
InvalidDataException,
|
||||
EmptyCategoryException,
|
||||
NonexistentCategoryException,
|
||||
NonexistentProjectException,
|
||||
NonexistentVersionException,
|
||||
)
|
||||
from frog_api.models import Category, Entry, Measure, Project, Version
|
||||
from frog_api.serializers.model_serializers import EntrySerializer
|
||||
from frog_api.serializers.request_serializers import CreateEntriesSerializer
|
||||
@@ -42,15 +48,6 @@ def get_latest_entry(
|
||||
return EntrySerializer(entry).data
|
||||
|
||||
|
||||
def get_latest_entry_throw(
|
||||
project_slug: str, version_slug: str, category_slug: str
|
||||
) -> EntryT:
|
||||
entry = get_latest_entry(project_slug, version_slug, category_slug)
|
||||
if entry is None:
|
||||
raise NoEntriesException(project_slug, version_slug, category_slug)
|
||||
return entry
|
||||
|
||||
|
||||
def get_all_entries(
|
||||
project_slug: str, version_slug: str, category_slug: str
|
||||
) -> list[EntryT]:
|
||||
@@ -121,9 +118,10 @@ class ProjectDataView(APIView):
|
||||
def get_progress_shield(
|
||||
request: Request, project_slug: str, version_slug: str, category_slug: str
|
||||
) -> dict[str, Any]:
|
||||
latest = get_latest_entry_throw(project_slug, version_slug, category_slug)
|
||||
latest = get_latest_entry(project_slug, version_slug, category_slug)
|
||||
|
||||
assert latest is not None
|
||||
if latest is None:
|
||||
raise EmptyCategoryException(project_slug, version_slug, category_slug)
|
||||
|
||||
latest_measures = latest["measures"]
|
||||
|
||||
@@ -191,11 +189,17 @@ class VersionDataView(APIView):
|
||||
request_ser.is_valid(raise_exception=True)
|
||||
data = request_ser.data
|
||||
|
||||
project = get_project(project_slug)
|
||||
try:
|
||||
project = get_project(project_slug)
|
||||
except NonexistentProjectException:
|
||||
raise InvalidDataException(f"Project '{project_slug}' does not exist")
|
||||
|
||||
validate_api_key(data["api_key"], project)
|
||||
|
||||
version = get_version(version_slug, project)
|
||||
try:
|
||||
version = get_version(version_slug, project)
|
||||
except NonexistentVersionException:
|
||||
raise InvalidDataException(f"Version '{version_slug}' does not exist")
|
||||
|
||||
to_save: list[models.Model] = []
|
||||
for entry in data["entries"]:
|
||||
@@ -203,7 +207,10 @@ class VersionDataView(APIView):
|
||||
git_hash = entry["git_hash"]
|
||||
categories = entry["categories"]
|
||||
for cat in categories:
|
||||
category = get_category(cat, version)
|
||||
try:
|
||||
category = get_category(cat, version)
|
||||
except NonexistentCategoryException:
|
||||
raise InvalidDataException(f"Category '{cat}' does not exist")
|
||||
|
||||
entry = Entry(category=category, timestamp=timestamp, git_hash=git_hash)
|
||||
|
||||
@@ -300,9 +307,8 @@ class CategoryDataView(APIView):
|
||||
|
||||
match mode:
|
||||
case Mode.LATEST:
|
||||
entries = [
|
||||
get_latest_entry_throw(project_slug, version_slug, category_slug)
|
||||
]
|
||||
entry = get_latest_entry(project_slug, version_slug, category_slug)
|
||||
entries = [entry] if entry is not None else []
|
||||
response_json = {project_slug: {version_slug: {category_slug: entries}}}
|
||||
return Response(response_json)
|
||||
case Mode.ALL:
|
||||
|
||||
Reference in New Issue
Block a user