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 1
1
from azure .cosmos .exceptions import CosmosResourceExistsError , CosmosResourceNotFoundError , CosmosHttpResponseError
2
2
from faker import Faker
3
3
from flask import current_app as app
4
- from flask_restplus import Api , fields
4
+ from flask_restplus import Api , fields , reqparse
5
5
from flask_restplus ._http import HTTPStatus
6
6
7
7
from commons .data_access_layer .cosmos_db import CustomError
18
18
security = "TimeTracker JWT" ,
19
19
)
20
20
21
+ # Filters
22
+ def create_attributes_filter (attributes_filter ):
23
+ filter_attributes_parser = reqparse .RequestParser ()
24
+ for attribute in attributes_filter :
25
+ filter_attributes_parser .add_argument (f'filters[{ attribute } ]' , location = 'args' )
26
+
27
+ return filter_attributes_parser
28
+
21
29
# For matching UUIDs
22
30
UUID_REGEX = '[0-9a-f]{8}\-[0-9a-f]{4}\-4[0-9a-f]{3}\-[89ab][0-9a-f]{3}\-[0-9a-f]{12}'
23
31
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 1
1
from faker import Faker
2
2
from flask_restplus import Namespace , Resource , fields
3
3
from flask_restplus ._http import HTTPStatus
4
- from flask import request
5
4
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
7
8
from time_tracker_api .projects .projects_model import create_dao
8
9
9
10
faker = Faker ()
55
56
56
57
project_dao = create_dao ()
57
58
59
+ attributes_filter = create_attributes_filter (['customer_id' ])
58
60
59
61
@ns .route ('' )
60
62
class Projects (Resource ):
61
63
@ns .doc ('list_projects' )
62
64
@ns .marshal_list_with (project )
65
+ @ns .expect (attributes_filter )
63
66
def get (self ):
64
67
"""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 ))
66
70
67
71
@ns .doc ('create_project' )
68
72
@ns .response (HTTPStatus .CONFLICT , 'This project already exists' )
You can’t perform that action at this time.
0 commit comments