From 8068e64be4275300c57fdf9f357350198d9a1e1c Mon Sep 17 00:00:00 2001 From: Leandro Roberto Date: Tue, 2 Apr 2019 00:07:18 -0300 Subject: [PATCH] add endpoint get ultima_tramitacao --- sapl/api/views.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/sapl/api/views.py b/sapl/api/views.py index f2f146e24..f15232871 100644 --- a/sapl/api/views.py +++ b/sapl/api/views.py @@ -349,6 +349,23 @@ class _ProposicaoViewSet(SaplSetViews['materia']['proposicao']): return qs +class _MateriaLegislativaViewSet(SaplSetViews['materia']['materialegislativa']): + + @action(detail=True, methods=['GET']) + def ultima_tramitacao(self, request, *args, **kwargs): + + materia = self.get_object() + if not materia.tramitacao_set.exists(): + return Response({}) + + ultima_tramitacao = materia.tramitacao_set.last() + + serializer_class = SaplSetViews[ + 'materia']['tramitacao'].serializer_class(ultima_tramitacao) + + return Response(serializer_class.data) + + class _TipoMateriaLegislativaViewSet(SaplSetViews['materia']['tipomaterialegislativa']): @action(detail=True, methods=['POST']) @@ -443,6 +460,8 @@ class _SessaoPlenariaViewSet( SaplSetViews['base']['autor'] = _AutorViewSet.build_class_with_actions() + +SaplSetViews['materia']['materialegislativa'] = _MateriaLegislativaViewSet SaplSetViews['materia']['proposicao'] = _ProposicaoViewSet SaplSetViews['materia']['tipomaterialegislativa'] = _TipoMateriaLegislativaViewSet