204 lines
3.6 KiB
TypeScript
204 lines
3.6 KiB
TypeScript
/**
|
|
* Interface of the server (auto-generated code)
|
|
*/
|
|
import {
|
|
HTTPMimeType,
|
|
HTTPRequestModel,
|
|
RESTCallbacks,
|
|
RESTConfig,
|
|
RESTRequestJson,
|
|
RESTRequestVoid,
|
|
} from "../rest-tools";
|
|
|
|
import { z as zod } from "zod"
|
|
import {
|
|
Album,
|
|
AlbumCreate,
|
|
AlbumUpdate,
|
|
ObjectId,
|
|
ZodAlbum,
|
|
isAlbum,
|
|
} from "../model";
|
|
|
|
export namespace AlbumResource {
|
|
|
|
/**
|
|
* Get a specific Album with his ID
|
|
*/
|
|
export function get({
|
|
restConfig,
|
|
params,
|
|
}: {
|
|
restConfig: RESTConfig,
|
|
params: {
|
|
oid: ObjectId,
|
|
},
|
|
}): Promise<Album> {
|
|
return RESTRequestJson({
|
|
restModel: {
|
|
endPoint: "/album/{oid}",
|
|
requestType: HTTPRequestModel.GET,
|
|
accept: HTTPMimeType.JSON,
|
|
},
|
|
restConfig,
|
|
params,
|
|
}, isAlbum);
|
|
};
|
|
|
|
export const ZodGetsTypeReturn = zod.array(ZodAlbum);
|
|
export type GetsTypeReturn = zod.infer<typeof ZodGetsTypeReturn>;
|
|
|
|
export function isGetsTypeReturn(data: any): data is GetsTypeReturn {
|
|
try {
|
|
ZodGetsTypeReturn.parse(data);
|
|
return true;
|
|
} catch (e: any) {
|
|
console.log(`Fail to parse data type='ZodGetsTypeReturn' error=${e}`);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Get all the available Albums
|
|
*/
|
|
export function gets({
|
|
restConfig,
|
|
}: {
|
|
restConfig: RESTConfig,
|
|
}): Promise<GetsTypeReturn> {
|
|
return RESTRequestJson({
|
|
restModel: {
|
|
endPoint: "/album/",
|
|
requestType: HTTPRequestModel.GET,
|
|
accept: HTTPMimeType.JSON,
|
|
},
|
|
restConfig,
|
|
}, isGetsTypeReturn);
|
|
};
|
|
/**
|
|
* Add an album (when all the data already exist)
|
|
*/
|
|
export function post({
|
|
restConfig,
|
|
data,
|
|
}: {
|
|
restConfig: RESTConfig,
|
|
data: AlbumCreate,
|
|
}): Promise<Album> {
|
|
return RESTRequestJson({
|
|
restModel: {
|
|
endPoint: "/album/",
|
|
requestType: HTTPRequestModel.POST,
|
|
contentType: HTTPMimeType.JSON,
|
|
accept: HTTPMimeType.JSON,
|
|
},
|
|
restConfig,
|
|
data,
|
|
}, isAlbum);
|
|
};
|
|
/**
|
|
* Update a specific album
|
|
*/
|
|
export function put({
|
|
restConfig,
|
|
params,
|
|
data,
|
|
}: {
|
|
restConfig: RESTConfig,
|
|
params: {
|
|
oid: ObjectId,
|
|
},
|
|
data: AlbumUpdate,
|
|
}): Promise<Album> {
|
|
return RESTRequestJson({
|
|
restModel: {
|
|
endPoint: "/album/{oid}",
|
|
requestType: HTTPRequestModel.PUT,
|
|
contentType: HTTPMimeType.JSON,
|
|
accept: HTTPMimeType.JSON,
|
|
},
|
|
restConfig,
|
|
params,
|
|
data,
|
|
}, isAlbum);
|
|
};
|
|
/**
|
|
* Remove a specific album
|
|
*/
|
|
export function remove({
|
|
restConfig,
|
|
params,
|
|
}: {
|
|
restConfig: RESTConfig,
|
|
params: {
|
|
oid: ObjectId,
|
|
},
|
|
}): Promise<void> {
|
|
return RESTRequestVoid({
|
|
restModel: {
|
|
endPoint: "/album/{oid}",
|
|
requestType: HTTPRequestModel.DELETE,
|
|
contentType: HTTPMimeType.TEXT_PLAIN,
|
|
},
|
|
restConfig,
|
|
params,
|
|
});
|
|
};
|
|
/**
|
|
* Remove a cover on a specific album
|
|
*/
|
|
export function removeCover({
|
|
restConfig,
|
|
params,
|
|
}: {
|
|
restConfig: RESTConfig,
|
|
params: {
|
|
coverId: ObjectId,
|
|
oid: ObjectId,
|
|
},
|
|
}): Promise<Album> {
|
|
return RESTRequestJson({
|
|
restModel: {
|
|
endPoint: "/album/{oid}/cover/{coverId}",
|
|
requestType: HTTPRequestModel.DELETE,
|
|
contentType: HTTPMimeType.TEXT_PLAIN,
|
|
accept: HTTPMimeType.JSON,
|
|
},
|
|
restConfig,
|
|
params,
|
|
}, isAlbum);
|
|
};
|
|
/**
|
|
* Add a cover on a specific album
|
|
*/
|
|
export function uploadCover({
|
|
restConfig,
|
|
params,
|
|
data,
|
|
callbacks,
|
|
}: {
|
|
restConfig: RESTConfig,
|
|
params: {
|
|
oid: ObjectId,
|
|
},
|
|
data: {
|
|
file?: File,
|
|
uri?: string,
|
|
},
|
|
callbacks?: RESTCallbacks,
|
|
}): Promise<Album> {
|
|
return RESTRequestJson({
|
|
restModel: {
|
|
endPoint: "/album/{oid}/cover",
|
|
requestType: HTTPRequestModel.POST,
|
|
contentType: HTTPMimeType.MULTIPART,
|
|
accept: HTTPMimeType.JSON,
|
|
},
|
|
restConfig,
|
|
params,
|
|
data,
|
|
callbacks,
|
|
}, isAlbum);
|
|
};
|
|
}
|