-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/adding migrate changing service order #109
Merged
oxechicao
merged 5 commits into
develop
from
feature/adding-migrate-changing-service-order
Jul 13, 2020
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a7a369e
joia
oxechicao 482657f
WIP
oxechicao 7fbea36
Merge branch 'merge' into feature/adding-migrate-changing-service-order
oxechicao 30b3e04
[@chicaothiago] Issue #108 - Adaptei os mocks para as alterações nos …
oxechicao 4b35025
[@chicaothiago] Corrigindo erros. TODO provavelmente vai da ruim quan…
oxechicao File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
@@ -0,0 +1,131 @@ | ||
from flask_restful import Resource | ||
from flask import make_response, jsonify, request | ||
from ..helpers.helper_response import error_response, get_response, post_response | ||
from ..helpers.helper_update import pop_id | ||
from ..services.item_service import ItemService | ||
from ..validation.schemas.item_schema import ItemSchema | ||
from ..validation.validation_request import ( | ||
validate_request, | ||
validate_post, | ||
invalid_deleted_parameter, | ||
validate_request_dict_id, | ||
validate_request_id, | ||
validate_is_list, | ||
) | ||
import json | ||
|
||
|
||
class ItemsManyController(Resource): | ||
def get(self): | ||
args_deleted = request.args.get("deleted") | ||
if invalid_deleted_parameter(args_deleted): | ||
return error_response("Parameter deleted is not equal true.", 400) | ||
|
||
content = ItemService().fetch_items_list(args_deleted) | ||
|
||
return get_response(content, args_deleted) | ||
|
||
def post(self): | ||
body = request.get_json() | ||
|
||
validate, message = validate_request(body) | ||
if not validate: | ||
return error_response(message) | ||
|
||
errors = [] | ||
for index, item in enumerate(body["content"]): | ||
validate, message = validate_post(item) | ||
if not validate: | ||
errors.append({index: message}) | ||
continue | ||
|
||
erro_schema = ItemSchema().validate(item) | ||
if erro_schema: | ||
errors.append({index: erro_schema}) | ||
|
||
if errors: | ||
return error_response(errors) | ||
|
||
content = [] | ||
for item in body["content"]: | ||
content.append(ItemService().register_item(item)) | ||
|
||
return post_response(content) | ||
|
||
def put(self): | ||
body = request.get_json() | ||
validate, message = validate_request(body) | ||
if not validate: | ||
return error_response(message) | ||
|
||
errors = [] | ||
for index, item in enumerate(body['content']): | ||
validate, message = validate_request_dict_id(item) | ||
if not validate: | ||
errors.append({index: message}) | ||
continue | ||
|
||
erro_schema = ItemSchema().validate(item) | ||
if erro_schema: | ||
errors.append({index: erro_schema}) | ||
|
||
if errors: | ||
return error_response(errors) | ||
|
||
for index, item in enumerate(body['content']): | ||
id = pop_id(item) | ||
ItemService().replace_fields(id, item) | ||
|
||
return '', 200 | ||
|
||
def patch(self): | ||
body = request.get_json() | ||
validate, message = validate_request(body) | ||
if not validate: | ||
return error_response(message) | ||
|
||
errors = [] | ||
for index, item in enumerate(body["content"]): | ||
validate, message = validate_request_dict_id(item) | ||
if not validate: | ||
errors.append({index: message}) | ||
continue | ||
|
||
erro_schema = ItemSchema().validate_updates(item, index) | ||
if erro_schema: | ||
errors.append({index: erro_schema}) | ||
|
||
if errors: | ||
return error_response(errors) | ||
|
||
for index, item in enumerate(body["content"]): | ||
id = pop_id(item) | ||
ItemService().update_item_only_fields(data=item, id=id) | ||
|
||
return "", 200 | ||
|
||
def delete(self): | ||
body = request.get_json() | ||
validate, message = validate_request(body) | ||
if not validate: | ||
return error_response(message) | ||
|
||
validate, message = validate_is_list(body['content']) | ||
if not validate: | ||
return error_response(message) | ||
|
||
errors = [] | ||
for index, _id in enumerate(body['content']): | ||
validate, message = validate_request_id(_id) | ||
|
||
if not validate: | ||
errors.append({index: message}) | ||
|
||
if errors: | ||
return error_response(errors) | ||
|
||
|
||
for _id in body['content']: | ||
ItemService().delete_item(_id) | ||
|
||
return "", 200 |
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
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Talvez seja uma boa ideia mover as validações de esquema desta classe para validators/validation_request