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 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 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 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)