diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..84e945d --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# Django stuff: +*.log +local_settings.py + +#SQLite +*.sqlite3 diff --git a/DepuTinder_API/__pycache__/__init__.cpython-34.pyc b/DepuTinder_API/__pycache__/__init__.cpython-34.pyc deleted file mode 100644 index c8f1a49..0000000 Binary files a/DepuTinder_API/__pycache__/__init__.cpython-34.pyc and /dev/null differ diff --git a/DepuTinder_API/__pycache__/settings.cpython-34.pyc b/DepuTinder_API/__pycache__/settings.cpython-34.pyc deleted file mode 100644 index 8fad0dd..0000000 Binary files a/DepuTinder_API/__pycache__/settings.cpython-34.pyc and /dev/null differ diff --git a/DepuTinder_API/__pycache__/urls.cpython-34.pyc b/DepuTinder_API/__pycache__/urls.cpython-34.pyc deleted file mode 100644 index 1056427..0000000 Binary files a/DepuTinder_API/__pycache__/urls.cpython-34.pyc and /dev/null differ diff --git a/DepuTinder_API/__pycache__/wsgi.cpython-34.pyc b/DepuTinder_API/__pycache__/wsgi.cpython-34.pyc deleted file mode 100644 index dd4249f..0000000 Binary files a/DepuTinder_API/__pycache__/wsgi.cpython-34.pyc and /dev/null differ diff --git a/DepuTinder_API/settings.py b/DepuTinder_API/settings.py index b479def..ca1209b 100644 --- a/DepuTinder_API/settings.py +++ b/DepuTinder_API/settings.py @@ -25,19 +25,20 @@ # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True -ALLOWED_HOSTS = [] +ALLOWED_HOSTS = ['localhost'] # Application definition INSTALLED_APPS = [ + 'propositions', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', - 'rest_framework', + 'rest_framework', ] MIDDLEWARE = [ diff --git a/DepuTinder_API/urls.py b/DepuTinder_API/urls.py index 5805efc..b4e98f1 100644 --- a/DepuTinder_API/urls.py +++ b/DepuTinder_API/urls.py @@ -15,7 +15,9 @@ """ from django.conf.urls import url from django.contrib import admin +from propositions.views import propositions urlpatterns = [ url(r'^admin/', admin.site.urls), + url(r'^propositions/', propositions), ] diff --git a/README.md b/README.md index 041a625..dc73caa 100644 --- a/README.md +++ b/README.md @@ -1 +1,27 @@ -# 2017.2-DepuTinder-API \ No newline at end of file +## 2017.2 - meRepresenta - Rest API + + +<p align="justify">  A API do software possui um repositório destinado a ela. Este pode ser acessado no endereço a seguir: +[meRepresenta](https://github.com/fga-gpp-mds/2017.2-DepuTinder)</p> + +### Instalação + +<p align="justify">  Para que seja possível a utilização da API, é preciso executar o makemigrations. Este comando é necessário para criação de novas migrações relacionadas às models:</p> + +``` +python3 manage.py makemigrations +``` + +<p align="justify">  Para que essas migrações possam ser manipuladas, tanto na aplicação de novas quando no exclusão das existentes, é necessário executar o comando:</p> + +``` +python3 manage.py migrate +``` + +<p align="justify">  Para executar a API é fundamental o seguinte comando: </p> + +``` +python3 manage.py runserver +``` + +<p align="justify">  Para acessar o servidor gerado no comando anterior, basta acessar [localhost:8000](http://localhost:8000/)</p> diff --git a/db.sqlite3 b/db.sqlite3 index dc6058b..6132868 100644 Binary files a/db.sqlite3 and b/db.sqlite3 differ diff --git a/propositions/__init__.py b/propositions/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/propositions/admin.py b/propositions/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/propositions/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/propositions/apps.py b/propositions/apps.py new file mode 100644 index 0000000..394c3f8 --- /dev/null +++ b/propositions/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class PropositionsConfig(AppConfig): + name = 'propositions' diff --git a/propositions/migrations/0001_initial.py b/propositions/migrations/0001_initial.py new file mode 100644 index 0000000..f02d617 --- /dev/null +++ b/propositions/migrations/0001_initial.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.5 on 2017-09-27 07:47 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Propositions', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('propositionID', models.IntegerField()), + ('propositionTitle', models.CharField(blank=True, max_length=100)), + ('propositionSubTitle', models.CharField(blank=True, max_length=150)), + ('propositionDescription', models.CharField(blank=True, max_length=200)), + ('propositionAuthor', models.CharField(blank=True, max_length=50)), + ], + ), + ] diff --git a/propositions/migrations/0002_remove_propositions_propositionid.py b/propositions/migrations/0002_remove_propositions_propositionid.py new file mode 100644 index 0000000..c45f1b5 --- /dev/null +++ b/propositions/migrations/0002_remove_propositions_propositionid.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.5 on 2017-09-27 20:17 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('propositions', '0001_initial'), + ] + + operations = [ + migrations.RemoveField( + model_name='propositions', + name='propositionID', + ), + ] diff --git a/propositions/migrations/__init__.py b/propositions/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/propositions/models.py b/propositions/models.py new file mode 100644 index 0000000..89fb68f --- /dev/null +++ b/propositions/models.py @@ -0,0 +1,7 @@ +from django.db import models + +class Propositions(models.Model): + propositionTitle = models.CharField(max_length=100, blank=True) + propositionSubTitle = models.CharField(max_length=150, blank=True) + propositionDescription = models.CharField(max_length=200, blank=True) + propositionAuthor = models.CharField(max_length=50, blank=True) diff --git a/propositions/serializers.py b/propositions/serializers.py new file mode 100644 index 0000000..c57dd50 --- /dev/null +++ b/propositions/serializers.py @@ -0,0 +1,7 @@ +from rest_framework import serializers +from .models import Propositions + +class PropositionsSerializer(serializers.Serializer): + class Meta: + model = Propositions + fields = ('propositionTitle', 'propositionSubTitle', 'propositionDescription', 'propositionAuthor') diff --git a/propositions/tests.py b/propositions/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/propositions/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/propositions/urls.py b/propositions/urls.py new file mode 100644 index 0000000..5007c3b --- /dev/null +++ b/propositions/urls.py @@ -0,0 +1,5 @@ +from django.conf.urls import url +from .views import propositions + +urlpatterns = [ +] diff --git a/propositions/views.py b/propositions/views.py new file mode 100644 index 0000000..716c66a --- /dev/null +++ b/propositions/views.py @@ -0,0 +1,20 @@ +from django.shortcuts import render +from .models import Propositions +from .serializers import PropositionsSerializer +from rest_framework.response import Response +from rest_framework import status +from rest_framework.decorators import api_view +import requests, json + +@api_view(['GET']) +def propositions(request): + propositions = Propositions.objects.all() + + if propositions: + return Response({}, status=status.HTTP_404_NOT_FOUND) + else: + serializer = PropositionsSerializer(propositions) + r = requests.get('https://api.myjson.com/bins/m7f4x', serializer) + data = json.loads(r.text) + + return Response(data, status=status.HTTP_201_CREATED)