Skip to content

Commit

Permalink
Removing/migrating canonical CRUD methods to the auto-generated ones.
Browse files Browse the repository at this point in the history
  • Loading branch information
buchananwill committed Apr 10, 2024
1 parent 76f0841 commit 51d17f8
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 131 deletions.
63 changes: 0 additions & 63 deletions app/api/actions/curriculum-delivery-model.ts

This file was deleted.

16 changes: 5 additions & 11 deletions app/api/actions/template-endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,8 @@ export interface BaseEndpointSet<T, ID_TYPE extends string | number> {
putOne: (dto: T) => ActionResponsePromise<T>;
postOne: (dto: T) => ActionResponsePromise<T>;
deleteOne: (id: ID_TYPE) => ActionResponsePromise<ID_TYPE>;
getDtoListByParamList: (
idList: ID_TYPE[],
url: string
) => ActionResponsePromise<T[]>;
getDtoListByBodyList: (
idList: ID_TYPE[],
url: string
) => ActionResponsePromise<T[]>;
getDtoListByParamList: (idList: ID_TYPE[]) => ActionResponsePromise<T[]>;
getDtoListByBodyList: (idList: ID_TYPE[]) => ActionResponsePromise<T[]>;
}

async function getDtoList<T>(
Expand All @@ -59,13 +53,13 @@ async function getDtoListByParamList<T, ID_TYPE extends string | number>(
url: string
): ActionResponsePromise<T[]> {
const paramString = idList.map((id) => `id=${id}`).join('&');
return getWithoutBody(`${url}/byIdList?${paramString}`);
return getWithoutBody(`${url}/listById?${paramString}`);
}
async function getDtoListByBodyList<T, ID_TYPE extends string | number>(
idList: ID_TYPE[],
url: string
): ActionResponsePromise<T[]> {
return getDtoListByIds<ID_TYPE, T>(idList, `${url}/byIdList`);
return getDtoListByIds<ID_TYPE, T>(idList, `${url}/listById`);
}

async function putDtoList<T>(
Expand Down Expand Up @@ -123,7 +117,7 @@ export function generateBaseEndpointSet<
ID_TYPE extends string | number
>(path: string | string[]): BaseEndpointSet<T, ID_TYPE> {
const generatedUrl = constructUrl(path);
console.log('generated url:', generatedUrl);

return {
getPage: (pageRequest) => getDtoList<T>(pageRequest, generatedUrl),
putList: (dtoList) => putDtoList(dtoList, generatedUrl),
Expand Down
22 changes: 22 additions & 0 deletions app/api/actions/work-project-series-schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use server';
import { ActionResponsePromise } from './actionResponse';
import { WorkProjectSeriesSchemaDto } from '../dtos/WorkProjectSeriesSchemaDtoSchema';
import { API_BASE_URL, Page } from '../main';
import { getWithoutBody } from './template-actions';

const SCHEMA_URL = `${API_BASE_URL}/workProjectSeriesSchemas`;

// TODO REMOVE/MIGRATE THIS FUNCTION
export async function getCurriculumDeliveryModelSchemasByKnowledgeLevel(
page: number = 0,
size: number = 10,
yearGroup?: number
): ActionResponsePromise<Page<WorkProjectSeriesSchemaDto>> {
let url = SCHEMA_URL;
const paging = `?page=${page}&size=${size}&sort=name,asc`;
if (!!yearGroup) {
url = `${url}/knowledge-level-ordinal/${yearGroup}`;
}
url = url + paging;
return await getWithoutBody<Page<WorkProjectSeriesSchemaDto>>(url);
}
34 changes: 2 additions & 32 deletions app/api/actions/work-series-schema-bundles.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import { WorkSeriesSchemaBundleLeanDto } from '../dtos/WorkSeriesSchemaBundleLeanDtoSchema';
import { ActionResponsePromise } from './actionResponse';
import {
deleteEntities,
getDtoListByIds,
getWithoutBody,
postEntities,
putEntities
} from './template-actions';
import { API_V2_URL, Page } from '../main';
import { getDtoListByIds } from './template-actions';
import { API_V2_URL } from '../main';

const BUNDLES_ENDPOINT = `${API_V2_URL}/workProjectSeriesSchemas/bundles`;

Expand All @@ -19,27 +13,3 @@ export async function getBundlesBySchemaIdList(

return getDtoListByIds(idList, urlForBundlesContainingSchemasInList);
}

export async function getBundles(): ActionResponsePromise<
Page<WorkSeriesSchemaBundleLeanDto>
> {
return getWithoutBody(`${BUNDLES_ENDPOINT}?page=0&size=100`);
}

export async function putBundles(
bundleList: WorkSeriesSchemaBundleLeanDto[]
): ActionResponsePromise<WorkSeriesSchemaBundleLeanDto[]> {
return putEntities(bundleList, BUNDLES_ENDPOINT);
}

export async function postBundles(
bundleList: WorkSeriesSchemaBundleLeanDto[]
): ActionResponsePromise<WorkSeriesSchemaBundleLeanDto[]> {
return postEntities(bundleList, BUNDLES_ENDPOINT);
}

export async function deleteBundles(
deleteBundleIds: number[]
): ActionResponsePromise<number[]> {
return deleteEntities(deleteBundleIds, BUNDLES_ENDPOINT);
}
8 changes: 0 additions & 8 deletions app/api/actions/work-task-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,3 @@ export async function getWorkTaskTypesByWorkProjectSeriesSchemaIdList(
url
);
}

export async function putWorkTaskTypes(
modelList: WorkTaskTypeDto[]
): ActionResponsePromise<WorkTaskTypeDto[]> {
const url = `${API_BASE_URL}/workTasks/types`;

return putEntities(modelList, url);
}
4 changes: 2 additions & 2 deletions app/curriculum/class-hierarchy/[yearGroup]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { getSchemasByIdList } from '../../../api/actions/curriculum-delivery-model';
import { Card } from '@nextui-org/card';

import ForceGraphPage from '../../../graphing/force-graph-page';
Expand All @@ -18,6 +17,7 @@ import { getOrganizationGraphByOrganizationType } from '../../../api/actions/org
import { parseTen } from '../../../api/date-and-time';
import { isNotUndefined } from '../../../api/main';
import { getPage } from '../../../api/READ-ONLY-generated-actions/WorkSeriesSchemaBundle';
import { getDtoListByBodyList } from '../../../api/READ-ONLY-generated-actions/WorkProjectSeriesSchema';

const emptyBundles = {} as StringMap<string>;

Expand All @@ -43,7 +43,7 @@ export default async function Page({
? [...new Set(schemaIdList)]
: ([] as string[]);

const allSchemasInBundles = await getSchemasByIdList(schemaIdListFromSet);
const allSchemasInBundles = await getDtoListByBodyList(schemaIdListFromSet);

const typeId = parseTen(yearGroup);
const bundleDeliveries = await getBundleAssignmentsByOrgType(typeId);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getCurriculumDeliveryModelSchemasByKnowledgeLevel } from '../../../../api/actions/curriculum-delivery-model';
import { getCurriculumDeliveryModelSchemasByKnowledgeLevel } from '../../../../api/actions/work-project-series-schema';
import { normalizeQueryParamToNumber } from '../../../../api/utils';
import { Card } from '@nextui-org/card';
import { BundleEditor } from './bundle-editor';
Expand Down
2 changes: 1 addition & 1 deletion app/curriculum/delivery-models/[yearGroup]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getCurriculumDeliveryModelSchemasByKnowledgeLevel } from '../../../api/actions/curriculum-delivery-model';
import { getCurriculumDeliveryModelSchemasByKnowledgeLevel } from '../../../api/actions/work-project-series-schema';
import { Card, Title } from '@tremor/react';
import { Pagination } from '../../../generic/components/buttons/pagination';
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { WorkProjectSeriesSchemaDto } from '../../api/dtos/WorkProjectSeriesSche
import { useSelectiveContextDispatchBoolean } from '../../selective-context/components/typed/selective-context-manager-boolean';
import { UnsavedCurriculumModelChanges } from './contexts/curriculum-models-context-provider';
import { useRouter } from 'next/navigation';
import { postModels } from '../../api/actions/curriculum-delivery-model';
import {
getStepperInterface,
StepperContext
Expand All @@ -30,6 +29,7 @@ import {
} from '../../generic/components/modals/confirm-action-modal';
import TupleSelector from '../../generic/components/dropdown/tuple-selector';
import { isNotNull } from '../../api/main';
import { postList } from '../../api/READ-ONLY-generated-actions/WorkProjectSeriesSchema';

export interface NameAccessor<T> extends AccessorFunction<T, string> {
(object: T): string;
Expand Down Expand Up @@ -116,7 +116,7 @@ export function AddNewCurriculumModelCard({
userToProviderRatio: 30
};

postModels([unsavedModel]).then((r) => {
postList([unsavedModel]).then((r) => {
if (r.data !== undefined) {
const payloadArray = getPayloadArray(r.data, (schema) => schema.id);
dispatch({ type: 'updateAll', payload: payloadArray });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ import {
CurriculumModelsContext,
CurriculumModelsContextDispatch
} from './use-curriculum-model-context';

import {
deleteCurriculumDeliveryModels,
putModels
} from '../../../api/actions/curriculum-delivery-model';
import { useSelectiveContextControllerBoolean } from '../../../selective-context/components/typed/selective-context-manager-boolean';
import { ExclamationTriangleIcon } from '@heroicons/react/20/solid';

Expand All @@ -24,6 +19,10 @@ import {
ConfirmActionModal,
useModal
} from '../../../generic/components/modals/confirm-action-modal';
import {
deleteIdList,
putList
} from '../../../api/READ-ONLY-generated-actions/WorkProjectSeriesSchema';

export const UnsavedCurriculumModelChanges = 'unsaved-model-changes';
export const DeletedCurriculumModelIdsKey = 'deleted-curriculum-model-id-list';
Expand Down Expand Up @@ -70,7 +69,7 @@ export function CurriculumModelsContextProvider({
};

if (deletedModelsIdList.length > 0) {
deleteCurriculumDeliveryModels(deletedModelsIdList)
deleteIdList(deletedModelsIdList)
.then((r) => {
if (r.status == 200) {
dispatchDeletedModelIdList({
Expand All @@ -85,7 +84,7 @@ export function CurriculumModelsContextProvider({
.finally(clearFlag);
}
const workProjectSeriesSchemaDtosCurrent = Object.values(currentModels);
putModels(workProjectSeriesSchemaDtosCurrent)
putList(workProjectSeriesSchemaDtosCurrent)
.then((r) => {
if (r.data) {
const schemas = getPayloadArray(r.data, (schema) => schema.id);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
'use client';
import {
StringMap,
StringMapReducer,
useStringMapReducer
StringMapReducer
} from '../../../contexts/string-map-context/string-map-reducer';
import React, { PropsWithChildren, useReducer } from 'react';
import { useSelectiveContextControllerBoolean } from '../../../selective-context/components/typed/selective-context-manager-boolean';
Expand All @@ -11,12 +10,12 @@ import {
WorkTaskTypeContextDispatch
} from './use-work-task-type-context';
import { WorkTaskTypeDto } from '../../../api/dtos/WorkTaskTypeDtoSchema';
import { putWorkTaskTypes } from '../../../api/actions/work-task-types';

import { getPayloadArray } from '../use-editing-context-dependency';
import { UnsavedChangesModal } from '../../../generic/components/modals/unsaved-changes-modal';
import { useSyncStringMapToProps } from '../../../contexts/string-map-context/use-sync-string-map-to-props';
import { IdStringFromNumberAccessor } from '../../../premises/classroom-suitability/rating-table-accessor-functions';
import { putList } from '../../../api/READ-ONLY-generated-actions/WorkTaskType';

export const UnsavedWorkTaskTypeChanges = 'unsaved-workTaskType-changes';
export const WorkTaskTypeChangesProviderListener =
Expand Down Expand Up @@ -61,7 +60,7 @@ export function WorkTaskTypeContextProvider({
const workTaskTypeDtos = Object.values(
currentModels as StringMap<WorkTaskTypeDto>
);
putWorkTaskTypes(workTaskTypeDtos).then((r) => {
putList(workTaskTypeDtos).then((r) => {
if (r.data) {
const schemas = getPayloadArray(r.data, (r) => r.id.toString());
dispatch({ type: 'updateAll', payload: schemas });
Expand Down

0 comments on commit 51d17f8

Please sign in to comment.