-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created a standardized endpoint generator for the front end. Need to …
…add singleton operations, types, intersections, collections and graphs.
- Loading branch information
1 parent
0d16358
commit eb53b76
Showing
22 changed files
with
333 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
'use server'; | ||
import { generateBaseEndpointSet } from './template-endpoints'; | ||
import { CarouselDto } from '../dtos/CarouselDtoSchema'; | ||
|
||
export const { getPage, deleteIdList, postList, putList } = | ||
generateBaseEndpointSet<CarouselDto, string>(['carouselGroups', 'carousels']); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
'use server'; | ||
import { ActionResponsePromise } from './actionResponse'; | ||
import { GraphDto, GraphDtoPutRequestBody } from '../zod-mods'; | ||
import { OrganizationDto } from '../dtos/OrganizationDtoSchema'; | ||
import { | ||
getWithoutBody, | ||
putRequestWithDifferentReturnType | ||
} from './template-actions'; | ||
import { API_BASE_URL } from '../main'; | ||
import { OrganizationTypeDto } from '../dtos/OrganizationTypeDtoSchema'; | ||
|
||
const organizationGraphEndpoint = `${API_BASE_URL}/v2/organizations/graphs`; | ||
|
||
export async function getOrganizationGraph(): ActionResponsePromise< | ||
GraphDto<OrganizationDto> | ||
> { | ||
return getWithoutBody(organizationGraphEndpoint); | ||
} | ||
|
||
export async function getOrganizationGraphByRootId( | ||
rootId: number | ||
): ActionResponsePromise<GraphDto<OrganizationDto>> { | ||
return getWithoutBody(`${organizationGraphEndpoint}/byRootId/${rootId}`); | ||
} | ||
|
||
export async function getOrganizationGraphByOrganizationType(typeId: number) { | ||
return getWithoutBody<GraphDto<OrganizationDto>>( | ||
`${organizationGraphEndpoint}/byOrganizationType/${typeId}` | ||
); | ||
} | ||
|
||
export async function getOrganizationTypes(): ActionResponsePromise< | ||
GraphDto<OrganizationTypeDto> | ||
> { | ||
const url = `${API_BASE_URL}/v2/organizations/types/graphs/byRootId/6?depth=0&depthOp=%3E | ||
`; | ||
return getWithoutBody(url); | ||
} | ||
|
||
export async function putOrganizationGraph( | ||
requestBody: GraphDtoPutRequestBody<OrganizationDto> | ||
): ActionResponsePromise<GraphDto<OrganizationDto>> { | ||
return putRequestWithDifferentReturnType< | ||
GraphDtoPutRequestBody<OrganizationDto>, | ||
GraphDto<OrganizationDto> | ||
>(requestBody, organizationGraphEndpoint); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { ActionResponsePromise } from './actionResponse'; | ||
import { | ||
deleteEntities, | ||
getWithoutBody, | ||
postEntities, | ||
putEntities | ||
} from './template-actions'; | ||
import { API_V2_URL, isNotUndefined, Page } from '../main'; | ||
|
||
function constructUrl(resourceSegments: string[], action?: string) { | ||
const basePath = API_V2_URL; | ||
const resourcePath = resourceSegments.join('/'); | ||
return `${basePath}/${resourcePath}${ | ||
isNotUndefined(action) ? `/${action}` : '' | ||
}`; | ||
} | ||
|
||
export interface PageRequest { | ||
page?: number; | ||
pageSize?: number; | ||
sort?: string; | ||
} | ||
|
||
export interface BaseEndpointSet<T, ID_TYPE> { | ||
getPage: (pageRequest: PageRequest) => ActionResponsePromise<Page<T>>; | ||
putList: (dtoList: T[]) => ActionResponsePromise<T[]>; | ||
postList: (dtoList: T[]) => ActionResponsePromise<T[]>; | ||
deleteIdList: (idDeletionList: ID_TYPE[]) => ActionResponsePromise<ID_TYPE[]>; | ||
} | ||
|
||
async function getDtoList<T>( | ||
{ page = 0, pageSize = 10 }: PageRequest, | ||
url: string | ||
): ActionResponsePromise<Page<T>> { | ||
return getWithoutBody(`${url}?page=${page}&size=${pageSize}`); | ||
} | ||
|
||
async function putDtoList<T>( | ||
dtoList: T[], | ||
url: string | ||
): ActionResponsePromise<T[]> { | ||
return putEntities(dtoList, url); | ||
} | ||
|
||
async function postDtoList<T>( | ||
dtoList: T[], | ||
url: string | ||
): ActionResponsePromise<T[]> { | ||
return postEntities(dtoList, url); | ||
} | ||
|
||
async function deleteDtoList<ID_TYPE>( | ||
deletionIdList: ID_TYPE[], | ||
url: string | ||
): ActionResponsePromise<ID_TYPE[]> { | ||
return deleteEntities(deletionIdList, url); | ||
} | ||
|
||
export function generateBaseEndpointSet<T, ID_TYPE>( | ||
resourceSegments: string[] | ||
): BaseEndpointSet<T, ID_TYPE> { | ||
const generatedUrl = constructUrl(resourceSegments); | ||
return { | ||
getPage: (pageRequest) => getDtoList<T>(pageRequest, generatedUrl), | ||
putList: (dtoList) => putDtoList(dtoList, generatedUrl), | ||
postList: (dtoList) => postDtoList(dtoList, generatedUrl), | ||
deleteIdList: (idDeletionList) => | ||
deleteDtoList<ID_TYPE>(idDeletionList, generatedUrl) | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
'use server'; | ||
import { ActionResponsePromise } from './actionResponse'; | ||
import { WorkSeriesBundleAssignmentDto } from '../dtos/WorkSeriesBundleAssignmentDtoSchema'; | ||
import { | ||
getWithoutBody, | ||
postEntitiesWithDifferentReturnType | ||
} from './template-actions'; | ||
import { API_V2_URL } from '../main'; | ||
import { LongLongTuple } from '../dtos/LongLongTupleSchema'; | ||
|
||
const ASSIGNMENTS_ENDPOINT = `${API_V2_URL}/workProjectSeriesSchemas/bundleAssignments`; | ||
|
||
export async function getBundleAssignmentsByOrgType( | ||
orgType: number | ||
): ActionResponsePromise<WorkSeriesBundleAssignmentDto[]> { | ||
const url = `${ASSIGNMENTS_ENDPOINT}/byOrganizationType/${orgType}`; | ||
console.log(url); | ||
return await getWithoutBody<WorkSeriesBundleAssignmentDto[]>(url); | ||
} | ||
|
||
export async function postBundleDeliveries( | ||
bundleAssignments: LongLongTuple[] | ||
): ActionResponsePromise<WorkSeriesBundleAssignmentDto[]> { | ||
const bundlePostUrl = `${ASSIGNMENTS_ENDPOINT}/byLongLongTupleList`; | ||
return postEntitiesWithDifferentReturnType< | ||
LongLongTuple[], | ||
WorkSeriesBundleAssignmentDto[] | ||
>(bundleAssignments, bundlePostUrl); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
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'; | ||
|
||
const BUNDLES_ENDPOINT = `${API_V2_URL}/workProjectSeriesSchemas/bundles`; | ||
|
||
export async function getBundlesBySchemaIdList( | ||
idList: string[] | ||
): ActionResponsePromise<WorkSeriesSchemaBundleLeanDto[]> { | ||
const urlForBundlesContainingSchemasInList = `${BUNDLES_ENDPOINT}/withItemSchemaIdInList`; | ||
console.log(urlForBundlesContainingSchemasInList); | ||
|
||
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
import { CarouselOptionDtoSchema } from './CarouselOptionDtoSchema'; | ||
import { z } from 'zod'; | ||
export const CarouselDtoSchema = z.object({ | ||
id: z.string().uuid(), | ||
name: z.string(), | ||
workProjectSeriesSchemaId: z.string().uuid(), | ||
workProjectSeriesSchemaName: z.string(), | ||
workProjectSeriesSchemaShortCode: z.string(), | ||
carouselOrdinal: z.number(), | ||
carouselGroupId: z.string().uuid(), | ||
carouselOptions: z.array(CarouselOptionDtoSchema), | ||
}); | ||
export type CarouselDto = z.infer<typeof CarouselDtoSchema>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { z } from 'zod'; | ||
export const CarouselOrderItemDtoSchema = z.object({ | ||
id: z.number(), | ||
carouselOrderId: z.string().uuid(), | ||
workProjectSeriesSchemaId: z.string().uuid(), | ||
preferencePosition: z.number(), | ||
active: z.boolean(), | ||
carouselOptionId: z.number(), | ||
}); | ||
export type CarouselOrderItemDto = z.infer<typeof CarouselOrderItemDtoSchema>; |
Oops, something went wrong.