def standard_list(): """ get: summary: List all standards responses: 200: description: Success response content: application/json: schema: StandardListResponseSchema """ service = StandardManagerService(logger=logger) request = ApiRequest().parse_request(app) response = ApiResponse(request) status_code = 200 try: data = service.list(request) total = service.count(request) response.set_data(data) response.set_total(total) except Exception as err: logger.error(err) if isinstance(err, ApiException): api_ex = err status_code = 404 else: api_ex = ApiException(MessagesEnum.LIST_ERROR) status_code = 500 response.set_exception(api_ex) return response.get_response(status_code)
def updates_sync(): """ get: summary: Synchronize the updates responses: 200: description: Success response content: application/json: schema: UpdatesSyncResponseSchema """ service = UpdateSynchronizerService() request = ApiRequest().parse_request(app) response = ApiResponse(request) status_code = 200 try: raise ApiException(MessagesEnum.METHOD_NOT_IMPLEMENTED_ERROR) except Exception as err: logger.error(err) status_code = 501 if isinstance(err, ApiException): api_ex = err else: api_ex = ApiException(MessagesEnum.METHOD_NOT_IMPLEMENTED_ERROR) response.set_exception(api_ex) return response.get_response(status_code)
def standard_delete(uuid): """ delete: summary: Delete Standard parameters: - in: path name: uuid description: "Standard uuid" required: true schema: type: string format: UUID responses: 200: content: application/json: schema: StandardDeleteResponseSchema """ service = StandardManagerService(logger=logger) request = ApiRequest().parse_request(app) response = ApiResponse(request) status_code = 200 try: service.delete(request, uuid) data = { "success": True, "code": MessagesEnum.ENTITY_DELETION_SUCCESS.code, "label": MessagesEnum.ENTITY_DELETION_SUCCESS.label, "message": MessagesEnum.ENTITY_DELETION_SUCCESS.message, "params": [uuid] } response.set_data(data) except Exception as err: print(err) logger.error(err) if isinstance(err, ApiException): api_ex = err status_code = 404 else: api_ex = ApiException(MessagesEnum.DELETE_ERROR) status_code = 500 data = { "success": False, "code": api_ex.code, "label": api_ex.label, "message": api_ex.message, # por segurança não passar o param aqui "params": [] } response.set_data(data) # response.set_exception(api_ex) return response.get_response(status_code)
def get_request(): request = ApiRequest() request.limit = 2 request2 = ApiRequest() request2.limit = 2 request2.offset = 1 return (request, ), (request2, ),
def standard_update(uuid): """ put: summary: Update Standard parameters: - in: path name: uuid description: "Standard uuid" required: true schema: type: string format: UUID requestBody: description: 'Objeto a ser atualizado' required: true content: application/json: schema: StandardUpdateRequest responses: 200: content: application/json: schema: StandardUpdateResponseSchema """ service = StandardManagerService(logger=logger) request = ApiRequest().parse_request(app) response = ApiResponse(request) status_code = 200 try: data = service.update(request, uuid) response.set_data(data) except Exception as err: logger.error(err) if isinstance(err, ApiException): api_ex = err status_code = 404 else: api_ex = ApiException(MessagesEnum.UPDATE_ERROR) status_code = 500 response.set_exception(api_ex) return response.get_response(status_code)
def updates_get(uuid): """ get: summary: Get Standard Update parameters: - in: path name: uuid description: "Standard Update uuid" required: true schema: type: string format: UUID responses: 200: description: Success response content: application/json: schema: StandardUpdatesGetResponseSchema """ service = StandardUpdatesService() request = ApiRequest().parse_request(app) response = ApiResponse(request) status_code = 200 try: data = service.get(request, uuid) response.set_data(data) except Exception as err: logger.error(err) if isinstance(err, ApiException): api_ex = err status_code = 404 else: api_ex = ApiException(MessagesEnum.FIND_ERROR) status_code = 500 response.set_exception(api_ex) return response.get_response(status_code)
def updates_check(): """ get: summary: Check for updates responses: 200: description: Success response content: application/json: schema: UpdatesCheckResponseSchema """ service = UpdateCheckerService() request = ApiRequest().parse_request(app) response = ApiResponse(request) status_code = 200 try: service.execute() total = len(service.updates) data = service.get_updates() print(total) print(data) response.set_data(data) response.set_total(total) except Exception as err: logger.error(err) if isinstance(err, ApiException): api_ex = err status_code = 404 else: api_ex = ApiException(MessagesEnum.LIST_ERROR) status_code = 500 response.set_exception(api_ex) return response.get_response(status_code)
def get_sale_event_request(): with open( path.join( ROOT_DIR, 'tests/datasources/request/protheus/sale-event.json')) as f: request_str = f.read() try: request_json = json.loads(request_str) request = ApiRequest() request.host = 'localhost' request.path = '/v1/event/sale-event' request.method = 'POST' request.server_type = "Flask" request.where = request_json return request except Exception as err: print(err) raise Exception('Invalid JSON')
def standard_create(): """ post: summary: Create Standard requestBody: description: 'Objeto a ser criado' required: true content: application/json: schema: StandardCreateRequest responses: 200: content: application/json: schema: StandardCreateResponseSchema """ service = StandardManagerService(logger=logger) request = ApiRequest().parse_request(app) response = ApiResponse(request) status_code = 200 try: data = service.create(request) response.set_data(data) except Exception as err: logger.error(err) if isinstance(err, ApiException): api_ex = err status_code = 404 else: api_ex = ApiException(MessagesEnum.LIST_ERROR) status_code = 500 response.set_exception(api_ex) return response.get_response(status_code)
def get_request(): request = ApiRequest() return (request, ),