File tree Expand file tree Collapse file tree 3 files changed +32
-4
lines changed Expand file tree Collapse file tree 3 files changed +32
-4
lines changed Original file line number Diff line number Diff line change 11from azure .cosmos .exceptions import CosmosResourceExistsError , CosmosResourceNotFoundError , CosmosHttpResponseError
22from faker import Faker
33from flask import current_app as app
4- from flask_restplus import Api , fields
4+ from flask_restplus import Api , fields , reqparse
55from flask_restplus ._http import HTTPStatus
66
77from commons .data_access_layer .cosmos_db import CustomError
1515 description = "API for the TimeTracker project"
1616)
1717
18+ # Filters
19+ def create_attributes_filter (attributes_filter ):
20+ filter_attributes_parser = reqparse .RequestParser ()
21+ for attribute in attributes_filter :
22+ filter_attributes_parser .add_argument (f'filters[{ attribute } ]' , location = 'args' )
23+
24+ return filter_attributes_parser
25+
1826# For matching UUIDs
1927UUID_REGEX = '[0-9a-f]{8}\-[0-9a-f]{4}\-4[0-9a-f]{3}\-[89ab][0-9a-f]{3}\-[0-9a-f]{12}'
2028
Original file line number Diff line number Diff line change 1+ import re
2+
3+ def remove_none_values (dictionary ):
4+ dictionary_with_values = {}
5+ for key , value in dictionary .items ():
6+ if value is not None :
7+ dictionary_with_values .update ({key : value })
8+ return dictionary_with_values
9+
10+
11+ def remove_filters_wrapper_from_keys (dictionary ):
12+ dictionary_with_unwrapped_keys = {}
13+ for key , value in dictionary .items ():
14+ unwrapped_key = re .search ('\\ [(.+?)\\ ]' , key ).groups ()[0 ]
15+ dictionary_with_unwrapped_keys .update ({unwrapped_key : value })
16+ return dictionary_with_unwrapped_keys
Original file line number Diff line number Diff line change 11from faker import Faker
22from flask_restplus import Namespace , Resource , fields
33from flask_restplus ._http import HTTPStatus
4- from flask import request
54
6- from time_tracker_api .api import common_fields , UUID_REGEX
5+ from time_tracker_api .api import common_fields , UUID_REGEX , create_attributes_filter
6+
7+ from time_tracker_api .collections .dictionary_utils import remove_none_values , remove_filters_wrapper_from_keys
78from time_tracker_api .projects .projects_model import create_dao
89
910faker = Faker ()
5556
5657project_dao = create_dao ()
5758
59+ attributes_filter = create_attributes_filter (['customer_id' ])
5860
5961@ns .route ('' )
6062class Projects (Resource ):
6163 @ns .doc ('list_projects' )
6264 @ns .marshal_list_with (project )
65+ @ns .expect (attributes_filter )
6366 def get (self ):
6467 """List all projects"""
65- return project_dao .get_all (conditions = request .args )
68+ conditions = remove_none_values (attributes_filter .parse_args ())
69+ return project_dao .get_all (conditions = remove_filters_wrapper_from_keys (conditions ))
6670
6771 @ns .doc ('create_project' )
6872 @ns .response (HTTPStatus .CONFLICT , 'This project already exists' )
You can’t perform that action at this time.
0 commit comments