Skip to content

Commit

Permalink
Merge pull request #2 from fga-gpp-mds/development
Browse files Browse the repository at this point in the history
0.1 is Kraken "Release The Kraken"
  • Loading branch information
tulioc authored Sep 28, 2017
2 parents 76df060 + 1f47346 commit 16dfb7b
Show file tree
Hide file tree
Showing 20 changed files with 139 additions and 3 deletions.
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# Django stuff:
*.log
local_settings.py

#SQLite
*.sqlite3
Binary file removed DepuTinder_API/__pycache__/__init__.cpython-34.pyc
Binary file not shown.
Binary file removed DepuTinder_API/__pycache__/settings.cpython-34.pyc
Binary file not shown.
Binary file removed DepuTinder_API/__pycache__/urls.cpython-34.pyc
Binary file not shown.
Binary file removed DepuTinder_API/__pycache__/wsgi.cpython-34.pyc
Binary file not shown.
5 changes: 3 additions & 2 deletions DepuTinder_API/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
2 changes: 2 additions & 0 deletions DepuTinder_API/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
]
28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,27 @@
# 2017.2-DepuTinder-API
## 2017.2 - meRepresenta - Rest API


<p align="justify">&emsp;&emsp;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">&emsp;&emsp;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">&emsp;&emsp;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">&emsp;&emsp;Para executar a API é fundamental o seguinte comando: </p>

```
python3 manage.py runserver
```

<p align="justify">&emsp;&emsp;Para acessar o servidor gerado no comando anterior, basta acessar [localhost:8000](http://localhost:8000/)</p>
Binary file modified db.sqlite3
Binary file not shown.
Empty file added propositions/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions propositions/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
5 changes: 5 additions & 0 deletions propositions/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class PropositionsConfig(AppConfig):
name = 'propositions'
27 changes: 27 additions & 0 deletions propositions/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -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)),
],
),
]
19 changes: 19 additions & 0 deletions propositions/migrations/0002_remove_propositions_propositionid.py
Original file line number Diff line number Diff line change
@@ -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',
),
]
Empty file.
7 changes: 7 additions & 0 deletions propositions/models.py
Original file line number Diff line number Diff line change
@@ -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)
7 changes: 7 additions & 0 deletions propositions/serializers.py
Original file line number Diff line number Diff line change
@@ -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')
3 changes: 3 additions & 0 deletions propositions/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
5 changes: 5 additions & 0 deletions propositions/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.conf.urls import url
from .views import propositions

urlpatterns = [
]
20 changes: 20 additions & 0 deletions propositions/views.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 16dfb7b

Please sign in to comment.