initial shtuff

This commit is contained in:
Ethan Roseman
2022-08-19 19:35:05 +09:00
commit 5b02dc1b33
22 changed files with 1064 additions and 0 deletions

0
frog_api/__init__.py Normal file
View File

5
frog_api/admin.py Normal file
View File

@@ -0,0 +1,5 @@
from django.contrib import admin
from frog_api.models import Project
admin.site.register(Project)

6
frog_api/apps.py Normal file
View File

@@ -0,0 +1,6 @@
from django.apps import AppConfig
class FrogApiConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'frog_api'

View File

@@ -0,0 +1,69 @@
# Generated by Django 4.1 on 2022-08-19 09:01
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = []
operations = [
migrations.CreateModel(
name="Project",
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, unique=True)),
("name", models.CharField(max_length=255)),
("auth_key", models.CharField(max_length=255)),
],
),
migrations.CreateModel(
name="Version",
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)),
(
"project",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
to="frog_api.project",
),
),
],
),
migrations.CreateModel(
name="Entry",
fields=[
("id", models.AutoField(primary_key=True, serialize=False)),
("created_on", models.DateTimeField(auto_now_add=True)),
("last_updated", models.DateTimeField(auto_now=True)),
("timestamp", models.DateTimeField()),
("git_hash", models.CharField(max_length=40)),
("total_functions", models.IntegerField()),
("decompiled_functions", models.IntegerField()),
("matching_functions", models.IntegerField()),
("total_bytes", models.IntegerField()),
("decompiled_bytes", models.IntegerField()),
("matching_bytes", models.IntegerField()),
("other_data", models.JSONField(blank=True, null=True)),
(
"version",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
to="frog_api.version",
),
),
],
options={
"ordering": ["-timestamp"],
},
),
]

View File

44
frog_api/models.py Normal file
View File

@@ -0,0 +1,44 @@
from django.db import models
class Project(models.Model):
id = models.AutoField(primary_key=True)
created_on = models.DateTimeField(auto_now_add=True)
last_updated = models.DateTimeField(auto_now=True)
slug = models.SlugField(max_length=255, unique=True)
name = models.CharField(max_length=255)
auth_key = models.CharField(max_length=255)
class Version(models.Model):
id = models.AutoField(primary_key=True)
created_on = models.DateTimeField(auto_now_add=True)
last_updated = models.DateTimeField(auto_now=True)
project = models.ForeignKey(Project, on_delete=models.CASCADE)
slug = models.SlugField(max_length=255)
name = models.CharField(max_length=255)
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)
version = models.ForeignKey(Version, 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()
# Bytes
total_bytes = models.IntegerField()
decompiled_bytes = models.IntegerField()
matching_bytes = models.IntegerField()
# Other
other_data = models.JSONField(null=True, blank=True)
class Meta:
ordering = ["-timestamp"]

32
frog_api/serializers.py Normal file
View File

@@ -0,0 +1,32 @@
from rest_framework import serializers
from frog_api.models import Project, Version
class ProjectSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Project
fields = ["slug", "name"]
class VersionSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Version
fields = ["project", "slug", "name"]
class EntrySerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Version
fields = [
"version",
"timestamp",
"git_hash",
"total_functions",
"decompiled_functions",
"matching_functions",
"total_bytes",
"decompiled_bytes",
"matching_bytes",
"other_data",
]

3
frog_api/tests.py Normal file
View File

@@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

6
frog_api/urls.py Normal file
View File

@@ -0,0 +1,6 @@
from django.urls import path
from frog_api import views
urlpatterns = [
path("projects/", views.ProjectView.as_view()),
]

19
frog_api/views.py Normal file
View File

@@ -0,0 +1,19 @@
from rest_framework.response import Response
from rest_framework.views import APIView
from frog_api.models import Project
from frog_api.serializers import ProjectSerializer
class ProjectView(APIView):
"""
API endpoint that allows projects to be viewed or edited.
"""
def get(self, request, format=None):
"""
Return a list of all projects.
"""
projects = Project.objects.all()
serializer = ProjectSerializer(projects, many=True)
return Response(serializer.data)