Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V.0.3.1 #29

Merged
merged 2 commits into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "backend"
version = "0.1.0"
version = "0.3.0"
description = ""
authors = ["xKhronoz"]
readme = "README.md"
Expand Down
28 changes: 14 additions & 14 deletions frontend/app/api/admin/collections-requests/approve/route.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createClient } from '@supabase/supabase-js';
import { NextRequest, NextResponse } from "next/server";

// POST request to approve the user's public collections request status in the database (Used by admin)
// POST request to approve the user's collections request status in the database (Used by admin)
export async function POST(request: NextRequest) {
// Create a new Supabase client
const supabase = createClient(
Expand All @@ -13,31 +13,31 @@ export async function POST(request: NextRequest) {
// Retrieve the collection_id from the request body
const { collection_id, is_make_public } = await request?.json();

// Update the user's public collections request data in the database, set is_pending = false
const { data: updatedUserPubCollectionsReq, error: updatedUserPubCollReqErr } = await supabase
.from('public_collections_requests')
// Update the user's collections request data in the database, set is_pending = false
const { data: updatedUserCollectionsReq, error: updatedUserCollReqErr } = await supabase
.from('collections_requests')
.update({ is_pending: false, is_approved: true })
.eq('collection_id', collection_id);

if (updatedUserPubCollReqErr) {
console.error('Error updating user public collections request data in database:', updatedUserPubCollReqErr.message);
return NextResponse.json({ error: updatedUserPubCollReqErr.message }, { status: 500 });
if (updatedUserCollReqErr) {
console.error('Error updating user collections request data in database:', updatedUserCollReqErr.message);
return NextResponse.json({ error: updatedUserCollReqErr.message }, { status: 500 });
}

// Update the user's collections data in the database, set is_public = true
console.log('is_public:', is_make_public);
const { data: updatedUserPubCollections, error: updatedUserPubCollErr } = await supabase
const { data: updatedUserCollections, error: updatedUserCollErr } = await supabase
.from('collections')
.update({ is_public: is_make_public})
.eq('collection_id', collection_id);

if (updatedUserPubCollErr) {
console.error('Error updating user public collections data in database:', updatedUserPubCollErr.message);
return NextResponse.json({ error: updatedUserPubCollErr.message }, { status: 500 });
if (updatedUserCollErr) {
console.error('Error updating user public collections data in database:', updatedUserCollErr.message);
return NextResponse.json({ error: updatedUserCollErr.message }, { status: 500 });
}

// console.log('Admin: User Public Collections Requests:', userPubCollectionsReq);
// console.log('Admin: User Public Collections:', userPubCollections);
// console.log('Admin: Approved User Collections Request:', userPubCollectionsReq);
// console.log('Admin: Updated User Collections:', userPubCollections);

return NextResponse.json({ updatedUserPubCollectionsReq, updatedUserPubCollections });
return NextResponse.json({ updatedUserCollectionsReq, updatedUserCollections });
}
18 changes: 9 additions & 9 deletions frontend/app/api/admin/collections-requests/reject/route.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createClient } from '@supabase/supabase-js';
import { NextRequest, NextResponse } from "next/server";

// POST request to reject the user's public collections request status in the database (Used by admin)
// POST request to reject the user's collections request status in the database (Used by admin)
export async function POST(request: NextRequest) {
// Create a new Supabase client
const supabase = createClient(
Expand All @@ -13,18 +13,18 @@ export async function POST(request: NextRequest) {
// Retrieve the collection_id from the request body
const { collection_id } = await request?.json();

// Update the user's public collections request data in the database, set is_pending = false
const { data: updatedUserPubCollectionsReq, error: updatedUserPubCollErr } = await supabase
.from('public_collections_requests')
// Update the user's collections request data in the database, set is_pending = false
const { data: updatedUserCollectionsReq, error: updatedUserCollErr } = await supabase
.from('collections_requests')
.update({ is_pending: false, is_approved: false})
.eq('collection_id', collection_id);

if (updatedUserPubCollErr) {
console.error('Error updating user public collections request data in database:', updatedUserPubCollErr.message);
return NextResponse.json({ error: updatedUserPubCollErr.message }, { status: 500 });
if (updatedUserCollErr) {
console.error('Error updating user collections request data in database:', updatedUserCollErr.message);
return NextResponse.json({ error: updatedUserCollErr.message }, { status: 500 });
}

// console.log('User Public Collections Requests:', userPubCollectionsReq);
// console.log('Admin: Reject User Collections Requests:', updatedUserCollectionsReq);

return NextResponse.json({ updatedUserPubCollectionsReq });
return NextResponse.json({ updatedUserCollectionsReq });
}
7 changes: 4 additions & 3 deletions frontend/app/api/admin/collections-requests/route.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createClient } from '@supabase/supabase-js';
import { NextRequest, NextResponse } from "next/server";

// GET request to retrieve the collections requests data from the database
export async function GET(request: NextRequest) {
// Create a new Supabase client
const supabase = createClient(
Expand All @@ -11,16 +12,16 @@ export async function GET(request: NextRequest) {

// Retrieve the public collections requests data from the database
const { data: pubCollectionsReq, error: pubCollErr } = await supabase
.from('public_collections_requests')
.from('collections_requests')
.select('collection_id, is_make_public, is_pending, is_approved, created_at, updated_at, collections (collection_id, id, display_name, description, is_public, users (id, name, email))')
.eq('is_pending', true);

if (pubCollErr) {
console.error('Error fetching public collection request data from database:', pubCollErr.message);
console.error('Error fetching collection request data from database:', pubCollErr.message);
return NextResponse.json({ error: pubCollErr.message }, { status: 500 });
}

console.log('Collections Request:', pubCollectionsReq);
// console.log('Collections Request:', pubCollectionsReq);

return NextResponse.json({ pubCollectionsReq: pubCollectionsReq });
}
41 changes: 41 additions & 0 deletions frontend/app/api/admin/collections/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,44 @@ export async function GET(request: NextRequest) {

return NextResponse.json({ collections: collections });
}

// PUT request to update the collection data in the database
export async function PUT(request: NextRequest) {
// Create a new Supabase client
const supabase = createClient(
process.env.SUPABASE_URL ?? '',
process.env.SUPABASE_SERVICE_ROLE_KEY ?? '',
{ db: { schema: 'public' } },
);

// Retrieve the collection ID from the request body
const { collection_id, is_public } = await request.json();

// Update the collection data in the database
const { data, error } = await supabase
.from('collections')
.update({ is_public: is_public })
.match({ collection_id });

if (error) {
console.error('Error updating collection data in database:', error.message);
return NextResponse.json({ error: error.message }, { status: 500 });
}

// console.log('Updated collection:', data);

// Delete the collection requests data in the database (Since it is manually updated by Admin)
const { data: delData, error: delError } = await supabase
.from('collection_requests')
.delete()
.match({ collection_id });

if (delError) {
console.error('Error deleting collection requests data in database:', delError.message);
return NextResponse.json({ error: delError.message }, { status: 500 });
}

// console.log('Deleted collection requests:', delData);

return NextResponse.json({ message: 'Collection updated successfully' });
}
8 changes: 4 additions & 4 deletions frontend/app/api/profile/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ export async function DELETE(request: NextRequest) {
// Convert collectionIds to an array of strings with only the collection_id values
const collectionIdsArray = collectionIds.map((collection: any) => collection.collection_id);

console.log('collectionIdsArray:', collectionIdsArray);
// console.log('collectionIdsArray:', collectionIdsArray);

// Log the request body before sending the POST request
console.log('Request Body:', JSON.stringify({ collection_ids: collectionIdsArray }));
// console.log('Request Body:', JSON.stringify({ collection_ids: collectionIdsArray }));

// Delete the user's collection data from vecs schema via POST request to Backend API
const deleteVecsResponse = await fetch(`${process.env.DELETE_MULTI_COLLECTION_API}`, {
Expand All @@ -148,7 +148,7 @@ export async function DELETE(request: NextRequest) {
return NextResponse.json({ error: deleteVecsResponse.statusText }, { status: deleteVecsResponse.status });
}

// Delete the user's profile data from users table in next_auth schema (and all related data via cascaded delete for tables in both publicand next_auth schema)
// Delete the user's profile data from users table in next_auth schema (and all related data via cascaded delete for tables in both public and next_auth schema)
const { data: deletedUserData, error: deleteError } = await supabaseAuth
.from('users')
.delete()
Expand All @@ -161,7 +161,7 @@ export async function DELETE(request: NextRequest) {
return NextResponse.json({ error: deleteError.message }, { status: 500 });
}

console.log('deletedUserData:', deletedUserData, 'collectionIds:', collectionIdsArray, 'deleteVecsResponse:', deleteVecsResponse);
// console.log('deletedUserData:', deletedUserData, 'collectionIds:', collectionIdsArray, 'deleteVecsResponse:', deleteVecsResponse);

return NextResponse.json({ deletedUserData });
}
68 changes: 34 additions & 34 deletions frontend/app/api/user/collections-requests/route.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createClient } from '@supabase/supabase-js';
import { NextRequest, NextResponse } from "next/server";

// GET request to retrieve the user's public collections requests data from the database
// GET request to retrieve the user's collections requests data from the database
export async function GET(request: NextRequest) {
// Retrieve the session token from the request cookies
const session = request.cookies.get('next-auth.session-token') || request.cookies.get('__Secure-next-auth.session-token');
Expand Down Expand Up @@ -33,23 +33,23 @@ export async function GET(request: NextRequest) {
return NextResponse.json({ error: sessionError.message }, { status: 500 });
}

// Retrieve the user's collections and public collections requests data via inner join from the database
const { data: userPubCollectionsReq, error: userPubCollErr } = await supabase
// Retrieve the user's collections and collections requests data via inner join from the database
const { data: userCollectionsReq, error: userCollErr } = await supabase
.from('collections')
.select('collection_id, display_name, description, is_public, created_at, public_collections_requests (collection_id, is_make_public, is_pending, is_approved, created_at, updated_at)')
.select('collection_id, display_name, description, is_public, created_at, collections_requests (collection_id, is_make_public, is_pending, is_approved, created_at, updated_at)')
.eq('id', userId);

if (userPubCollErr) {
console.error('Error fetching user public collections requests data from database:', userPubCollErr.message);
return NextResponse.json({ error: userPubCollErr.message }, { status: 500 });
if (userCollErr) {
console.error('Error fetching user collections requests data from database:', userCollErr.message);
return NextResponse.json({ error: userCollErr.message }, { status: 500 });
}

// console.log('User Public Collections Requests:', userPubCollectionsReq.map(item => item.public_collections_requests));
// console.log('User Collections Requests:', userCollectionsReq);

return NextResponse.json({ userPubCollectionsReq: userPubCollectionsReq });
return NextResponse.json({ userCollectionsReq: userCollectionsReq });
}

// POST request to insert the user's public collections request data into the database if not exist (Used by user)
// POST request to insert the user's collections request data into the database if not exist (Used by user)
export async function POST(request: NextRequest) {
// Create a new Supabase client
const supabase = createClient(
Expand All @@ -62,21 +62,21 @@ export async function POST(request: NextRequest) {
const { collection_id, is_make_public } = await request?.json();

// Insert the user's public collections request data into the database
const { data: newUserPubCollectionsReq, error: newUserPubCollErr } = await supabase
.from('public_collections_requests')
const { data: newUserCollectionsReq, error: newUserCollErr } = await supabase
.from('collections_requests')
.insert([{ collection_id, is_make_public }]);

if (newUserPubCollErr) {
console.error('Error inserting user public collections request data into database:', newUserPubCollErr.message);
return NextResponse.json({ error: newUserPubCollErr.message }, { status: 500 });
if (newUserCollErr) {
console.error('Error inserting user collections request data into database:', newUserCollErr.message);
return NextResponse.json({ error: newUserCollErr.message }, { status: 500 });
}

// console.log('User Public Collections Requests:', userPubCollectionsReq);
// console.log('Insert User Collections Requests:', userCollectionsReq);

return NextResponse.json({ newUserPubCollectionsReq });
return NextResponse.json({ newUserCollectionsReq });
}

// PUT request to update the user's public collections request data in the database (Used by user)
// PUT request to update the user's collections request data in the database (Used by user)
export async function PUT(request: NextRequest) {
// Create a new Supabase client
const supabase = createClient(
Expand All @@ -89,22 +89,22 @@ export async function PUT(request: NextRequest) {
const { collection_id, is_make_public } = await request?.json();

// Update the user's public collections request data in the database, set is_pending = true
const { data: updatedUserPubCollectionsReq, error: updatedUserPubCollErr } = await supabase
.from('public_collections_requests')
const { data: updatedUserCollectionsReq, error: updatedUserCollErr } = await supabase
.from('collections_requests')
.update({ is_make_public: is_make_public, is_pending: true, is_approved: false })
.eq('collection_id', collection_id);

if (updatedUserPubCollErr) {
console.error('Error updating user public collections request data in database:', updatedUserPubCollErr.message);
return NextResponse.json({ error: updatedUserPubCollErr.message }, { status: 500 });
if (updatedUserCollErr) {
console.error('Error updating user collections request data in database:', updatedUserCollErr.message);
return NextResponse.json({ error: updatedUserCollErr.message }, { status: 500 });
}

// console.log('User Public Collections Requests:', userPubCollectionsReq);
// console.log('Update User Collections Requests:', userCollectionsReq);

return NextResponse.json({ updatedUserPubCollectionsReq });
return NextResponse.json({ updatedUserCollectionsReq });
}

// DELETE request to delete the user's public collections request data from the database
// DELETE request to delete the user's collections request data from the database
export async function DELETE(request: NextRequest) {
// Create a new Supabase client
const supabase = createClient(
Expand All @@ -116,18 +116,18 @@ export async function DELETE(request: NextRequest) {
// Retrieve the collection_id from the request body
const { collection_id } = await request?.json();

// Delete the user's public collections request data from the database
const { data: deletedUserPubCollectionsReq, error: deletedUserPubCollErr } = await supabase
.from('public_collections_requests')
// Delete the user's collections request data from the database
const { data: deletedUserCollectionsReq, error: deletedUserCollErr } = await supabase
.from('collections_requests')
.delete()
.eq('collection_id', collection_id);

if (deletedUserPubCollErr) {
console.error('Error deleting user public collections request data from database:', deletedUserPubCollErr.message);
return NextResponse.json({ error: deletedUserPubCollErr.message }, { status: 500 });
if (deletedUserCollErr) {
console.error('Error deleting user collections request data from database:', deletedUserCollErr.message);
return NextResponse.json({ error: deletedUserCollErr.message }, { status: 500 });
}

// console.log('User Public Collections Requests:', userPubCollectionsReq);
// console.log('Delete User Collections Requests:', userCollectionsReq);

return NextResponse.json({ deletedUserPubCollectionsReq });
return NextResponse.json({ deletedUserCollectionsReq });
}
4 changes: 2 additions & 2 deletions frontend/app/api/user/collections/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export async function POST(request: NextRequest) {
return NextResponse.json({ error: insertError.message }, { status: 500 });
}

console.log('Collection data inserted:', insertData);
// console.log('Collection data inserted:', insertData);

return NextResponse.json({ message: 'Collection data inserted successfully.', collectionId: insertData[0].collection_id });
}
Expand Down Expand Up @@ -177,7 +177,7 @@ export async function DELETE(request: NextRequest) {
return NextResponse.json({ error: deleteError.message }, { status: 500 });
}

console.log('Delete', collection_id, ':', deleteData, 'deleteVecsResponse:', deleteVecsResponse);
// console.log('Delete', collection_id, ':', deleteData, 'deleteVecsResponse:', deleteVecsResponse);

return NextResponse.json({ message: 'Collection data deleted successfully.' });
}
Loading
Loading