Skip to content

Commit

Permalink
[@adrilene/@denisousa] Issue #73 - Iniciando registro da ordem de ser…
Browse files Browse the repository at this point in the history
…viço.
  • Loading branch information
Adrilene committed Jun 24, 2020
1 parent 0af3728 commit f2bdb85
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
6 changes: 6 additions & 0 deletions api/utils/success_response.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from flask import make_response, jsonify
from http import HTTPStatus


def post_response(content):
return make_response(jsonify({"content": content}), 201)
15 changes: 11 additions & 4 deletions api/v2/controllers/service_orders_many_controller.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from flask_restful import Resource
from ..helpers.helper_response import get_response, error_response
from ..helpers.helper_response import get_response
from ..validation.validation_request import invalid_deleted_parameter
from api.v2.controllers.validators.validation_request import validate_request
from api.v2.services.service_order_service import ServiceOrderService
from http import HTTPStatus
from flask import request
from api.v2.models.schemas.service_order_schema import ServiceOrderSchema
from api.v2.utils.util_response import error_response
from api.v2.utils import error_response, success_response


class ServiceOrdersManyController(Resource):
def get(self):
Expand Down Expand Up @@ -36,7 +37,13 @@ def post(self):
errors.append({index: message})
continue

if errors:
if errors:
return error_response(errors)

return ''
# Testar se o id do item existe.

content = []
for service_order in body["content"]:
content.append(ServiceOrderService().register_service_order(service_order))

return success_response.post_response(content)
4 changes: 4 additions & 0 deletions api/v2/services/service_order_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ def fetch_active(self):
def fetch_all(self):
return self.parser_mongo_response_to_list(
OrdemServico.objects())

def register_service_order(self, body):
service_order = Service_order(**body).save()
return str(service_order.id)

0 comments on commit f2bdb85

Please sign in to comment.