diff --git a/.gitignore b/.gitignore index b248f03..c19112f 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ __pycache__ *.pyc *.db .DS_Store -.env.* \ No newline at end of file +.env.* +db.sqlite3 diff --git a/frog_api/admin.py b/frog_api/admin.py index 604a1d6..3a6f219 100644 --- a/frog_api/admin.py +++ b/frog_api/admin.py @@ -1,5 +1,8 @@ from django.contrib import admin -from frog_api.models import Project +from frog_api.models import Category, Entry, Project, Version admin.site.register(Project) +admin.site.register(Version) +admin.site.register(Category) +admin.site.register(Entry) diff --git a/frog_api/migrations/0002_remove_entry_version_category_entry_category.py b/frog_api/migrations/0002_remove_entry_version_category_entry_category.py new file mode 100644 index 0000000..8141acd --- /dev/null +++ b/frog_api/migrations/0002_remove_entry_version_category_entry_category.py @@ -0,0 +1,45 @@ +# Generated by Django 4.1 on 2022-08-20 02:04 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ("frog_api", "0001_initial"), + ] + + operations = [ + migrations.RemoveField( + model_name="entry", + name="version", + ), + migrations.CreateModel( + name="Category", + fields=[ + ("id", models.AutoField(primary_key=True, serialize=False)), + ("created_on", models.DateTimeField(auto_now_add=True)), + ("last_updated", models.DateTimeField(auto_now=True)), + ("slug", models.SlugField(max_length=255)), + ("name", models.CharField(max_length=255)), + ( + "version", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + to="frog_api.version", + ), + ), + ], + ), + migrations.AddField( + model_name="entry", + name="category", + field=models.ForeignKey( + default="", + on_delete=django.db.models.deletion.CASCADE, + to="frog_api.category", + ), + preserve_default=False, + ), + ] diff --git a/frog_api/migrations/0003_rename_decompiled_functions_entry_decompiled_chunks_and_more.py b/frog_api/migrations/0003_rename_decompiled_functions_entry_decompiled_chunks_and_more.py new file mode 100644 index 0000000..c28ba49 --- /dev/null +++ b/frog_api/migrations/0003_rename_decompiled_functions_entry_decompiled_chunks_and_more.py @@ -0,0 +1,32 @@ +# Generated by Django 4.1 on 2022-08-20 02:19 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("frog_api", "0002_remove_entry_version_category_entry_category"), + ] + + operations = [ + migrations.RenameField( + model_name="entry", + old_name="decompiled_functions", + new_name="decompiled_chunks", + ), + migrations.RenameField( + model_name="entry", + old_name="matching_functions", + new_name="matching_chunks", + ), + migrations.RenameField( + model_name="entry", + old_name="total_functions", + new_name="total_chunks", + ), + migrations.RemoveField( + model_name="entry", + name="other_data", + ), + ] diff --git a/frog_api/models.py b/frog_api/models.py index 898debe..c7cad5a 100644 --- a/frog_api/models.py +++ b/frog_api/models.py @@ -1,6 +1,6 @@ from django.db import models - +# Example: OOT class Project(models.Model): id = models.AutoField(primary_key=True) created_on = models.DateTimeField(auto_now_add=True) @@ -10,7 +10,11 @@ class Project(models.Model): name = models.CharField(max_length=255) auth_key = models.CharField(max_length=255) + def __str__(self) -> str: + return self.slug + +# Example: US 1.0 class Version(models.Model): id = models.AutoField(primary_key=True) created_on = models.DateTimeField(auto_now_add=True) @@ -20,25 +24,48 @@ class Version(models.Model): slug = models.SlugField(max_length=255) name = models.CharField(max_length=255) + def __str__(self) -> str: + return f"{self.project} {self.slug}" -class Entry(models.Model): + +# Example: Actors +class Category(models.Model): id = models.AutoField(primary_key=True) created_on = models.DateTimeField(auto_now_add=True) last_updated = models.DateTimeField(auto_now=True) version = models.ForeignKey(Version, on_delete=models.CASCADE) + slug = models.SlugField(max_length=255) + name = models.CharField(max_length=255) + + class Meta: + verbose_name_plural = "Categories" + + def __str__(self) -> str: + return f"{self.version} {self.slug}" + + +# A snapshot in time of progress, tied to a Category +class Entry(models.Model): + id = models.AutoField(primary_key=True) + created_on = models.DateTimeField(auto_now_add=True) + last_updated = models.DateTimeField(auto_now=True) + + category = models.ForeignKey(Category, on_delete=models.CASCADE) timestamp = models.DateTimeField() git_hash = models.CharField(max_length=40) - # Functions - total_functions = models.IntegerField() - decompiled_functions = models.IntegerField() - matching_functions = models.IntegerField() + # Functions / files / whatever you want + total_chunks = models.IntegerField() + decompiled_chunks = models.IntegerField() + matching_chunks = models.IntegerField() # Bytes total_bytes = models.IntegerField() decompiled_bytes = models.IntegerField() matching_bytes = models.IntegerField() - # Other - other_data = models.JSONField(null=True, blank=True) class Meta: + verbose_name_plural = "Entries" ordering = ["-timestamp"] + + def __str__(self) -> str: + return f"{self.category} {self.timestamp}" diff --git a/frog_api/serializers.py b/frog_api/serializers.py index 7e5f586..3839d73 100644 --- a/frog_api/serializers.py +++ b/frog_api/serializers.py @@ -1,6 +1,6 @@ from rest_framework import serializers -from frog_api.models import Project, Version +from frog_api.models import Entry, Project, Version class ProjectSerializer(serializers.HyperlinkedModelSerializer): @@ -17,16 +17,14 @@ class VersionSerializer(serializers.HyperlinkedModelSerializer): class EntrySerializer(serializers.HyperlinkedModelSerializer): class Meta: - model = Version + model = Entry fields = [ - "version", "timestamp", "git_hash", - "total_functions", - "decompiled_functions", - "matching_functions", + "total_chunks", + "decompiled_chunks", + "matching_chunks", "total_bytes", "decompiled_bytes", "matching_bytes", - "other_data", ] diff --git a/frog_api/views.py b/frog_api/views.py index 3404b8e..ed2e151 100644 --- a/frog_api/views.py +++ b/frog_api/views.py @@ -1,8 +1,12 @@ +from typing import Any from rest_framework.response import Response from rest_framework.views import APIView +from rest_framework import mixins +from rest_framework.request import Request +from rest_framework.viewsets import GenericViewSet -from frog_api.models import Project -from frog_api.serializers import ProjectSerializer +from frog_api.models import Entry, Project +from frog_api.serializers import EntrySerializer, ProjectSerializer class ProjectView(APIView):