From 497f5bb737f0e7c5788b6409abde83efd213d38f Mon Sep 17 00:00:00 2001 From: tbonza Date: Mon, 6 May 2019 15:06:43 -0400 Subject: [PATCH] adding api with django rest framework --- .dockerignore | 72 +++++++++++++ .gitignore | 66 ++++++++++++ .gitignore~ | 64 ++++++++++++ .openapi-generator-ignore | 23 +++++ .openapi-generator/VERSION | 1 + .travis.yml | 13 +++ garden/__init__.py | 0 garden/settings.py | 130 +++++++++++++++++++++++ garden/settings.py~ | 120 ++++++++++++++++++++++ garden/urls.py | 33 ++++++ garden/urls.py~ | 21 ++++ garden/wsgi.py | 16 +++ manage.py | 21 ++++ pick_okra/__init__.py | 0 pick_okra/admin.py | 3 + pick_okra/apps.py | 5 + pick_okra/migrations/0001_initial.py | 54 ++++++++++ pick_okra/migrations/__init__.py | 0 pick_okra/models.py | 20 ++++ pick_okra/models.py~ | 3 + pick_okra/serializers.py | 27 +++++ pick_okra/serializers.py~ | 3 + pick_okra/tests.py | 3 + pick_okra/urls.py~ | 4 + pick_okra/views.py | 45 ++++++++ pick_okra/views.py~ | 3 + swagger.yaml | 147 +++++++++++++++++++++++++++ 27 files changed, 897 insertions(+) create mode 100644 .dockerignore create mode 100644 .gitignore create mode 100644 .gitignore~ create mode 100644 .openapi-generator-ignore create mode 100644 .openapi-generator/VERSION create mode 100644 .travis.yml create mode 100644 garden/__init__.py create mode 100644 garden/settings.py create mode 100644 garden/settings.py~ create mode 100644 garden/urls.py create mode 100644 garden/urls.py~ create mode 100644 garden/wsgi.py create mode 100755 manage.py create mode 100644 pick_okra/__init__.py create mode 100644 pick_okra/admin.py create mode 100644 pick_okra/apps.py create mode 100644 pick_okra/migrations/0001_initial.py create mode 100644 pick_okra/migrations/__init__.py create mode 100644 pick_okra/models.py create mode 100644 pick_okra/models.py~ create mode 100644 pick_okra/serializers.py create mode 100644 pick_okra/serializers.py~ create mode 100644 pick_okra/tests.py create mode 100644 pick_okra/urls.py~ create mode 100644 pick_okra/views.py create mode 100644 pick_okra/views.py~ create mode 100644 swagger.yaml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..f961960 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,72 @@ +.travis.yaml +.openapi-generator-ignore +README.md +tox.ini +git_push.sh +test-requirements.txt +setup.py + +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +env/ +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +*.egg-info/ +.installed.cfg +*.egg + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*,cover +.hypothesis/ +venv/ +.python-version + +# Translations +*.mo +*.pot + +# Django stuff: +*.log + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +#Ipython Notebook +.ipynb_checkpoints diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..553c787 --- /dev/null +++ b/.gitignore @@ -0,0 +1,66 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +env/ +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +*.egg-info/ +.installed.cfg +*.egg + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*,cover +.hypothesis/ +venv/ +.python-version + +# Translations +*.mo +*.pot + +# Django stuff: +*.log + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +#Ipython Notebook +.ipynb_checkpoints + +db.sqlite3 \ No newline at end of file diff --git a/.gitignore~ b/.gitignore~ new file mode 100644 index 0000000..a655050 --- /dev/null +++ b/.gitignore~ @@ -0,0 +1,64 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +env/ +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +*.egg-info/ +.installed.cfg +*.egg + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*,cover +.hypothesis/ +venv/ +.python-version + +# Translations +*.mo +*.pot + +# Django stuff: +*.log + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +#Ipython Notebook +.ipynb_checkpoints diff --git a/.openapi-generator-ignore b/.openapi-generator-ignore new file mode 100644 index 0000000..7484ee5 --- /dev/null +++ b/.openapi-generator-ignore @@ -0,0 +1,23 @@ +# OpenAPI Generator Ignore +# Generated by openapi-generator https://github.com/openapitools/openapi-generator + +# Use this file to prevent files from being overwritten by the generator. +# The patterns follow closely to .gitignore or .dockerignore. + +# As an example, the C# client generator defines ApiClient.cs. +# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: +#ApiClient.cs + +# You can match any string of characters against a directory, file or extension with a single asterisk (*): +#foo/*/qux +# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux + +# You can recursively match patterns against a directory, file or extension with a double asterisk (**): +#foo/**/qux +# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux + +# You can also negate patterns with an exclamation (!). +# For example, you can ignore all files in a docs folder with the file extension .md: +#docs/*.md +# Then explicitly reverse the ignore rule for a single file: +#!docs/README.md diff --git a/.openapi-generator/VERSION b/.openapi-generator/VERSION new file mode 100644 index 0000000..2c6109e --- /dev/null +++ b/.openapi-generator/VERSION @@ -0,0 +1 @@ +3.3.4 \ No newline at end of file diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..dd6c445 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,13 @@ +# ref: https://docs.travis-ci.com/user/languages/python +language: python +python: + - "3.2" + - "3.3" + - "3.4" + - "3.5" + #- "3.5-dev" # 3.5 development branch + #- "nightly" # points to the latest development branch e.g. 3.6-dev +# command to install dependencies +install: "pip install -r requirements.txt" +# command to run tests +script: nosetests diff --git a/garden/__init__.py b/garden/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/garden/settings.py b/garden/settings.py new file mode 100644 index 0000000..8687044 --- /dev/null +++ b/garden/settings.py @@ -0,0 +1,130 @@ +""" +Django settings for garden project. + +Generated by 'django-admin startproject' using Django 2.2.1. + +For more information on this file, see +https://docs.djangoproject.com/en/2.2/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/2.2/ref/settings/ +""" + +import os + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'r8+b1#ixw_z1$%vp=@j1d#p4)^)nw-m21)fgxz-_e@zlt)5wws' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + +REST_FRAMEWORK = { + 'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination', + 'PAGE_SIZE': 10, +} + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + + # Django contribs + 'rest_framework', + + # Custom apps + 'pick_okra', +] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'garden.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'garden.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/2.2/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + } +} + + +# Password validation +# https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/2.2/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/2.2/howto/static-files/ + +STATIC_URL = '/static/' diff --git a/garden/settings.py~ b/garden/settings.py~ new file mode 100644 index 0000000..e9cb897 --- /dev/null +++ b/garden/settings.py~ @@ -0,0 +1,120 @@ +""" +Django settings for garden project. + +Generated by 'django-admin startproject' using Django 2.2.1. + +For more information on this file, see +https://docs.djangoproject.com/en/2.2/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/2.2/ref/settings/ +""" + +import os + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'r8+b1#ixw_z1$%vp=@j1d#p4)^)nw-m21)fgxz-_e@zlt)5wws' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', +] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'garden.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'garden.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/2.2/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + } +} + + +# Password validation +# https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/2.2/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/2.2/howto/static-files/ + +STATIC_URL = '/static/' diff --git a/garden/urls.py b/garden/urls.py new file mode 100644 index 0000000..c6a075e --- /dev/null +++ b/garden/urls.py @@ -0,0 +1,33 @@ +"""garden URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/2.2/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.urls import include, path + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) +""" +from django.contrib import admin +from django.urls import include, path +from rest_framework import routers + +from pick_okra.views import RepositoryViewSet +from pick_okra.views import RepositoryInfoViewSet +from pick_okra.views import RepositoryMetricsViewSet +from pick_okra.views import ContributorViewSet + +router = routers.DefaultRouter() +router.register(r'repository', RepositoryViewSet) +router.register(r'repository_info', RepositoryInfoViewSet) +router.register(r'repository_metrics', RepositoryMetricsViewSet) +router.register(r'contributor', ContributorViewSet) + +urlpatterns = [ + path('', include(router.urls)), +] diff --git a/garden/urls.py~ b/garden/urls.py~ new file mode 100644 index 0000000..64979be --- /dev/null +++ b/garden/urls.py~ @@ -0,0 +1,21 @@ +"""garden URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/2.2/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.urls import include, path + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) +""" +from django.contrib import admin +from django.urls import path + +urlpatterns = [ + path('admin/', admin.site.urls), +] diff --git a/garden/wsgi.py b/garden/wsgi.py new file mode 100644 index 0000000..3ff9bbf --- /dev/null +++ b/garden/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for garden project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/2.2/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'garden.settings') + +application = get_wsgi_application() diff --git a/manage.py b/manage.py new file mode 100755 index 0000000..b38f59a --- /dev/null +++ b/manage.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python +"""Django's command-line utility for administrative tasks.""" +import os +import sys + + +def main(): + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'garden.settings') + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) + + +if __name__ == '__main__': + main() diff --git a/pick_okra/__init__.py b/pick_okra/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pick_okra/admin.py b/pick_okra/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/pick_okra/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/pick_okra/apps.py b/pick_okra/apps.py new file mode 100644 index 0000000..b68f3ba --- /dev/null +++ b/pick_okra/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class PickOkraConfig(AppConfig): + name = 'pick_okra' diff --git a/pick_okra/migrations/0001_initial.py b/pick_okra/migrations/0001_initial.py new file mode 100644 index 0000000..636bdfd --- /dev/null +++ b/pick_okra/migrations/0001_initial.py @@ -0,0 +1,54 @@ +# Generated by Django 2.2.1 on 2019-05-06 18:12 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Contributor', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=100)), + ], + ), + migrations.CreateModel( + name='Repository', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('repo_id', models.CharField(max_length=200)), + ], + ), + migrations.CreateModel( + name='RepositoryMetrics', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('repo_id', models.CharField(max_length=200)), + ('rating', models.FloatField()), + ], + ), + migrations.CreateModel( + name='RepositoryInfo', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('repo_id', models.CharField(max_length=200)), + ('name', models.CharField(max_length=50)), + ('namespace', models.CharField(max_length=50)), + ('firstCommitDate', models.DateTimeField()), + ('contibutors', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='pick_okra.Contributor')), + ('metrics', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='pick_okra.RepositoryMetrics')), + ], + ), + migrations.AddField( + model_name='contributor', + name='projects', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='pick_okra.Repository'), + ), + ] diff --git a/pick_okra/migrations/__init__.py b/pick_okra/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pick_okra/models.py b/pick_okra/models.py new file mode 100644 index 0000000..18017e6 --- /dev/null +++ b/pick_okra/models.py @@ -0,0 +1,20 @@ +from django.db import models + +class Repository(models.Model): + repo_id = models.CharField(max_length=200) + +class RepositoryMetrics(models.Model): + repo_id = models.CharField(max_length=200) + rating = models.FloatField() + +class Contributor(models.Model): + name = models.CharField(max_length=100) + projects = models.ForeignKey('Repository', on_delete=models.CASCADE) + +class RepositoryInfo(models.Model): + repo_id = models.CharField(max_length=200) + name = models.CharField(max_length=50) + namespace = models.CharField(max_length=50) + firstCommitDate = models.DateTimeField() + contibutors = models.ForeignKey('Contributor', on_delete=models.CASCADE) + metrics = models.ForeignKey('RepositoryMetrics', on_delete=models.CASCADE) diff --git a/pick_okra/models.py~ b/pick_okra/models.py~ new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/pick_okra/models.py~ @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/pick_okra/serializers.py b/pick_okra/serializers.py new file mode 100644 index 0000000..1101c32 --- /dev/null +++ b/pick_okra/serializers.py @@ -0,0 +1,27 @@ +from rest_framework import serializers + +from pick_okra.models import Contributor +from pick_okra.models import Repository +from pick_okra.models import RepositoryInfo +from pick_okra.models import RepositoryMetrics + + +class RepositorySerializer(serializers.HyperlinkedModelSerializer): + class Meta: + model = Repository + fields = '__all__' + +class RepositoryMetricsSerializer(serializers.HyperlinkedModelSerializer): + class Meta: + model = RepositoryMetrics + fields = '__all__' + +class ContributorSerializer(serializers.HyperlinkedModelSerializer): + class Meta: + model = Contributor + fields = '__all__' + +class RepositoryInfoSerializer(serializers.HyperlinkedModelSerializer): + class Meta: + model = RepositoryInfo + fields = '__all__' diff --git a/pick_okra/serializers.py~ b/pick_okra/serializers.py~ new file mode 100644 index 0000000..28add31 --- /dev/null +++ b/pick_okra/serializers.py~ @@ -0,0 +1,3 @@ + + +from rest_framework import serializers diff --git a/pick_okra/tests.py b/pick_okra/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/pick_okra/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/pick_okra/urls.py~ b/pick_okra/urls.py~ new file mode 100644 index 0000000..6e3cc24 --- /dev/null +++ b/pick_okra/urls.py~ @@ -0,0 +1,4 @@ +from django.urls import include, path +from rest_framework import routers + +from pick_okra.views import RepositoryViewSet diff --git a/pick_okra/views.py b/pick_okra/views.py new file mode 100644 index 0000000..5cd4e77 --- /dev/null +++ b/pick_okra/views.py @@ -0,0 +1,45 @@ +from django.shortcuts import render +from rest_framework import viewsets + +from pick_okra.models import Contributor +from pick_okra.models import Repository +from pick_okra.models import RepositoryInfo +from pick_okra.models import RepositoryMetrics + +from pick_okra.serializers import ContributorSerializer +from pick_okra.serializers import RepositorySerializer +from pick_okra.serializers import RepositoryInfoSerializer +from pick_okra.serializers import RepositoryMetricsSerializer + +class RepositoryViewSet(viewsets.ModelViewSet): + """ + API endpoint that all repo_id: pallet/flask + """ + queryset = Repository.objects.all() + serializer_class = RepositorySerializer + http_method_names = ['get'] + +class RepositoryMetricsViewSet(viewsets.ModelViewSet): + """ + Metrics on each repository rating + """ + queryset = RepositoryMetrics.objects.all() + serializer_class = RepositoryMetricsSerializer + http_method_names = ['get'] + +class ContributorViewSet(viewsets.ModelViewSet): + """ + Metrics on each contributor + """ + queryset = Contributor.objects.all() + serializer_class = ContributorSerializer + http_method_names = ['get'] + +class RepositoryInfoViewSet(viewsets.ModelViewSet): + """ + General Metrics on each repository + """ + queryset = RepositoryInfo.objects.all() + serializer_class = RepositoryInfoSerializer + http_method_names = ['get'] + diff --git a/pick_okra/views.py~ b/pick_okra/views.py~ new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/pick_okra/views.py~ @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/swagger.yaml b/swagger.yaml new file mode 100644 index 0000000..5d32f5e --- /dev/null +++ b/swagger.yaml @@ -0,0 +1,147 @@ +openapi: 3.0.0 +# Added by API Auto Mocking Plugin +servers: + - description: Okra API definition + url: https://virtserver.swaggerhub.com/aexvir/Okra/1.0.0 +info: + description: Okra repository analysis endpoint + version: "1.0.0" + title: Okra API + contact: + email: you@your-company.com + license: + name: Apache 2.0 + url: 'http://www.apache.org/licenses/LICENSE-2.0.html' +tags: + - name: developers + description: Operations available to regular developers +paths: + /repositories: + get: + tags: + - developers + summary: List all the repositories + description: | + By passing in the appropriate options, you can search for + available inventory in the system + parameters: + - in: query + name: search + description: pass an optional search string for looking up inventory + required: false + schema: + type: string + - in: query + name: limit + description: maximum number of records to return + schema: + type: integer + format: int32 + minimum: 0 + maximum: 50 + responses: + '200': + description: access package or search + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/RepositoryInfo' + '400': + description: bad input parameter + /repositories/{id}: + get: + tags: + - developers + summary: Gets specific repository details + description: | + By passing in the appropriate options, you can search for + available inventory in the system + parameters: + - in: path + name: id + description: repository identifier + required: true + schema: + type: string + responses: + '200': + description: access package or search + content: + application/json: + schema: + $ref: '#/components/schemas/RepositoryInfo' + '400': + description: bad input parameter +components: + schemas: + RepositoryInfo: + type: object + required: + - id + - name + - namespace + - firstCommitDate + - lastCommitDate + - lastCommitHash + - contributors + - metrics + properties: + id: + type: string + format: string + example: pallets/flask + name: + type: string + example: flask + namespace: + type: string + example: pallets + firstCommitDate: + type: string + format: date-time + example: '2016-08-29T09:12:33.001Z' + contributors: + type: array + items: + $ref: '#/components/schemas/Contributor' + metrics: + type: object + $ref: '#/components/schemas/RepositoryMetrics' + + Contributor: + type: object + required: + - name + - projects + properties: + name: + type: string + example: John Doe + projects: + type: array + items: + $ref: '#/components/schemas/Repository' + + Repository: + type: object + required: + - id + properties: + id: + type: string + format: string + example: pallets/flask + + RepositoryMetrics: + type: object + required: + - id + properties: + id: + type: string + format: string + example: pallets/flask + rating: + type: string \ No newline at end of file