-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into feature/91_new_patch_service_order
- Loading branch information
Showing
26 changed files
with
543 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -133,4 +133,4 @@ env_config.py | |
api/storage/* | ||
teste-gestao | ||
env/ | ||
.vscode | ||
.vscode |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,87 @@ | ||
from flask_restful import Resource | ||
from ..helpers.helper_response import get_response, error_response | ||
from ..validation.validation_request import invalid_deleted_parameter | ||
from ..services.service_order_service import ServiceOrderService | ||
from http import HTTPStatus | ||
from flask import request | ||
from .dtos.service_order_request import ServiceOrderRequest | ||
from flask_restful import Resource | ||
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 api.v2.models.schemas.service_order_schema import ServiceOrderSchema | ||
from api.v2.utils.util_response import error_response, post_response | ||
from .validators.validation_request import validate_request_id | ||
|
||
|
||
class ServiceOrdersManyController(Resource): | ||
def get(self): | ||
deleted_included = request.args.get("deleted") | ||
if invalid_deleted_parameter(deleted_included): | ||
return error_response( | ||
"Parameter deleted is not equal true.", HTTPStatus.BAD_REQUEST) | ||
"Parameter deleted is not equal true.", HTTPStatus.BAD_REQUEST | ||
) | ||
if deleted_included: | ||
service_orders = ServiceOrderService().fetch_all() | ||
service_orders = ServiceOrderService().fetch_all() | ||
else: | ||
service_orders = ServiceOrderService().fetch_active() | ||
|
||
return get_response(service_orders, deleted_included) | ||
|
||
def patch(self, id=None): | ||
body = request.get_json() | ||
service_order_request = ServiceOrderRequest(body['content']) | ||
|
||
service_order_request = ServiceOrderRequest(body["content"]) | ||
so = service_order_request.get() | ||
|
||
ServiceOrderService().update(so) | ||
return "", 200 | ||
|
||
|
||
|
||
|
||
def post(self): | ||
body = request.get_json() | ||
|
||
validate, message = validate_request(body) | ||
if not validate: | ||
return error_response(message) | ||
|
||
errors = [] | ||
for index, service_order in enumerate(body["content"]): | ||
validate, message = ServiceOrderSchema().validate_save(service_order) | ||
if not validate: | ||
errors.append({index: message}) | ||
continue | ||
|
||
validate, message = validate_request_id( | ||
"equipamento", service_order["equipamento_id"] | ||
) | ||
if not validate: | ||
errors.append({index: message}) | ||
|
||
accessories = service_order["triagem"]["acessorios"] | ||
for accessory in accessories: | ||
validate, message = validate_request_id("item", accessory["item_id"]) | ||
if not validate: | ||
errors.append({index: message}) | ||
|
||
items = service_order["diagnostico"]["itens"] | ||
for item in items: | ||
validate, message = validate_request_id("item", item["item_id"]) | ||
if not validate: | ||
errors.append({index: message}) | ||
|
||
service_order[ | ||
"numero_ordem_servico" | ||
] = ServiceOrderService().format_service_order_number( | ||
service_order["numero_ordem_servico"] | ||
) | ||
|
||
if ServiceOrderService().check_duplicates_service_order_number( | ||
service_order["numero_ordem_servico"] | ||
): | ||
errors.append({index: "Service Order number already exists"}) | ||
|
||
if errors: | ||
return error_response(errors) | ||
|
||
content = [] | ||
for service_order in body["content"]: | ||
content.append(ServiceOrderService().save_service_order(service_order)) | ||
|
||
return post_response(content) |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
from bson import ObjectId | ||
from api.v2.services.item_service import ItemService | ||
from api.services.equipamento_service import listar_equipamento_by_id | ||
|
||
|
||
def invalid_deleted_parameter(param): | ||
return param and param != "true" | ||
|
||
|
||
def validate_is_list(body): | ||
if isinstance(type(body), list): | ||
return (False, "Not a list.") | ||
return (True, "OK") | ||
|
||
|
||
def validate_post(body): | ||
if "_id" in body: | ||
return (False, "ID must not be sent") | ||
return (True, "OK") | ||
|
||
|
||
def validate_request(body): | ||
if not body: | ||
return (False, "No body found") | ||
|
||
if not "content" in body: | ||
return (False, "No content found") | ||
|
||
if not isinstance(body["content"], list): | ||
return (False, "No list found.") | ||
|
||
if not len(body["content"]): | ||
return (False, "Empty list. Nothing to do.") | ||
for item in body["content"]: | ||
if not item: | ||
return (False, "Some entry has no data.") | ||
|
||
return (True, "OK") | ||
|
||
|
||
def validate_id_included(entity): | ||
if "_id" not in entity: | ||
return (False, "Missing ID") | ||
return (True, "OK") | ||
|
||
|
||
def validate_id_objectID(_id): | ||
try: | ||
ObjectId(_id) | ||
except Exception: | ||
return (False, "Invalid ID") | ||
return (True, "OK") | ||
|
||
|
||
def validate_id_exists(entity, _id): | ||
if entity == "item": | ||
if not ItemService().fetch_item_by_id(_id): | ||
return (False, "Nonexistent item ID") | ||
|
||
if entity == "equipamento": | ||
if not listar_equipamento_by_id(_id): | ||
return (False, "Nonexistent equipamento ID") | ||
|
||
return (True, "OK") | ||
|
||
|
||
def validate_request_dict_id(entity): | ||
validate, message = validate_id_included(entity) | ||
if not validate: | ||
return (validate, message) | ||
|
||
validate, message = validate_request_id(entity["_id"]) | ||
if not validate: | ||
return (validate, message) | ||
|
||
return (True, "OK") | ||
|
||
|
||
def validate_request_id(entity, _id): | ||
validate, message = validate_id_objectID(_id) | ||
if not validate: | ||
return (validate, message) | ||
|
||
validate, message = validate_id_exists(entity, _id) | ||
if not validate: | ||
return (validate, message) | ||
|
||
return (True, "OK") |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from marshmallow import ValidationError | ||
|
||
|
||
class SchemaBase: | ||
def validate_save(self, body): | ||
if "_id" in body: | ||
return False, "Id must not be sent" | ||
|
||
if "updated_at" in body: | ||
return False, "Updated must not be sent" | ||
|
||
if "deleted_at" in body: | ||
return False, "Deleted must not be sent" | ||
|
||
try: | ||
self.load(body) | ||
except ValidationError as err: | ||
return False, err.messages | ||
|
||
return True, "OK" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
from api.v2.models import service_order_model | ||
from .schema_base import SchemaBase | ||
from marshmallow import Schema, fields, validate | ||
|
||
|
||
class AccessorySchema(Schema): | ||
class Meta: | ||
model = service_order_model.Acessorio | ||
fields = ("item_id", | ||
"acompanha", | ||
"quantidade", | ||
"estado_de_conservacao") | ||
|
||
item_id = fields.String(required=True) | ||
acompanha = fields.Boolean(required=True) | ||
quantidade = fields.Integer(required=True) | ||
estado_de_conservacao = fields.String(required=False) | ||
|
||
|
||
class ScreeningSchema(Schema): | ||
class Meta: | ||
model = service_order_model.Triagem | ||
fields = ("estado_de_conservacao", | ||
"foto_antes_limpeza", | ||
"acessorios", | ||
"foto_apos_limpeza") | ||
|
||
foto_antes_limpeza = fields.String(required=False) | ||
estado_de_conservacao = fields.String(required=False) | ||
acessorios = fields.List(fields.Nested(AccessorySchema), required=False) | ||
foto_apos_limpeza = fields.String(required=False) | ||
|
||
|
||
class ItemDiganotico(Schema): | ||
class Meta: | ||
model = service_order_model.Item | ||
fields = ("item_id", | ||
"quantidade") | ||
|
||
item_id = fields.String(required=True) | ||
quantidade = fields.Integer(required=True) | ||
|
||
|
||
class DiagnosticSchema(Schema): | ||
class Meta: | ||
model = service_order_model.Triagem | ||
fields = ("resultado_tecnico", | ||
"demanda_servicos", | ||
"observacoes", | ||
"itens") | ||
|
||
resultado_tecnico = fields.String(required=False) | ||
demanda_servicos = fields.String(required=False) | ||
observacoes = fields.String(required=False) | ||
itens = fields.List(fields.Nested(ItemDiganotico), required=False) | ||
|
||
|
||
class CalibrationSchema(Schema): | ||
class Meta: | ||
model = service_order_model.Calibragem | ||
fields = ( | ||
"status", | ||
) | ||
|
||
status = fields.String(required=False) | ||
|
||
|
||
class ServiceOrderSchema(Schema, SchemaBase): | ||
class Meta: | ||
model = service_order_model.OrdemServico | ||
fields = ("_id", | ||
"equipamento_id", | ||
"numero_ordem_servico", | ||
"created_at", | ||
"updated_at", | ||
"triagem", | ||
"clinico", | ||
"tecnico", | ||
"foto_equipamento_chegada", | ||
"status", | ||
"diagnostico", | ||
"calibragem") | ||
|
||
equipamento_id = fields.String(required=False) | ||
numero_ordem_servico = fields.Integer(required=True) | ||
created_at = fields.DateTime(required=False) | ||
updated_at = fields.DateTime(required=False) | ||
triagem = fields.Nested(ScreeningSchema, required=False) | ||
diagnostico = fields.Nested(DiagnosticSchema, required=False) | ||
calibragem = fields.Nested(CalibrationSchema, required=True) | ||
status = fields.String(validate=validate.OneOf(["triagem", "diagnostico"]), | ||
required=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.