refactor(backend): RemoteResource-systeem dat vervangen werd door TanStack verwijderd.
This commit is contained in:
parent
be78e7f44d
commit
a33ec6c452
9 changed files with 0 additions and 193 deletions
|
@ -1,9 +0,0 @@
|
|||
import {type Params, RestEndpoint} from "@/services/api-client/endpoints/rest-endpoint.ts";
|
||||
|
||||
export class DeleteEndpoint<PP extends Params, QP extends Params, R> extends RestEndpoint<PP, QP, undefined, R> {
|
||||
readonly method = "GET";
|
||||
|
||||
public delete(pathParams: PP, queryParams: QP): Promise<R> {
|
||||
return super.request(pathParams, queryParams, undefined);
|
||||
}
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
import {type Params, RestEndpoint} from "@/services/api-client/endpoints/rest-endpoint.ts";
|
||||
|
||||
export class GetEndpoint<PP extends Params, QP extends Params, R> extends RestEndpoint<PP, QP, undefined, R> {
|
||||
readonly method = "GET";
|
||||
|
||||
public get(pathParams: PP, queryParams: QP): Promise<R> {
|
||||
return super.request(pathParams, queryParams, undefined);
|
||||
}
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
import {type Params, RestEndpoint} from "@/services/api-client/endpoints/rest-endpoint.ts";
|
||||
|
||||
export class GetHtmlEndpoint<PP extends Params, QP extends Params> extends RestEndpoint<PP, QP, undefined, Document> {
|
||||
readonly method: "GET" | "POST" | "PUT" | "DELETE" = "GET";
|
||||
|
||||
public get(pathParams: PP, queryParams: QP): Promise<Document> {
|
||||
return super.request(pathParams, queryParams, undefined, "document");
|
||||
}
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
import {type Params, RestEndpoint} from "@/services/api-client/endpoints/rest-endpoint.ts";
|
||||
|
||||
export class PostEndpoint<PP extends Params, QP extends Params, B, R> extends RestEndpoint<PP, QP, B, R> {
|
||||
readonly method = "POST";
|
||||
|
||||
public post(pathParams: PP, queryParams: QP, body: B): Promise<R> {
|
||||
return super.request(pathParams, queryParams, body);
|
||||
}
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
import apiClient from "@/services/api-client/api-client.ts";
|
||||
import {HttpErrorStatusException} from "@/services/api-client/api-exceptions.ts";
|
||||
import type {ResponseType} from "axios";
|
||||
|
||||
export abstract class RestEndpoint<PP extends Params, QP extends Params, B, R> {
|
||||
public abstract readonly method: "GET" | "POST" | "PUT" | "DELETE";
|
||||
constructor(public readonly url: string) {
|
||||
}
|
||||
|
||||
protected async request(pathParams: PP, queryParams: QP, body: B, responseType?: ResponseType): Promise<R> {
|
||||
let urlFilledIn = this.url.replace(/:(\w+)(\/|$)/g, (_, key, after) =>
|
||||
(pathParams[key] ? encodeURIComponent(pathParams[key]) : `:${key}`) + after
|
||||
);
|
||||
const response = await apiClient.request<R>({
|
||||
url: urlFilledIn,
|
||||
method: this.method,
|
||||
params: queryParams,
|
||||
data: body,
|
||||
responseType: responseType || 'json'
|
||||
});
|
||||
if (response.status / 100 !== 2) {
|
||||
throw new HttpErrorStatusException(response);
|
||||
}
|
||||
return response.data;
|
||||
}
|
||||
}
|
||||
|
||||
export type Params = {[key: string]: string | number | boolean | undefined};
|
|
@ -1,37 +0,0 @@
|
|||
import {type ShallowReactive, shallowReactive} from "vue";
|
||||
|
||||
export type NotLoadedState = {
|
||||
type: "notLoaded"
|
||||
};
|
||||
export type LoadingState = {
|
||||
type: "loading"
|
||||
};
|
||||
export type ErrorState = {
|
||||
type: "error",
|
||||
error: any
|
||||
};
|
||||
export type SuccessState<T> = {
|
||||
type: "success",
|
||||
data: T
|
||||
};
|
||||
export type RemoteResourceState<T> = NotLoadedState | LoadingState | ErrorState | SuccessState<T>;
|
||||
|
||||
export type RemoteResource<T> = ShallowReactive<{
|
||||
state: RemoteResourceState<T>
|
||||
}>;
|
||||
|
||||
export function remoteResource<T>(): RemoteResource<T> {
|
||||
return shallowReactive({
|
||||
state: {
|
||||
type: "notLoaded"
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function loadResource<T>(resource: RemoteResource<T>, promise: Promise<T>): void {
|
||||
resource.state = { type: "loading" }
|
||||
promise.then(
|
||||
data => resource.state = { type: "success", data },
|
||||
error => resource.state = { type: "error", error }
|
||||
);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue