Phill Pover 3ecd1bc422
Some checks failed
Music Collection CI Workflow / test (./backend) (push) Successful in 29s
Music Collection CI Workflow / test (./frontend) (push) Successful in 35s
Music Collection CI Workflow / deploy (push) Has been cancelled
Music Collection CI Workflow / build-and-push-images (./frontend/Dockerfile, git.anatid.net/tabris/music-collection-frontend, ./frontend) (push) Has been cancelled
Music Collection CI Workflow / build-and-push-images (./backend/Dockerfile, git.anatid.net/tabris/music-collection-backend, ./backend) (push) Has been cancelled
Fixes
2025-04-07 05:40:48 +01:00

191 lines
5.0 KiB
TypeScript

'use server'
export async function getAlbums() {
return fetch('https://api.anatid.net/album', {
method: "GET",
headers: { "Content-Type": "application/json" },
next: { revalidate: 10 }
}).then(response => {
if (response.ok) {
return response.json();
}
return Promise.reject(response);
}).catch(error => {
console.log(error);
});
}
export async function getAlbum(id: number) {
return fetch(`https://api.anatid.net/album/${id}`, {
method: "GET",
headers: { "Content-Type": "application/json" },
next: { revalidate: 10 }
}).then(response => {
if (response.ok) {
return response.json();
}
return Promise.reject(response);
}).catch(error => {
console.log(error);
});
}
export async function createAlbum(formData: FormData) {
const title = formData.get('title');
const artist = formData.get('artist');
const genre = formData.get('genre');
return fetch("https://api.anatid.net/album", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
title: title,
artist: artist,
genre: genre,
})
}).then(response => {
if (response.ok) {
return response.json();
}
return Promise.reject(response);
}).catch(error => {
console.log(error);
});
}
export async function updateAlbum(formData: FormData) {
const id = formData.get('id');
const title = formData.get('title');
const artist = formData.get('artist');
const genre = formData.get('genre');
console.log(id,title,artist,genre);
return fetch(`https://api.anatid.net/album/${id}`, {
method: "PUT",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
id: id,
title: title,
artist: artist,
genre: genre,
})
}).then(response => {
if (response.ok) {
return response.json();
}
return Promise.reject(response);
}).catch(error => {
console.log(error);
});
}
export async function deleteAlbum(id: number) {
return fetch(`https://api.anatid.net/album/${id}`, {
method: "DELETE",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
id: id,
})
}).then(response => {
if (response.ok) {
return response.json();
}
return Promise.reject(response);
}).catch(error => {
console.log(error);
});
}
export async function getSongs() {
return fetch("https://api.anatid.net/song/", {
method: "GET",
headers: { "Content-Type": "application/json" },
next: { revalidate: 10 }
}).then(response => {
if (response.ok) {
return response.json();
}
return Promise.reject(response);
}).catch(error => {
console.log(error);
});
}
export async function getSong(id: number) {
return fetch(`https://api.anatid.net/song/${id}`, {
method: "GET",
headers: { "Content-Type": "application/json" },
next: { revalidate: 10 }
}).then(response => {
if (response.ok) {
return response.json();
}
return Promise.reject(response);
}).catch(error => {
console.log(error);
});
}
export async function createSong(formData: FormData) {
const albumId = formData.get('album-id');
const title = formData.get('title');
const duration = formData.get('duration');
const trackNumber = formData.get('trackNumber');
return fetch("https://api.anatid.net/song", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
albumId: albumId,
title: title,
duration: duration,
trackNumber: trackNumber,
})
}).then(response => {
if (response.ok) {
return response.json();
}
return Promise.reject(response);
}).catch(error => {
console.log(error);
});
}
export async function updateSong(formData: FormData) {
const id = formData.get('id');
const albumId = formData.get('album-id');
const title = formData.get('title');
const duration = formData.get('duration');
const trackNumber = formData.get('trackNumber');
return fetch(`https://api.anatid.net/song/${albumId}`, {
method: "PUT",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
id: id,
albumId: albumId,
title: title,
duration: duration,
trackNumber: trackNumber,
}),
next: { revalidate: 10 }
}).then(response => {
if (response.ok) {
return response.json();
}
return Promise.reject(response);
}).catch(error => {
console.log(error);
});
}
export async function deleteSong(id: number) {
return fetch(`https://api.anatid.net/song/${id}`, {
method: "DELETE",
headers: { "Content-Type": "application/json" }
}).then(response => {
if (response.ok) {
return response.json();
}
return Promise.reject(response);
}).catch(error => {
console.log(error);
});
}