Skip to content

Commit

Permalink
Update to latest openAPI spec from DPL-CMS
Browse files Browse the repository at this point in the history
  • Loading branch information
kasperbirch1 committed Mar 25, 2024
1 parent e8ee476 commit 8c0bb1a
Show file tree
Hide file tree
Showing 26 changed files with 599 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
"response" : {
"status" : 200,
"body" : "[\n {\n \"category\": {\n \"title\": \"Open\"\n },\n \"date\": \"2024-03-22\",\n \"start_time\": \"09:00\",\n \"end_time\": \"17:00\"\n },\n {\n \"category\": {\n \"title\": \"Open\"\n },\n \"date\": \"2024-03-23\",\n \"start_time\": \"09:00\",\n \"end_time\": \"17:00\"\n }\n]",
"body" : "[\n {\n \"id\": 0,\n \"category\": {\n \"title\": \"Open\",\n \"color\": \"#ff0099\"\n },\n \"date\": \"2024-03-26\",\n \"start_time\": \"09:00\",\n \"end_time\": \"17:00\",\n \"branch_id\": 1\n}, {\n \"id\": 1,\n \"category\": {\n \"title\": \"Open\",\n \"color\": \"#ff0099\"\n },\n \"date\": \"2024-03-27\",\n \"start_time\": \"09:00\",\n \"end_time\": \"17:00\",\n \"branch_id\": 1\n}\n]",
"headers" : { }
},
"uuid" : "479e26d6-5197-4d8f-a2dd-fefe64aabc14",
Expand Down
2 changes: 1 addition & 1 deletion orval.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export default defineConfig({
},
input: {
target:
"https://raw.githubusercontent.com/danskernesdigitalebibliotek/dpl-cms/e1edb7e35beacb93e78eef0541c8ccebad68d6f1/openapi.json",
"https://raw.githubusercontent.com/danskernesdigitalebibliotek/dpl-cms/opening-hours-api/openapi.json",
converterOptions: {
indent: 2
}
Expand Down
11 changes: 5 additions & 6 deletions src/apps/opening-hours-editor/helper.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { EventInput } from "@fullcalendar/core";
import { DplOpeningHoursListGET200Item } from "../../core/dpl-cms/model";

const formatDateTimeString = (date: string, time: string): string => {
Expand All @@ -10,16 +11,14 @@ export const createCmsEventId = (title: string, startDay: Date) => {

export const formatCmsEventsToFullCalendar = (
data: DplOpeningHoursListGET200Item[]
) => {
return data.map(({ category, date, start_time, end_time }) => {
const startDateTime = new Date(formatDateTimeString(date, start_time));
): EventInput[] => {
return data.map(({ category, date, start_time, end_time, id }) => {
return {
id: createCmsEventId(category.title, startDateTime),
id: id.toString(),
title: category.title,
start: formatDateTimeString(date, start_time),
end: formatDateTimeString(date, end_time),
allDay: false,
color: "blue"
color: category.color
};
});
};
Expand Down
287 changes: 285 additions & 2 deletions src/core/dpl-cms/dpl-cms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ import type {
CampaignMatchPOST200,
CampaignMatchPOSTBodyItem,
CampaignMatchPOSTParams,
DplOpeningHoursGET200,
DplOpeningHoursGETOpeningHoursInstanceBody,
DplOpeningHoursGETParams,
DplOpeningHoursDELETE200,
DplOpeningHoursDELETEParams,
DplOpeningHoursPATCH200,
DplOpeningHoursPATCHParams,
DplOpeningHoursPOST200,
DplOpeningHoursPOSTParams,
DplOpeningHoursListGET200Item,
DplOpeningHoursListGETParams,
EventPATCHBody,
Expand All @@ -35,7 +44,7 @@ type AwaitedInput<T> = PromiseLike<T> | T;
type Awaited<O> = O extends AwaitedInput<infer T> ? T : never;

/**
* @summary Hent kampagne som matcher facetter fra søgeresultatet
* @summary Get campaign matching search result facets
*/
export const campaignMatchPOST = (
campaignMatchPOSTBodyItem: CampaignMatchPOSTBodyItem[],
Expand Down Expand Up @@ -97,6 +106,280 @@ export const useCampaignMatchPOST = <
>(mutationFn, mutationOptions);
};

/**
* @summary Manage individual opening hours
*/
export const dplOpeningHoursGET = (
id: string,
dplOpeningHoursGETOpeningHoursInstanceBody: BodyType<DplOpeningHoursGETOpeningHoursInstanceBody>,
params?: DplOpeningHoursGETParams,
signal?: AbortSignal
) => {
return fetcher<DplOpeningHoursGET200 | void>({
url: `/dpl_opening_hours/${id}`,
method: "get",
signal,
headers: { "Content-Type": "application/json" },
params
});
};

export const getDplOpeningHoursGETQueryKey = (
id: string,
dplOpeningHoursGETOpeningHoursInstanceBody: DplOpeningHoursGETOpeningHoursInstanceBody,
params?: DplOpeningHoursGETParams
) => [
`/dpl_opening_hours/${id}`,
...(params ? [params] : []),
dplOpeningHoursGETOpeningHoursInstanceBody
];

export type DplOpeningHoursGETQueryResult = NonNullable<
Awaited<ReturnType<typeof dplOpeningHoursGET>>
>;
export type DplOpeningHoursGETQueryError = ErrorType<unknown>;

export const useDplOpeningHoursGET = <
TData = Awaited<ReturnType<typeof dplOpeningHoursGET>>,
TError = ErrorType<unknown>
>(
id: string,
dplOpeningHoursGETOpeningHoursInstanceBody: DplOpeningHoursGETOpeningHoursInstanceBody,
params?: DplOpeningHoursGETParams,
options?: {
query?: UseQueryOptions<
Awaited<ReturnType<typeof dplOpeningHoursGET>>,
TError,
TData
>;
}
): UseQueryResult<TData, TError> & { queryKey: QueryKey } => {
const { query: queryOptions } = options ?? {};

const queryKey =
queryOptions?.queryKey ??
getDplOpeningHoursGETQueryKey(
id,
dplOpeningHoursGETOpeningHoursInstanceBody,
params
);

const queryFn: QueryFunction<
Awaited<ReturnType<typeof dplOpeningHoursGET>>
> = ({ signal }) =>
dplOpeningHoursGET(
id,
dplOpeningHoursGETOpeningHoursInstanceBody,
params,
signal
);

const query = useQuery<
Awaited<ReturnType<typeof dplOpeningHoursGET>>,
TError,
TData
>(queryKey, queryFn, { enabled: !!id, ...queryOptions });

return {
queryKey,
...query
};
};

/**
* @summary Manage individual opening hours
*/
export const dplOpeningHoursDELETE = (
id: string,
dplOpeningHoursGETOpeningHoursInstanceBody: BodyType<DplOpeningHoursGETOpeningHoursInstanceBody>,
params?: DplOpeningHoursDELETEParams
) => {
return fetcher<DplOpeningHoursDELETE200 | void>({
url: `/dpl_opening_hours/${id}`,
method: "delete",
headers: { "Content-Type": "application/json" },
data: dplOpeningHoursGETOpeningHoursInstanceBody,
params
});
};

export type DplOpeningHoursDELETEMutationResult = NonNullable<
Awaited<ReturnType<typeof dplOpeningHoursDELETE>>
>;
export type DplOpeningHoursDELETEMutationBody =
BodyType<DplOpeningHoursGETOpeningHoursInstanceBody>;
export type DplOpeningHoursDELETEMutationError = ErrorType<unknown>;

export const useDplOpeningHoursDELETE = <
TError = ErrorType<unknown>,
TContext = unknown
>(options?: {
mutation?: UseMutationOptions<
Awaited<ReturnType<typeof dplOpeningHoursDELETE>>,
TError,
{
id: string;
data: BodyType<DplOpeningHoursGETOpeningHoursInstanceBody>;
params?: DplOpeningHoursDELETEParams;
},
TContext
>;
}) => {
const { mutation: mutationOptions } = options ?? {};

const mutationFn: MutationFunction<
Awaited<ReturnType<typeof dplOpeningHoursDELETE>>,
{
id: string;
data: BodyType<DplOpeningHoursGETOpeningHoursInstanceBody>;
params?: DplOpeningHoursDELETEParams;
}
> = (props) => {
const { id, data, params } = props ?? {};

return dplOpeningHoursDELETE(id, data, params);
};

return useMutation<
Awaited<ReturnType<typeof dplOpeningHoursDELETE>>,
TError,
{
id: string;
data: BodyType<DplOpeningHoursGETOpeningHoursInstanceBody>;
params?: DplOpeningHoursDELETEParams;
},
TContext
>(mutationFn, mutationOptions);
};

/**
* @summary Manage individual opening hours
*/
export const dplOpeningHoursPATCH = (
id: string,
dplOpeningHoursGETOpeningHoursInstanceBody: BodyType<DplOpeningHoursGETOpeningHoursInstanceBody>,
params?: DplOpeningHoursPATCHParams
) => {
return fetcher<DplOpeningHoursPATCH200 | void>({
url: `/dpl_opening_hours/${id}`,
method: "patch",
headers: { "Content-Type": "application/json" },
data: dplOpeningHoursGETOpeningHoursInstanceBody,
params
});
};

export type DplOpeningHoursPATCHMutationResult = NonNullable<
Awaited<ReturnType<typeof dplOpeningHoursPATCH>>
>;
export type DplOpeningHoursPATCHMutationBody =
BodyType<DplOpeningHoursGETOpeningHoursInstanceBody>;
export type DplOpeningHoursPATCHMutationError = ErrorType<unknown>;

export const useDplOpeningHoursPATCH = <
TError = ErrorType<unknown>,
TContext = unknown
>(options?: {
mutation?: UseMutationOptions<
Awaited<ReturnType<typeof dplOpeningHoursPATCH>>,
TError,
{
id: string;
data: BodyType<DplOpeningHoursGETOpeningHoursInstanceBody>;
params?: DplOpeningHoursPATCHParams;
},
TContext
>;
}) => {
const { mutation: mutationOptions } = options ?? {};

const mutationFn: MutationFunction<
Awaited<ReturnType<typeof dplOpeningHoursPATCH>>,
{
id: string;
data: BodyType<DplOpeningHoursGETOpeningHoursInstanceBody>;
params?: DplOpeningHoursPATCHParams;
}
> = (props) => {
const { id, data, params } = props ?? {};

return dplOpeningHoursPATCH(id, data, params);
};

return useMutation<
Awaited<ReturnType<typeof dplOpeningHoursPATCH>>,
TError,
{
id: string;
data: BodyType<DplOpeningHoursGETOpeningHoursInstanceBody>;
params?: DplOpeningHoursPATCHParams;
},
TContext
>(mutationFn, mutationOptions);
};

/**
* @summary Manage individual opening hours
*/
export const dplOpeningHoursPOST = (
dplOpeningHoursGETOpeningHoursInstanceBody: BodyType<DplOpeningHoursGETOpeningHoursInstanceBody>,
params?: DplOpeningHoursPOSTParams
) => {
return fetcher<DplOpeningHoursPOST200 | void>({
url: `/dpl_opening_hours`,
method: "post",
headers: { "Content-Type": "application/json" },
data: dplOpeningHoursGETOpeningHoursInstanceBody,
params
});
};

export type DplOpeningHoursPOSTMutationResult = NonNullable<
Awaited<ReturnType<typeof dplOpeningHoursPOST>>
>;
export type DplOpeningHoursPOSTMutationBody =
BodyType<DplOpeningHoursGETOpeningHoursInstanceBody>;
export type DplOpeningHoursPOSTMutationError = ErrorType<unknown>;

export const useDplOpeningHoursPOST = <
TError = ErrorType<unknown>,
TContext = unknown
>(options?: {
mutation?: UseMutationOptions<
Awaited<ReturnType<typeof dplOpeningHoursPOST>>,
TError,
{
data: BodyType<DplOpeningHoursGETOpeningHoursInstanceBody>;
params?: DplOpeningHoursPOSTParams;
},
TContext
>;
}) => {
const { mutation: mutationOptions } = options ?? {};

const mutationFn: MutationFunction<
Awaited<ReturnType<typeof dplOpeningHoursPOST>>,
{
data: BodyType<DplOpeningHoursGETOpeningHoursInstanceBody>;
params?: DplOpeningHoursPOSTParams;
}
> = (props) => {
const { data, params } = props ?? {};

return dplOpeningHoursPOST(data, params);
};

return useMutation<
Awaited<ReturnType<typeof dplOpeningHoursPOST>>,
TError,
{
data: BodyType<DplOpeningHoursGETOpeningHoursInstanceBody>;
params?: DplOpeningHoursPOSTParams;
},
TContext
>(mutationFn, mutationOptions);
};

/**
* @summary List all opening hours
*/
Expand Down Expand Up @@ -264,7 +547,7 @@ export const useEventsGET = <
};

/**
* @summary Generate proxy URL / Generer proxy URL
* @summary Generate proxy url
*/
export const proxyUrlGET = (
params?: ProxyUrlGETParams,
Expand Down
22 changes: 22 additions & 0 deletions src/core/dpl-cms/model/dplOpeningHoursDELETE200.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Generated by orval v6.8.1 🍺
* Do not edit manually.
* DPL CMS - REST API
* The REST API provide by the core REST module.
* OpenAPI spec version: Versioning not supported
*/
import type { DplOpeningHoursDELETE200Category } from "./dplOpeningHoursDELETE200Category";

export type DplOpeningHoursDELETE200 = {
/** An serial unique id of the opening hours instance. */
id: number;
category: DplOpeningHoursDELETE200Category;
/** The date which the opening hours applies to. In ISO 8601 format. */
date: string;
/** When the opening hours start. In format HH:MM */
start_time: string;
/** When the opening hours end. In format HH:MM */
end_time: string;
/** The id for the branch the instance belongs to */
branch_id: number;
};
13 changes: 13 additions & 0 deletions src/core/dpl-cms/model/dplOpeningHoursDELETE200Category.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* Generated by orval v6.8.1 🍺
* Do not edit manually.
* DPL CMS - REST API
* The REST API provide by the core REST module.
* OpenAPI spec version: Versioning not supported
*/

export type DplOpeningHoursDELETE200Category = {
title: string;
/** A CSS compatible color code which can be used to represent the category */
color: string;
};
Loading

0 comments on commit 8c0bb1a

Please sign in to comment.