From 9e403386a6f594e9731d1c6160a1da4fb027c2c1 Mon Sep 17 00:00:00 2001 From: 1AhmedYasser <26207361+1AhmedYasser@users.noreply.github.com> Date: Thu, 12 Feb 2026 01:04:48 +0200 Subject: [PATCH] chore(913): added sorting/pagination/search to common endpoints --- .../POST/endpoints/get_common_endpoints.sql | 13 ++++- .../endpoints/get_endpoints_by_service_id.sql | 3 +- DSL/Ruuter/services/GET/endpoints/common.yml | 17 ------- DSL/Ruuter/services/POST/endpoints/common.yml | 48 +++++++++++++++++++ .../services/{GET => POST}/service-by-id.yml | 27 +++++------ GUI/src/pages/ServiceFlowPage.tsx | 8 +++- GUI/src/resources/api-constants.ts | 2 +- GUI/src/store/new-services.store.ts | 30 +++++++++--- 8 files changed, 106 insertions(+), 42 deletions(-) delete mode 100644 DSL/Ruuter/services/GET/endpoints/common.yml create mode 100644 DSL/Ruuter/services/POST/endpoints/common.yml rename DSL/Ruuter/services/{GET => POST}/service-by-id.yml (84%) diff --git a/DSL/Resql/services/POST/endpoints/get_common_endpoints.sql b/DSL/Resql/services/POST/endpoints/get_common_endpoints.sql index 64e49de8d..08868644b 100644 --- a/DSL/Resql/services/POST/endpoints/get_common_endpoints.sql +++ b/DSL/Resql/services/POST/endpoints/get_common_endpoints.sql @@ -3,8 +3,17 @@ SELECT name, type, is_common, - definitions + definitions, + CASE WHEN :pagination THEN CEIL(COUNT(*) OVER() / :page_size::DECIMAL) ELSE 1 END AS total_pages FROM endpoints WHERE is_common = true AND deleted IS FALSE -ORDER BY id DESC; + AND (:search IS NULL OR :search = '' OR LOWER(name) LIKE LOWER('%' || :search || '%')) +ORDER BY + CASE WHEN :sorting = 'created_at asc' THEN created_at END ASC NULLS LAST, + CASE WHEN :sorting = 'created_at desc' THEN created_at END DESC NULLS LAST, + CASE WHEN :sorting = 'name asc' THEN name END ASC NULLS LAST, + CASE WHEN :sorting = 'name desc' THEN name END DESC NULLS LAST, + created_at DESC +OFFSET (CASE WHEN :pagination THEN (GREATEST(:page, 1) - 1) * :page_size ELSE 0 END) +LIMIT (CASE WHEN :pagination THEN :page_size END); diff --git a/DSL/Resql/services/POST/endpoints/get_endpoints_by_service_id.sql b/DSL/Resql/services/POST/endpoints/get_endpoints_by_service_id.sql index 71e93c211..233a1cd63 100644 --- a/DSL/Resql/services/POST/endpoints/get_endpoints_by_service_id.sql +++ b/DSL/Resql/services/POST/endpoints/get_endpoints_by_service_id.sql @@ -15,6 +15,7 @@ FROM endpoints AS e CROSS JOIN UserPreferences AS up WHERE (e.service_id = :id::uuid OR e.is_common = true) AND e.deleted IS FALSE + AND (:search IS NULL OR :search = '' OR LOWER(e.name) LIKE LOWER('%' || :search || '%')) ORDER BY CASE WHEN up.endpoints IS NULL OR array_length(up.endpoints, 1) = 0 THEN 1 @@ -23,4 +24,4 @@ ORDER BY CASE WHEN up.endpoints IS NULL OR array_length(up.endpoints, 1) = 0 THEN e.id ELSE NULL - END DESC; \ No newline at end of file + END DESC; diff --git a/DSL/Ruuter/services/GET/endpoints/common.yml b/DSL/Ruuter/services/GET/endpoints/common.yml deleted file mode 100644 index 803bf1e9f..000000000 --- a/DSL/Ruuter/services/GET/endpoints/common.yml +++ /dev/null @@ -1,17 +0,0 @@ -declaration: - call: declare - version: 0.1 - description: "Decription placeholder for 'Common'" - method: get - accepts: json - returns: json - namespace: service - -get_common_endpoints: - call: http.post - args: - url: "[#SERVICE_RESQL]/endpoints/get_common_endpoints" - result: res - -return_result: - return: ${res.response.body} diff --git a/DSL/Ruuter/services/POST/endpoints/common.yml b/DSL/Ruuter/services/POST/endpoints/common.yml new file mode 100644 index 000000000..611faca72 --- /dev/null +++ b/DSL/Ruuter/services/POST/endpoints/common.yml @@ -0,0 +1,48 @@ +declaration: + call: declare + version: 0.1 + description: "Decription placeholder for 'Common'" + method: post + accepts: json + returns: json + namespace: service + allowlist: + body: + - field: pagination + type: string + description: "Body field 'pagination'" + - field: page + type: string + description: "Body field 'page'" + - field: pageSize + type: string + description: "Body field 'pageSize'" + - field: sorting + type: string + description: "Body field 'sorting'" + - field: search + type: string + description: "Body field 'search'" + +extract_request_data: + assign: + pagination: ${incoming.body.pagination} + page: ${incoming.body.page} + pageSize: ${incoming.body.pageSize} + sorting: ${incoming.body.sorting} + search: ${incoming.body.search} + +get_common_endpoints: + call: http.post + args: + url: "[#SERVICE_RESQL]/endpoints/get_common_endpoints" + body: + pagination: ${pagination} + page: ${page} + page_size: ${pageSize} + sorting: ${sorting} + search: ${search} + result: res + +return_result: + return: ${res.response.body} diff --git a/DSL/Ruuter/services/GET/service-by-id.yml b/DSL/Ruuter/services/POST/service-by-id.yml similarity index 84% rename from DSL/Ruuter/services/GET/service-by-id.yml rename to DSL/Ruuter/services/POST/service-by-id.yml index 3f5e232f0..45fd1b03a 100644 --- a/DSL/Ruuter/services/GET/service-by-id.yml +++ b/DSL/Ruuter/services/POST/service-by-id.yml @@ -2,7 +2,7 @@ declaration: call: declare version: 0.1 description: "Decription placeholder for 'SERVICE-BY-ID'" - method: get + method: post accepts: json returns: json namespace: service @@ -11,15 +11,18 @@ declaration: - field: cookie type: string description: "Cookie field" - params: + body: - field: id type: string - description: "Parameter 'id'" + description: "Body field 'id'" + - field: search + type: string + description: "Body field 'search'" -check_for_parameters: - switch: - - condition: ${incoming.params == null || incoming.params.id == null} - next: return_incorrect_request +extract_request_data: + assign: + id: ${incoming.body.id} + search: ${incoming.body.search} get_user_info: call: http.post @@ -46,7 +49,7 @@ get_service_by_id: args: url: "[#SERVICE_RESQL]/get-service-by-id" body: - id: ${incoming.params.id} + id: ${id} result: service_results get_endpoints_by_service_id: @@ -54,8 +57,9 @@ get_endpoints_by_service_id: args: url: "[#SERVICE_RESQL]/endpoints/get_endpoints_by_service_id" body: - id: ${incoming.params.id} + id: ${id} user_id_code: ${idCode} + search: ${search} result: endpoints_results prepare_results: @@ -80,11 +84,6 @@ return_ok: return: ${results} next: end -return_incorrect_request: - status: 400 - return: "Required parameter(s) missing" - next: end - return_unauthorized: status: 401 return: "unauthorized" diff --git a/GUI/src/pages/ServiceFlowPage.tsx b/GUI/src/pages/ServiceFlowPage.tsx index 5a5bba46e..33bd1f77b 100644 --- a/GUI/src/pages/ServiceFlowPage.tsx +++ b/GUI/src/pages/ServiceFlowPage.tsx @@ -29,7 +29,13 @@ const ServiceFlowPage: FC = () => { if (!id) { await Promise.all([ useServiceStore.getState().loadStepPreferences(), - useServiceStore.getState().loadCommonEndpoints(), + useServiceStore.getState().loadCommonEndpoints( + false, + 1, + 10, + 'created_at asc', + '', // To be added: search functionality in common endpoints + ), ]); return; } diff --git a/GUI/src/resources/api-constants.ts b/GUI/src/resources/api-constants.ts index c422de06c..c20a767c2 100644 --- a/GUI/src/resources/api-constants.ts +++ b/GUI/src/resources/api-constants.ts @@ -23,7 +23,7 @@ export const getAvailableIntents = (): string => `${baseUrl}/services/available- export const jsonToYml = (): string => `${baseUrl}/saveJsonToYml`; export const getFaultyServices = (page: number, pageSize: number, sort: string, order: string): string => `${baseUrl}/services/services-detailed/nok?page=${page}&page_size=${pageSize}&sort=${sort}&order=${order}`; -export const getServiceById = (id: string): string => `${baseUrl}/service-by-id?id=${id}`; +export const getServiceById = (): string => `${baseUrl}/service-by-id`; export const createEndpoint = (): string => `${baseUrl}/services/create-endpoint`; export const updateEndpoint = (id: string): string => `${baseUrl}/services/update-endpoint?id=${id}`; export const deleteEndpoint = (): string => `${baseUrl}/services/delete-endpoint`; diff --git a/GUI/src/store/new-services.store.ts b/GUI/src/store/new-services.store.ts index 3e6f3c82c..ae4e16cc3 100644 --- a/GUI/src/store/new-services.store.ts +++ b/GUI/src/store/new-services.store.ts @@ -100,8 +100,14 @@ export interface ServiceStoreState { editEndpoint: (endpoint?: EndpointData) => void; loadSecretVariables: () => Promise; loadTaraVariables: () => Promise; - loadService: (id?: string, resetState?: boolean) => Promise | undefined>; - loadCommonEndpoints: () => Promise; + loadService: (id?: string, resetState?: boolean, search?: string) => Promise | undefined>; + loadCommonEndpoints: ( + isPagination: boolean, + page?: number, + pageSize?: number, + sorting?: string, + search?: string, + ) => Promise; loadStepPreferences: () => Promise; getAvailableRequestValues: (endpoint: EndpointData) => PreDefinedEndpointEnvVariables; onNameChange: (endpointId: string, oldName: string, newName: string) => void; @@ -408,7 +414,7 @@ const useServiceStore = create((set, get) => ({ }, resetAssign: () => set({ assignElements: [] }), resetRules: () => set({ rules: [], isYesNoQuestion: false }), - loadService: async (id, resetState) => { + loadService: async (id, resetState, search) => { if (resetState === true) { get().resetState(); } @@ -416,7 +422,7 @@ const useServiceStore = create((set, get) => ({ let serviceResponse: AxiosResponse | undefined; if (id) { - serviceResponse = await api.get(getServiceById(id)); + serviceResponse = await api.post(getServiceById(), { id, search: search ?? '' }); const structure = JSON.parse(serviceResponse.data.structure?.value ?? '{}'); let endpoints = serviceResponse.data.endpoints.map((endpoint) => { @@ -487,8 +493,20 @@ const useServiceStore = create((set, get) => ({ get().addProductionVariables(variables); return serviceResponse; }, - loadCommonEndpoints: async () => { - const response = await api.get(getCommonEndpoints()); + loadCommonEndpoints: async ( + isPagination: boolean, + page?: number, + pageSize?: number, + sorting?: string, + search?: string, + ) => { + const response = await api.post(getCommonEndpoints(), { + pagination: isPagination, + page, + pageSize, + sorting, + search, + }); const endpointsResponse: Array< Pick & { definitions: EndpointDefinitionJson;