You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
191 lines
4.9 KiB
191 lines
4.9 KiB
// TODO: this file is located in the client src folder because |
|
// otherwise, Create React App will refuse to compile it. |
|
// Putting it in the server folder or in its own folder makes more sense. |
|
|
|
// This file represents the API interface for Mudbase's back-end. |
|
// Each endpoint is described by its endpoint address, |
|
// a request structure, a response structure and |
|
// a checking function which determines request validity. |
|
|
|
// Query for songs (POST). |
|
export const QuerySongsEndpoint = '/song/query'; |
|
export enum SongQueryElemOp { |
|
And = "AND", |
|
Or = "OR", |
|
} |
|
export enum SongQueryFilterOp { |
|
Eq = "EQ", |
|
Ne = "NE", |
|
In = "IN", |
|
NotIn = "NOTIN" |
|
} |
|
export enum SongQueryElemProperty { |
|
id = "id", |
|
artistIds = "artistIds", |
|
albumIds = "albumIds", |
|
} |
|
export interface SongQueryElem { |
|
prop?: SongQueryElemProperty, |
|
propOperand?: any, |
|
propOperator?: SongQueryFilterOp, |
|
children?: SongQueryElem[] |
|
childrenOperator?: SongQueryElemOp, |
|
} |
|
export interface SongQuery extends SongQueryElem {} |
|
export interface QuerySongsRequest { |
|
query: SongQuery |
|
} |
|
export interface QuerySongsResponse { |
|
ids: Number[] |
|
} |
|
export function checkQuerySongsElem(elem:any): boolean { |
|
if(elem.childrenOperator && elem.children) { |
|
elem.children.forEach((child:any) => { |
|
if(!checkQuerySongsElem(child)) { |
|
return false; |
|
} |
|
}); |
|
} |
|
return (elem.childrenOperator && elem.children) || |
|
(elem.prop && elem.propOperand && elem.propOperator) || |
|
Object.keys(elem).length == 0; |
|
} |
|
export function checkQuerySongsRequest(req:any): boolean { |
|
return "query" in req && checkQuerySongsElem(req.query); |
|
} |
|
|
|
// Get song details (GET). |
|
export const SongDetailsEndpoint = '/song/:id'; |
|
export interface SongDetailsRequest {} |
|
export interface SongDetailsResponse { |
|
title: String, |
|
storeLinks: String[], |
|
artistIds: Number[], |
|
albumIds: Number[], |
|
} |
|
export function checkSongDetailsRequest(req:any): boolean { |
|
return true; |
|
} |
|
|
|
// Query for artists. |
|
export const QueryArtistsEndpoint = '/artist/query'; |
|
export interface QueryArtistsRequest {} |
|
export interface QueryArtistsResponse { |
|
ids: Number[] |
|
} |
|
export function checkQueryArtistsRequest(req:any): boolean { |
|
return true; |
|
} |
|
|
|
// Get artist details (GET). |
|
export const ArtistDetailsEndpoint = '/artist/:id'; |
|
export interface ArtistDetailsRequest {} |
|
export interface ArtistDetailsResponse { |
|
name: String, |
|
storeLinks: String[], |
|
} |
|
export function checkArtistDetailsRequest(req:any): boolean { |
|
return true; |
|
} |
|
|
|
// Create a new song (POST). |
|
export const CreateSongEndpoint = '/song'; |
|
export interface CreateSongRequest { |
|
title: String; |
|
artistIds?: Number[]; |
|
albumIds?: Number[]; |
|
storeLinks?: String[]; |
|
} |
|
export interface CreateSongResponse { |
|
id: Number; |
|
} |
|
export function checkCreateSongRequest(req:any): boolean { |
|
return "body" in req && |
|
"title" in req.body; |
|
} |
|
|
|
// Modify an existing song (PUT). |
|
export const ModifySongEndpoint = '/song/:id'; |
|
export interface ModifySongRequest { |
|
title?: String; |
|
artistIds?: Number[]; |
|
albumIds?: Number[]; |
|
storeLinks?: String[]; |
|
} |
|
export interface ModifySongResponse {} |
|
export function checkModifySongRequest(req:any): boolean { |
|
return true; |
|
} |
|
|
|
// Create a new artist (POST). |
|
export const CreateArtistEndpoint = '/artist'; |
|
export interface CreateArtistRequest { |
|
name: String; |
|
songIds?: Number[]; |
|
albumIds?: Number[]; |
|
storeLinks?: String[]; |
|
} |
|
export interface CreateArtistResponse { |
|
id: Number; |
|
} |
|
export function checkCreateArtistRequest(req:any): boolean { |
|
return "body" in req && |
|
"name" in req.body; |
|
} |
|
|
|
// Modify an existing artist (PUT). |
|
export const ModifyArtistEndpoint = '/artist/:id'; |
|
export interface ModifyArtistRequest { |
|
name?: String, |
|
storeLinks?: String[], |
|
} |
|
export interface ModifyArtistResponse {} |
|
export function checkModifyArtistRequest(req:any): boolean { |
|
return true; |
|
} |
|
|
|
// Create a new tag (POST). |
|
export const CreateTagEndpoint = '/tag'; |
|
export interface CreateTagRequest { |
|
name: String; |
|
parentId?: Number; |
|
} |
|
export interface CreateTagResponse { |
|
id: Number; |
|
} |
|
export function checkCreateTagRequest(req:any): boolean { |
|
return "body" in req && |
|
"name" in req.body; |
|
} |
|
|
|
// Modify an existing tag (PUT). |
|
export const ModifyTagEndpoint = '/tag/:id'; |
|
export interface ModifyTagRequest { |
|
name?: String, |
|
parentId?: Number; |
|
} |
|
export interface ModifyTagResponse {} |
|
export function checkModifyTagRequest(req:any): boolean { |
|
return true; |
|
} |
|
|
|
// Query for tags. |
|
export const QueryTagEndpoint = '/tag/query'; |
|
export interface QueryTagsRequest {} |
|
export interface QueryTagsResponse { |
|
ids: Number[] |
|
} |
|
export function checkQueryTagsRequest(req:any): boolean { |
|
return true; |
|
} |
|
|
|
// Get tag details (GET). |
|
export const TagDetailsEndpoint = '/tag/:id'; |
|
export interface TagDetailsRequest {} |
|
export interface TagDetailsResponse { |
|
name: String, |
|
parentId?: Number, |
|
} |
|
export function checkTagDetailsRequest(req:any): boolean { |
|
return true; |
|
} |