Skip to content

Commit 6559839

Browse files
committed
Add project type and work type resources
1 parent 54b47c9 commit 6559839

File tree

6 files changed

+217
-123
lines changed

6 files changed

+217
-123
lines changed
Lines changed: 122 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -1,118 +1,122 @@
1-
# Copyright © 2019 Province of British Columbia
2-
#
3-
# Licensed under the Apache License, Version 2.0 (the "License");
4-
# you may not use this file except in compliance with the License.
5-
# You may obtain a copy of the License at
6-
#
7-
# http://www.apache.org/licenses/LICENSE-2.0
8-
#
9-
# Unless required by applicable law or agreed to in writing, software
10-
# distributed under the License is distributed on an "AS IS" BASIS,
11-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12-
# See the License for the specific language governing permissions and
13-
# limitations under the License.
14-
"""Exposes all of the resource endpoints mounted in Flask-Blueprint style.
15-
16-
Uses restplus namespaces to mount individual api endpoints into the service.
17-
18-
All services have 2 defaults sets of endpoints:
19-
- ops
20-
- meta
21-
That are used to expose operational health information about the service, and meta information.
22-
"""
23-
24-
from flask import Blueprint
25-
26-
from .act_section import API as ACT_SECTION_API
27-
from .apihelper import Api
28-
from .code import API as CODES_API
29-
from .event import API as EVENT_API
30-
from .event_configuration import API as EVENT_CONFIGURATION_API
31-
from .event_template import API as EVENT_TEMPLATE_API
32-
from .indigenous_nation import API as INDIGENOUS_NATION_API
33-
from .inspection import API as INSPECTION_API
34-
from .lookup_data_generator import API as LOOKUP_API
35-
from .meta import API as META_API
36-
from .ops import API as OPS_API
37-
from .outcome import API as OUTCOME_API
38-
from .outcome_configuration import API as OUTCOME_CONFIGURATION_API
39-
from .phase import API as PHASE_API
40-
from .position import API as POSITION_API
41-
from .project import API as PROJECTS_API
42-
from .proponent import API as PROPONENT_API
43-
from .reminder_configuration import API as REMINDER_CONFIGURATION_API
44-
from .reports import API as REPORTS_API
45-
from .responsibility import API as RESPONSIBILITY_API
46-
from .special_field import API as SPECIAL_FIELD_API
47-
from .staff import API as STAFF_API
48-
from .sub_types import API as SUB_TYPES_API
49-
from .sync_form_data import API as SYNC_FORM_DATA_API
50-
from .task import API as TASK_API
51-
from .task_template import API as TASK_TEMPLATE_API
52-
from .user import API as USER_API
53-
from .work import API as WORK_API
54-
from .work_issues import API as WORK_ISSUES_API
55-
from .work_status import API as WORK_STATUS_API
56-
from .region import API as REGION_API
57-
from .eao_team import API as EAO_TEAM_API
58-
59-
60-
__all__ = ("API_BLUEPRINT", "OPS_BLUEPRINT")
61-
62-
# This will add the Authorize button to the swagger docs
63-
AUTHORIZATIONS = {"apikey": {"type": "apiKey", "in": "header", "name": "Authorization"}}
64-
65-
OPS_BLUEPRINT = Blueprint("API_OPS", __name__, url_prefix="/ops")
66-
67-
API_OPS = Api(
68-
OPS_BLUEPRINT,
69-
title="Service OPS API",
70-
version="1.0",
71-
description="The Core API for the Reports System",
72-
security=["apikey"],
73-
authorizations=AUTHORIZATIONS,
74-
)
75-
76-
API_OPS.add_namespace(OPS_API, path="/")
77-
78-
API_BLUEPRINT = Blueprint("API", __name__, url_prefix="/api/v1")
79-
80-
API = Api(
81-
API_BLUEPRINT,
82-
title="EAO Reports API",
83-
version="1.0",
84-
description="The Core API for the Reports System",
85-
security=["apikey"],
86-
authorizations=AUTHORIZATIONS,
87-
)
88-
89-
API.add_namespace(META_API, path="/meta")
90-
API.add_namespace(CODES_API, path="/codes")
91-
API.add_namespace(PROJECTS_API, path="/projects")
92-
API.add_namespace(SYNC_FORM_DATA_API, path="/sync-form-data")
93-
API.add_namespace(PHASE_API, path="/phases")
94-
API.add_namespace(STAFF_API, path="/staffs")
95-
API.add_namespace(OUTCOME_API, path="/outcomes")
96-
API.add_namespace(SUB_TYPES_API, path="/sub-types")
97-
API.add_namespace(INSPECTION_API, path="/inspections")
98-
API.add_namespace(WORK_API, path="/works")
99-
API.add_namespace(LOOKUP_API, path="/lookups")
100-
API.add_namespace(REPORTS_API, path="/reports")
101-
API.add_namespace(INDIGENOUS_NATION_API, path="/indigenous-nations")
102-
API.add_namespace(PROPONENT_API, path="/proponents")
103-
API.add_namespace(REMINDER_CONFIGURATION_API, path="/reminder-configurations")
104-
API.add_namespace(USER_API, path='/users')
105-
API.add_namespace(TASK_TEMPLATE_API, path="/task-templates")
106-
API.add_namespace(EVENT_TEMPLATE_API, path="/event-templates")
107-
API.add_namespace(TASK_API, path="/tasks")
108-
API.add_namespace(EVENT_API, path="/milestones")
109-
API.add_namespace(EVENT_CONFIGURATION_API, path="/event-configurations")
110-
API.add_namespace(RESPONSIBILITY_API, path="/responsibilities")
111-
API.add_namespace(OUTCOME_CONFIGURATION_API, path="/outcome-configurations")
112-
API.add_namespace(ACT_SECTION_API, path="/act-sections")
113-
API.add_namespace(WORK_STATUS_API, path='/work/<int:work_id>/statuses')
114-
API.add_namespace(WORK_ISSUES_API, path='/work/<int:work_id>/issues')
115-
API.add_namespace(SPECIAL_FIELD_API, path='/special-fields')
116-
API.add_namespace(POSITION_API, path='/positions')
117-
API.add_namespace(REGION_API, path='/regions')
118-
API.add_namespace(EAO_TEAM_API, path='/eao-teams')
1+
# Copyright © 2019 Province of British Columbia
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
"""Exposes all of the resource endpoints mounted in Flask-Blueprint style.
15+
16+
Uses restplus namespaces to mount individual api endpoints into the service.
17+
18+
All services have 2 defaults sets of endpoints:
19+
- ops
20+
- meta
21+
That are used to expose operational health information about the service, and meta information.
22+
"""
23+
24+
from flask import Blueprint
25+
26+
from .act_section import API as ACT_SECTION_API
27+
from .apihelper import Api
28+
from .code import API as CODES_API
29+
from .event import API as EVENT_API
30+
from .event_configuration import API as EVENT_CONFIGURATION_API
31+
from .event_template import API as EVENT_TEMPLATE_API
32+
from .indigenous_nation import API as INDIGENOUS_NATION_API
33+
from .inspection import API as INSPECTION_API
34+
from .lookup_data_generator import API as LOOKUP_API
35+
from .meta import API as META_API
36+
from .ops import API as OPS_API
37+
from .outcome import API as OUTCOME_API
38+
from .outcome_configuration import API as OUTCOME_CONFIGURATION_API
39+
from .phase import API as PHASE_API
40+
from .position import API as POSITION_API
41+
from .project import API as PROJECTS_API
42+
from .project_type import API as PROJECT_TYPES_API
43+
from .proponent import API as PROPONENT_API
44+
from .reminder_configuration import API as REMINDER_CONFIGURATION_API
45+
from .reports import API as REPORTS_API
46+
from .responsibility import API as RESPONSIBILITY_API
47+
from .special_field import API as SPECIAL_FIELD_API
48+
from .staff import API as STAFF_API
49+
from .sub_types import API as SUB_TYPES_API
50+
from .sync_form_data import API as SYNC_FORM_DATA_API
51+
from .task import API as TASK_API
52+
from .task_template import API as TASK_TEMPLATE_API
53+
from .user import API as USER_API
54+
from .work import API as WORK_API
55+
from .work_issues import API as WORK_ISSUES_API
56+
from .work_status import API as WORK_STATUS_API
57+
from .work_type import API as WORK_TYPES_API
58+
from .region import API as REGION_API
59+
from .eao_team import API as EAO_TEAM_API
60+
61+
62+
__all__ = ("API_BLUEPRINT", "OPS_BLUEPRINT")
63+
64+
# This will add the Authorize button to the swagger docs
65+
AUTHORIZATIONS = {"apikey": {"type": "apiKey", "in": "header", "name": "Authorization"}}
66+
67+
OPS_BLUEPRINT = Blueprint("API_OPS", __name__, url_prefix="/ops")
68+
69+
API_OPS = Api(
70+
OPS_BLUEPRINT,
71+
title="Service OPS API",
72+
version="1.0",
73+
description="The Core API for the Reports System",
74+
security=["apikey"],
75+
authorizations=AUTHORIZATIONS,
76+
)
77+
78+
API_OPS.add_namespace(OPS_API, path="/")
79+
80+
API_BLUEPRINT = Blueprint("API", __name__, url_prefix="/api/v1")
81+
82+
API = Api(
83+
API_BLUEPRINT,
84+
title="EAO Reports API",
85+
version="1.0",
86+
description="The Core API for the Reports System",
87+
security=["apikey"],
88+
authorizations=AUTHORIZATIONS,
89+
)
90+
91+
API.add_namespace(META_API, path="/meta")
92+
API.add_namespace(CODES_API, path="/codes")
93+
API.add_namespace(PROJECTS_API, path="/projects")
94+
API.add_namespace(PROJECT_TYPES_API, path="/project-types")
95+
API.add_namespace(SYNC_FORM_DATA_API, path="/sync-form-data")
96+
API.add_namespace(PHASE_API, path="/phases")
97+
API.add_namespace(STAFF_API, path="/staffs")
98+
API.add_namespace(OUTCOME_API, path="/outcomes")
99+
API.add_namespace(SUB_TYPES_API, path="/sub-types")
100+
API.add_namespace(INSPECTION_API, path="/inspections")
101+
API.add_namespace(WORK_API, path="/works")
102+
API.add_namespace(LOOKUP_API, path="/lookups")
103+
API.add_namespace(REPORTS_API, path="/reports")
104+
API.add_namespace(INDIGENOUS_NATION_API, path="/indigenous-nations")
105+
API.add_namespace(PROPONENT_API, path="/proponents")
106+
API.add_namespace(REMINDER_CONFIGURATION_API, path="/reminder-configurations")
107+
API.add_namespace(USER_API, path='/users')
108+
API.add_namespace(TASK_TEMPLATE_API, path="/task-templates")
109+
API.add_namespace(EVENT_TEMPLATE_API, path="/event-templates")
110+
API.add_namespace(TASK_API, path="/tasks")
111+
API.add_namespace(EVENT_API, path="/milestones")
112+
API.add_namespace(EVENT_CONFIGURATION_API, path="/event-configurations")
113+
API.add_namespace(RESPONSIBILITY_API, path="/responsibilities")
114+
API.add_namespace(OUTCOME_CONFIGURATION_API, path="/outcome-configurations")
115+
API.add_namespace(ACT_SECTION_API, path="/act-sections")
116+
API.add_namespace(WORK_STATUS_API, path='/work/<int:work_id>/statuses')
117+
API.add_namespace(WORK_TYPES_API, path='/work-types')
118+
API.add_namespace(WORK_ISSUES_API, path='/work/<int:work_id>/issues')
119+
API.add_namespace(SPECIAL_FIELD_API, path='/special-fields')
120+
API.add_namespace(POSITION_API, path='/positions')
121+
API.add_namespace(REGION_API, path='/regions')
122+
API.add_namespace(EAO_TEAM_API, path='/eao-teams')
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Copyright © 2019 Province of British Columbia
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
"""Resource for work endpoints."""
15+
from http import HTTPStatus
16+
17+
from flask import jsonify
18+
from flask_restx import Namespace, Resource, cors
19+
20+
from api.services import ProjectService
21+
from api.utils import auth, constants, profiletime
22+
from api.utils.caching import AppCache
23+
from api.utils.util import cors_preflight
24+
25+
26+
API = Namespace("project types", description="Project Types")
27+
28+
29+
@cors_preflight("GET")
30+
@API.route("", methods=["GET", "OPTIONS"])
31+
class ProjectTypes(Resource):
32+
"""Endpoint resource to manage project types."""
33+
34+
@staticmethod
35+
@cors.crossdomain(origin="*")
36+
@auth.require
37+
@profiletime
38+
@AppCache.cache.cached(timeout=constants.CACHE_DAY_TIMEOUT, query_string=True)
39+
def get():
40+
"""Return all project types."""
41+
project_types = ProjectService.find_all_project_types()
42+
return (
43+
jsonify(project_types),
44+
HTTPStatus.OK,
45+
)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Copyright © 2019 Province of British Columbia
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
"""Resource for work endpoints."""
15+
from http import HTTPStatus
16+
17+
from flask import jsonify
18+
from flask_restx import Namespace, Resource, cors
19+
20+
from api.services import WorkService
21+
from api.utils import auth, constants, profiletime
22+
from api.utils.caching import AppCache
23+
from api.utils.util import cors_preflight
24+
25+
26+
API = Namespace("work-types", description="Work types")
27+
28+
29+
@cors_preflight("GET")
30+
@API.route("", methods=["GET", "OPTIONS"])
31+
class WorkTypes(Resource):
32+
"""Endpoint resource to manage works."""
33+
34+
@staticmethod
35+
@cors.crossdomain(origin="*")
36+
@auth.require
37+
@AppCache.cache.cached(timeout=constants.CACHE_DAY_TIMEOUT)
38+
@profiletime
39+
def get():
40+
"""Return all active work types."""
41+
work_types = WorkService.find_all_work_types()
42+
return jsonify(work_types), HTTPStatus.OK

epictrack-web/src/constants/api-endpoint.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ const Endpoints = {
99
},
1010
Projects: {
1111
PROJECTS: "projects",
12-
PROJECT_TYPES: "projects/types",
1312
WORK_TYPES: "projects/:project_id/work-types",
1413
FIRST_NATIONS: "projects/:project_id/first-nations",
1514
FIRST_NATION_AVAILABLE: "projects/:project_id/first-nation-available",
1615
PROJECT_ABBREVIATION: "projects/abbreviation",
1716
},
17+
ProjectTypes: {
18+
GET_ALL: "project-types",
19+
},
1820
Codes: {
1921
GET_CODES: "codes",
2022
},
@@ -39,6 +41,9 @@ const Endpoints = {
3941
WORK_IMPORT_FIRST_NATIONS: "works/:work_id/first-nations/import",
4042
GET_ALL_WORK_TYPES: "works/types",
4143
},
44+
WorkTypes: {
45+
GET_ALL: "work-types",
46+
},
4247
WorkIssues: {
4348
ISSUES: "work/:work_id/issues",
4449
UPDATE_ISSUE: "work/:work_id/issues/:issue_id",

epictrack-web/src/services/projectService/projectService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class ProjectService implements ServiceBase {
7979
}
8080

8181
async getProjectTypes() {
82-
return await http.GetRequest<ListType[]>(Endpoints.Projects.PROJECT_TYPES);
82+
return await http.GetRequest<ListType[]>(Endpoints.ProjectTypes.GET_ALL);
8383
}
8484
}
8585

epictrack-web/src/services/workService/workService.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,7 @@ class WorkService implements ServiceBase {
207207
}
208208

209209
async getWorkTypes() {
210-
return await http.GetRequest<WorkType[]>(
211-
Endpoints.Works.GET_ALL_WORK_TYPES
212-
);
210+
return await http.GetRequest<WorkType[]>(Endpoints.WorkTypes.GET_ALL);
213211
}
214212
}
215213
export default new WorkService();

0 commit comments

Comments
 (0)