mirror of
https://github.com/Drop-OSS/drop.git
synced 2025-11-14 08:41:15 +10:00
feat: refactor & redesign parts of UI
This commit is contained in:
@ -20,22 +20,15 @@ export default defineEventHandler(async (h3) => {
|
||||
if (!gameId)
|
||||
throw createError({ statusCode: 400, statusMessage: "Game ID required" });
|
||||
|
||||
// Verify collection exists and user owns it
|
||||
const collection = await userLibraryManager.fetchCollection(id);
|
||||
if (!collection) {
|
||||
const successful = await userLibraryManager.collectionRemove(
|
||||
gameId,
|
||||
id,
|
||||
userId
|
||||
);
|
||||
if (!successful)
|
||||
throw createError({
|
||||
statusCode: 404,
|
||||
statusMessage: "Collection not found",
|
||||
});
|
||||
}
|
||||
|
||||
if (collection.userId !== userId) {
|
||||
throw createError({
|
||||
statusCode: 403,
|
||||
statusMessage: "Not authorized to modify this collection",
|
||||
});
|
||||
}
|
||||
|
||||
const removed = await userLibraryManager.collectionRemove(gameId, id);
|
||||
return {};
|
||||
});
|
||||
|
||||
@ -20,22 +20,6 @@ export default defineEventHandler(async (h3) => {
|
||||
if (!gameId)
|
||||
throw createError({ statusCode: 400, statusMessage: "Game ID required" });
|
||||
|
||||
// Verify collection exists and user owns it
|
||||
const collection = await userLibraryManager.fetchCollection(id);
|
||||
if (!collection) {
|
||||
throw createError({
|
||||
statusCode: 404,
|
||||
statusMessage: "Collection not found",
|
||||
});
|
||||
}
|
||||
|
||||
if (collection.userId !== userId) {
|
||||
throw createError({
|
||||
statusCode: 403,
|
||||
statusMessage: "Not authorized to modify this collection",
|
||||
});
|
||||
}
|
||||
|
||||
await userLibraryManager.collectionAdd(gameId, id);
|
||||
return { success: true };
|
||||
await userLibraryManager.collectionAdd(gameId, id, userId);
|
||||
return;
|
||||
});
|
||||
|
||||
@ -16,28 +16,19 @@ export default defineEventHandler(async (h3) => {
|
||||
});
|
||||
|
||||
// Verify collection exists and user owns it
|
||||
// Will not return the default collection
|
||||
const collection = await userLibraryManager.fetchCollection(id);
|
||||
if (!collection) {
|
||||
if (!collection)
|
||||
throw createError({
|
||||
statusCode: 404,
|
||||
statusMessage: "Collection not found",
|
||||
});
|
||||
}
|
||||
|
||||
if (collection.userId !== userId) {
|
||||
if (collection.userId !== userId)
|
||||
throw createError({
|
||||
statusCode: 403,
|
||||
statusMessage: "Not authorized to delete this collection",
|
||||
});
|
||||
}
|
||||
|
||||
// Don't allow deleting default collection
|
||||
if (collection.isDefault) {
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "Cannot delete default collection",
|
||||
});
|
||||
}
|
||||
|
||||
await userLibraryManager.deleteCollection(id);
|
||||
return { success: true };
|
||||
|
||||
@ -16,21 +16,20 @@ export default defineEventHandler(async (h3) => {
|
||||
});
|
||||
|
||||
// Fetch specific collection
|
||||
// Will not return the default collection
|
||||
const collection = await userLibraryManager.fetchCollection(id);
|
||||
if (!collection) {
|
||||
if (!collection)
|
||||
throw createError({
|
||||
statusCode: 404,
|
||||
statusMessage: "Collection not found",
|
||||
});
|
||||
}
|
||||
|
||||
// Verify user owns this collection
|
||||
if (collection.userId !== userId) {
|
||||
if (collection.userId !== userId)
|
||||
throw createError({
|
||||
statusCode: 403,
|
||||
statusMessage: "Not authorized to access this collection",
|
||||
});
|
||||
}
|
||||
|
||||
return collection;
|
||||
});
|
||||
|
||||
@ -13,18 +13,7 @@ export default defineEventHandler(async (h3) => {
|
||||
if (!gameId)
|
||||
throw createError({ statusCode: 400, statusMessage: "Game ID required" });
|
||||
|
||||
// Get the default collection for this user
|
||||
const collections = await userLibraryManager.fetchCollections(userId);
|
||||
const defaultCollection = collections.find(c => c.isDefault);
|
||||
|
||||
if (!defaultCollection) {
|
||||
throw createError({
|
||||
statusCode: 404,
|
||||
statusMessage: "Default collection not found",
|
||||
});
|
||||
}
|
||||
|
||||
// Add the game to the default collection
|
||||
await userLibraryManager.collectionAdd(gameId, defaultCollection.id);
|
||||
await userLibraryManager.libraryAdd(gameId, userId);
|
||||
return {};
|
||||
});
|
||||
|
||||
14
server/api/v1/collection/default/index.get.ts
Normal file
14
server/api/v1/collection/default/index.get.ts
Normal file
@ -0,0 +1,14 @@
|
||||
import userLibraryManager from "~/server/internal/userlibrary";
|
||||
|
||||
export default defineEventHandler(async (h3) => {
|
||||
const userId = await h3.context.session.getUserId(h3);
|
||||
if (!userId)
|
||||
throw createError({
|
||||
statusCode: 403,
|
||||
statusMessage: "Requires authentication",
|
||||
});
|
||||
|
||||
const collection = await userLibraryManager.fetchLibrary(userId);
|
||||
|
||||
return collection;
|
||||
});
|
||||
Reference in New Issue
Block a user