From 9bba91ca590c0e0036a3c36d607f509c9dc05180 Mon Sep 17 00:00:00 2001 From: Matthew Richards Date: Wed, 10 Jun 2020 11:17:57 +0000 Subject: [PATCH] Remove unused users investigation endpoints - Removing /users/{id}/investigations and /users/{id}/investigations/count - These endpoints are being removed because equivalent behaviour can be achieved by the respective endpoints in /investigations by using WHERE and INCLUDE filters --- common/database_helpers.py | 46 ---------- src/main.py | 10 +-- .../table_endpoints/table_endpoints.py | 85 +------------------ 3 files changed, 3 insertions(+), 138 deletions(-) diff --git a/common/database_helpers.py b/common/database_helpers.py index d942b1f7..af754685 100644 --- a/common/database_helpers.py +++ b/common/database_helpers.py @@ -508,52 +508,6 @@ def patch_entities(table, json_list): return results -class UserInvestigationsQuery(ReadQuery): - """ - The query class used for the /users/<:id>/investigations endpoint - """ - - def __init__(self, user_id): - super().__init__(INVESTIGATION) - self.base_query = self.base_query.join(INVESTIGATIONUSER).filter(INVESTIGATIONUSER.USER_ID == user_id) - - -def get_investigations_for_user(user_id, filters): - """ - Given a user id and a list of filters, return a filtered list of all investigations that belong to that user - :param user_id: The id of the user - :param filters: The list of filters - :return: A list of dictionary representations of the investigation entities - """ - with UserInvestigationsQuery(user_id) as query: - filter_handler = FilterOrderHandler() - return get_filtered_read_query_results(filter_handler, filters, query) - - -class UserInvestigationsCountQuery(CountQuery): - """ - The query class used for /users/<:id>/investigations/count - """ - - def __init__(self, user_id): - super().__init__(INVESTIGATION) - self.base_query = self.base_query.join(INVESTIGATIONUSER).filter(INVESTIGATIONUSER.USER_ID == user_id) - - -def get_investigations_for_user_count(user_id, filters): - """ - Given a user id and a list of filters, return the count of all investigations that belong to that user - :param user_id: The id of the user - :param filters: The list of filters - :return: The count - """ - with UserInvestigationsCountQuery(user_id) as count_query: - filter_handler = FilterOrderHandler() - filter_handler.add_filters(filters) - filter_handler.apply_filters(count_query) - return count_query.get_count() - - class InstrumentFacilityCyclesQuery(ReadQuery): def __init__(self, instrument_id): super().__init__(FACILITYCYCLE) diff --git a/src/main.py b/src/main.py index bbb952ca..3a9df028 100644 --- a/src/main.py +++ b/src/main.py @@ -9,9 +9,8 @@ get_find_one_endpoint from src.resources.entities.entity_map import endpoints from src.resources.non_entities.sessions_endpoints import * -from src.resources.table_endpoints.table_endpoints import UsersInvestigations, UsersInvestigationsCount, \ - InstrumentsFacilityCycles, InstrumentsFacilityCyclesCount, InstrumentsFacilityCyclesInvestigations, \ - InstrumentsFacilityCyclesInvestigationsCount +from src.resources.table_endpoints.table_endpoints import InstrumentsFacilityCycles, InstrumentsFacilityCyclesCount, \ + InstrumentsFacilityCyclesInvestigations, InstrumentsFacilityCyclesInvestigationsCount from apispec import APISpec from pathlib import Path @@ -71,11 +70,6 @@ spec.path(resource=Sessions, api=api) # Table specific endpoints -api.add_resource(UsersInvestigations, "/users//investigations") -spec.path(resource=UsersInvestigations, api=api) -api.add_resource(UsersInvestigationsCount, - "/users//investigations/count") -spec.path(resource=UsersInvestigationsCount, api=api) api.add_resource(InstrumentsFacilityCycles, "/instruments//facilitycycles") spec.path(resource=InstrumentsFacilityCycles, api=api) diff --git a/src/resources/table_endpoints/table_endpoints.py b/src/resources/table_endpoints/table_endpoints.py index f8ed027e..8b6132ca 100644 --- a/src/resources/table_endpoints/table_endpoints.py +++ b/src/resources/table_endpoints/table_endpoints.py @@ -1,93 +1,10 @@ from flask_restful import Resource -from common.database_helpers import get_investigations_for_user, get_investigations_for_user_count, \ - get_facility_cycles_for_instrument, get_facility_cycles_for_instrument_count, \ +from common.database_helpers import get_facility_cycles_for_instrument, get_facility_cycles_for_instrument_count, \ get_investigations_for_instrument_in_facility_cycle, get_investigations_for_instrument_in_facility_cycle_count from common.helpers import requires_session_id, queries_records, get_filters_from_query_string -class UsersInvestigations(Resource): - @requires_session_id - @queries_records - def get(self, id): - """ - --- - summary: Get a user's Investigations - description: Retrieve the investigations that a user of a given ID is an InvestigationUser on, subject to filters. - tags: - - Investigations - parameters: - - in: path - required: true - name: ID - description: The id of the user to retrieve the investigations of - schema: - type: integer - - WHERE_FILTER - - ORDER_FILTER - - LIMIT_FILTER - - SKIP_FILTER - - DISTINCT_FILTER - - INCLUDE_FILTER - responses: - 200: - description: Success - returns a list of the user's investigations that satisfy the filters - content: - application/json: - schema: - type: array - items: - $ref: '#/components/schemas/INVESTIGATION' - 400: - description: Bad request - Something was wrong with the request - 401: - description: Unauthorized - No session ID was found in the HTTP Authorization header - 403: - description: Forbidden - The session ID provided is invalid - 404: - description: No such record - Unable to find a record in the database - """ - return get_investigations_for_user(id, get_filters_from_query_string()), 200 - - -class UsersInvestigationsCount(Resource): - @requires_session_id - @queries_records - def get(self, id): - """ - --- - summary: Count a user's Investigations - description: Return the count of the Investigations that belong to a given user that would be retrieved given the filters provided - tags: - - Investigations - parameters: - - in: path - required: true - name: ID - description: The id of the user to count the investigations of - schema: - type: integer - - WHERE_FILTER - - DISTINCT_FILTER - responses: - 200: - description: Success - The count of the user's investigations that satisfy the filters - content: - application/json: - schema: - type: integer - 400: - description: Bad request - Something was wrong with the request - 401: - description: Unauthorized - No session ID was found in the HTTP Authorization header - 403: - description: Forbidden - The session ID provided is invalid - 404: - description: No such record - Unable to find a record in the database - """ - return get_investigations_for_user_count(id, get_filters_from_query_string()), 200 - - class InstrumentsFacilityCycles(Resource): @requires_session_id @queries_records