Skip to content

Commit

Permalink
[feat](#80) Adição da model imovel e seu endpoint na API
Browse files Browse the repository at this point in the history
Co-authored-by: Rafael Berto <[email protected]>
  • Loading branch information
JoaoHenrique12 and RafaelBP02 committed Jan 27, 2023
1 parent 7661896 commit c38b16a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
7 changes: 7 additions & 0 deletions app/backend/spothood/condominium/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,10 @@ class Aviso(models.Model):
titulo = models.CharField(max_length=75, null=False)
descricao = models.CharField(max_length=500, null=False)
data_cadastro = models.DateTimeField(auto_now_add=True,null=False)

class Imovel(models.Model):
idImovel = models.AutoField(primary_key=True)
cpf = models.ForeignKey(Pessoa, on_delete=models.RESTRICT, verbose_name=('cpf'))
cnpj = models.ForeignKey(Condominio, on_delete=models.RESTRICT, verbose_name=('cnpj'))

informacao_complementar = models.CharField(max_length=500, null=False)
12 changes: 11 additions & 1 deletion app/backend/spothood/condominium/serializers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from rest_framework import serializers
from .models import Pessoa, Condominio, Aviso
from .models import Pessoa, Condominio, Aviso, Imovel

from .validacao import Validador

Expand Down Expand Up @@ -99,3 +99,13 @@ class Meta:
'descricao',
'data_cadastro'
)

class ImovelSerializer(serializers.ModelSerializer):
class Meta:
model = Imovel
fields = (
'idImovel',
'cpf',
'cnpj',
'informacao_complementar',
)
3 changes: 2 additions & 1 deletion app/backend/spothood/condominium/urls.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from rest_framework import routers

from .views import PessoaViewSet, CondominioViewSet, AvisoViewSet
from .views import PessoaViewSet, CondominioViewSet, AvisoViewSet, ImovelViewSet

router = routers.DefaultRouter()
router.register(r'pessoa', PessoaViewSet)
router.register(r'condominio', CondominioViewSet)
router.register(r'aviso', AvisoViewSet)
router.register(r'imovel', ImovelViewSet)
9 changes: 7 additions & 2 deletions app/backend/spothood/condominium/views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from rest_framework import viewsets
from rest_framework import permissions
from .models import Pessoa, Condominio, Aviso
from .serializers import PessoaSerializer, CondominioSerializer, AvisoSerializer
from .models import Pessoa, Condominio, Aviso, Imovel
from .serializers import PessoaSerializer, CondominioSerializer, AvisoSerializer, ImovelSerializer

class PessoaViewSet(viewsets.ModelViewSet):
queryset = Pessoa.objects.all()
Expand All @@ -17,3 +17,8 @@ class AvisoViewSet(viewsets.ModelViewSet):
queryset = Aviso.objects.all()
serializer_class = AvisoSerializer
permission_classes = (permissions.AllowAny,)

class ImovelViewSet(viewsets.ModelViewSet):
queryset = Imovel.objects.all()
serializer_class = ImovelSerializer
permission_classes = (permissions.AllowAny,)

0 comments on commit c38b16a

Please sign in to comment.