Add admin panel
This commit is contained in:
@@ -0,0 +1,112 @@
|
||||
import { error } from '@sveltejs/kit';
|
||||
import type { Actions } from './$types';
|
||||
|
||||
const api_url = import.meta.env.VITE_API_URL;
|
||||
|
||||
export const actions: Actions = {
|
||||
addUser: async ({ request, fetch }) => {
|
||||
const formData = await request.formData();
|
||||
const userData = Object.fromEntries(formData);
|
||||
|
||||
const response = await fetch(`${api_url}/admin/user`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(userData)
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw error(response.status, 'Failed to add user');
|
||||
}
|
||||
|
||||
return { success: true };
|
||||
},
|
||||
|
||||
deleteUser: async ({ request, fetch }) => {
|
||||
const formData = await request.formData();
|
||||
const userId = formData.get('userId');
|
||||
|
||||
const response = await fetch(`${api_url}/admin/user/${userId}`, {
|
||||
method: 'DELETE'
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw error(response.status, 'Failed to delete user');
|
||||
}
|
||||
|
||||
return { success: true };
|
||||
},
|
||||
|
||||
addMovie: async ({ request, fetch }) => {
|
||||
const formData = await request.formData();
|
||||
const movieData = Object.fromEntries(formData);
|
||||
|
||||
const response = await fetch(`${api_url}/admin/movie`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(movieData)
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw error(response.status, 'Failed to add movie');
|
||||
}
|
||||
|
||||
return { success: true };
|
||||
},
|
||||
|
||||
setMovieWatched: async ({ request, fetch }) => {
|
||||
const formData = await request.formData();
|
||||
const movieId = formData.get('movieId');
|
||||
|
||||
const response = await fetch(`${api_url}/admin/movie/${movieId}`, {
|
||||
method: 'PATCH',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({ is_watched: true })
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw error(response.status, 'Failed to update movie status');
|
||||
}
|
||||
|
||||
return { success: true };
|
||||
},
|
||||
|
||||
addCard: async ({ request, fetch }) => {
|
||||
const formData = await request.formData();
|
||||
const cardData = Object.fromEntries(formData);
|
||||
|
||||
const response = await fetch(`${api_url}/admin/card`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(cardData)
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw error(response.status, 'Failed to add card');
|
||||
}
|
||||
|
||||
return { success: true };
|
||||
},
|
||||
|
||||
deleteCard: async ({ request, fetch }) => {
|
||||
const formData = await request.formData();
|
||||
const cardId = formData.get('cardId');
|
||||
|
||||
const response = await fetch(`${api_url}/admin/card/${cardId}`, {
|
||||
method: 'DELETE'
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw error(response.status, 'Failed to delete card');
|
||||
}
|
||||
|
||||
return { success: true };
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user