Skip to content

Commit dbdc871

Browse files
Merge pull request #55 from gonzo-engineering/collections-and-mixtapes
2 parents 5e4a9e3 + 9f3a58d commit dbdc871

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+1196
-418
lines changed

api/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@
3838
"stripe": "^19.1.0",
3939
"music-metadata": "^11.9.0"
4040
}
41-
}
41+
}

api/src/routes/artists/+server.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
import { TABLES } from '../../../../shared/config';
22
import { handlePostgrestQuery, supabase } from '$lib/server/supabase';
3-
import type { ArtistRaw } from '../../../../shared/types';
3+
import type { Artist } from '../../../../shared/types/core';
44

55
export async function GET() {
6-
return handlePostgrestQuery<ArtistRaw[]>(
7-
async () => await supabase.from(TABLES.artists).select(),
8-
{
9-
transform: (data) => data.sort((a, b) => a.name.localeCompare(b.name))
10-
}
11-
);
6+
return handlePostgrestQuery<Artist[]>(async () => await supabase.from(TABLES.artists).select(), {
7+
transform: (data) => data.sort((a, b) => a.name.localeCompare(b.name))
8+
});
129
}
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
import { TABLES } from '../../../../../shared/config';
22
import { handlePostgrestQuery, supabase } from '$lib/server/supabase';
3-
import type { ArtistRaw } from '../../../../../shared/types';
3+
import type { Artist } from '../../../../../shared/types/core';
44

55
export async function GET({ params }) {
6-
return handlePostgrestQuery<ArtistRaw>(
7-
async () => await supabase.from(TABLES.artists).select().eq('id', params.slug).single()
6+
return handlePostgrestQuery<Artist>(
7+
async () => await supabase.from(TABLES.artists).select().eq('id', params.slug).single(),
8+
{ errorMessage: 'Failed to fetch artist' }
89
);
910
}
1011

1112
export async function PATCH({ request, params }) {
12-
const body: Partial<ArtistRaw> = await request.json();
13-
return handlePostgrestQuery<ArtistRaw>(
14-
async () => await supabase.from(TABLES.artists).update(body).eq('id', params.slug)
13+
const body: Partial<Artist> = await request.json();
14+
return handlePostgrestQuery<Artist>(
15+
async () => await supabase.from(TABLES.artists).update(body).eq('id', params.slug),
16+
{ errorMessage: 'Failed to update artist details' }
1517
);
1618
}
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { TABLES } from '../../../../../../shared/config';
21
import { handlePostgrestQuery, supabase } from '$lib/server/supabase';
3-
import type { ReleaseHydrated } from '../../../../../../shared/types';
2+
import { TABLES } from '../../../../../../shared/config';
3+
import type { ReleaseHydrated } from '../../../../../../shared/types/hydrated';
44

55
export async function GET({ params }) {
66
return handlePostgrestQuery<ReleaseHydrated[]>(
7-
async () => await supabase.from(TABLES.releasesHydrated).select().eq('artist_id', params.slug)
7+
async () => await supabase.from(TABLES.releasesRich).select().eq('artist_id', params.slug),
8+
{ errorMessage: 'Failed to fetch releases for artist' }
89
);
910
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { supabase } from '$lib/server/supabase';
2+
import { json } from '@sveltejs/kit';
3+
import { TABLES } from '../../../../shared/config';
4+
5+
export async function POST({ request }) {
6+
const { userId, name, description } = await request.json();
7+
8+
if (!name) {
9+
return json({ error: 'Missing collection name' }, { status: 400 });
10+
}
11+
12+
const { error } = await supabase
13+
.from(TABLES.collections)
14+
.insert({ user_id: userId, name, description });
15+
16+
if (error) {
17+
return json({ error: 'Failed to create collection' }, { status: 500 });
18+
}
19+
20+
return json({ success: true });
21+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { handlePostgrestQuery, supabase } from '$lib/server/supabase';
2+
import { json } from '@sveltejs/kit';
3+
import { TABLES } from '../../../../../shared/config';
4+
5+
export async function GET({ params }) {
6+
return handlePostgrestQuery(
7+
async () => supabase.from(TABLES.collectionsRich).select('*').eq('id', params.slug).single(),
8+
{ errorMessage: 'Failed to fetch collection' }
9+
);
10+
}
11+
12+
export async function PATCH({ request, params }) {
13+
const collectionId = params.slug;
14+
const { releaseId, addOrRemove } = await request.json();
15+
16+
if (!releaseId) {
17+
return json({ error: 'Missing release ID' }, { status: 400 });
18+
}
19+
20+
if (addOrRemove === 'remove') {
21+
const { error } = await supabase
22+
.from(TABLES.collectionReleases)
23+
.delete()
24+
.eq('collection_id', collectionId)
25+
.eq('release_id', releaseId);
26+
27+
if (error) {
28+
console.error('Error removing release from collection:', error);
29+
return json({ error: 'Failed to remove release from collection' }, { status: 500 });
30+
}
31+
32+
return json({ success: true });
33+
}
34+
35+
const { error } = await supabase
36+
.from(TABLES.collectionReleases)
37+
.insert({ collection_id: collectionId, release_id: releaseId });
38+
39+
if (error) {
40+
console.error('Error adding release to collection:', error);
41+
return json({ error: 'Failed to add release to collection' }, { status: 500 });
42+
}
43+
44+
return json({ success: true });
45+
}
46+
47+
export async function DELETE({ request, params }) {
48+
const collectionId = params.slug;
49+
const { userId } = await request.json();
50+
51+
const { error } = await supabase
52+
.from(TABLES.collections)
53+
.delete()
54+
.eq('id', collectionId)
55+
.eq('user_id', userId);
56+
57+
if (error) {
58+
console.error('Error deleting collection:', error);
59+
return json({ error: 'Failed to delete collection' }, { status: 500 });
60+
}
61+
62+
return json({ success: true });
63+
}

api/src/routes/mixtapes/+server.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { supabase } from '$lib/server/supabase';
2+
import { json } from '@sveltejs/kit';
3+
import { TABLES } from '../../../../shared/config';
4+
5+
export async function POST({ request }) {
6+
const { userId, name, description } = await request.json();
7+
8+
if (!name) {
9+
console.log('Mixtape name is missing');
10+
return json({ error: 'Missing mixtape name' }, { status: 400 });
11+
}
12+
13+
const { error } = await supabase
14+
.from(TABLES.mixtapes)
15+
.insert({ user_id: userId, name, description });
16+
17+
if (error) {
18+
console.log('Error creating mixtape:', error);
19+
return json({ error: 'Failed to create mixtape' }, { status: 500 });
20+
}
21+
22+
return json({ success: true });
23+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { handlePostgrestQuery, supabase } from '$lib/server/supabase';
2+
import { json } from '@sveltejs/kit';
3+
import { TABLES } from '../../../../../shared/config';
4+
5+
export async function GET({ params }) {
6+
return handlePostgrestQuery(
7+
async () => supabase.from(TABLES.mixtapesRich).select('*').eq('id', params.slug).single(),
8+
{ errorMessage: 'Failed to fetch mixtape' }
9+
);
10+
}
11+
12+
export async function PATCH({ request, params }) {
13+
const mixtapeId = params.slug;
14+
const { trackId } = await request.json();
15+
16+
if (!trackId) {
17+
return json({ error: 'Missing track ID' }, { status: 400 });
18+
}
19+
20+
const { error } = await supabase
21+
.from(TABLES.mixtapeTracks)
22+
.insert({ mixtape_id: mixtapeId, track_id: trackId });
23+
24+
if (error) {
25+
return json({ error: 'Failed to add track to mixtape' }, { status: 500 });
26+
}
27+
28+
return json({ success: true });
29+
}
30+
31+
export const DELETE = async ({ request, params }) => {
32+
const mixtapeId = params.slug;
33+
const { userId } = await request.json();
34+
35+
const { error } = await supabase
36+
.from(TABLES.mixtapes)
37+
.delete()
38+
.eq('id', mixtapeId)
39+
.eq('user_id', userId);
40+
41+
if (error) {
42+
console.error('Error deleting mixtape:', error);
43+
return json({ error: 'Failed to delete mixtape' }, { status: 500 });
44+
}
45+
46+
return json({ success: true });
47+
};

api/src/routes/releases/+server.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { handlePostgrestQuery, supabase } from '$lib/server/supabase';
22
import { TABLES } from '../../../../shared/config';
33
import { sortReleasesByDate } from '../../../../shared/utils';
4-
import type { ReleaseHydrated, ReleaseRaw } from '../../../../shared/types';
4+
import type { ReleaseHydrated } from '../../../../shared/types/hydrated';
55
import { pinata } from '$lib/server/pinata';
66
import { json } from '@sveltejs/kit';
7+
import type { Release } from '../../../../shared/types/core';
78

89
export async function GET() {
910
return handlePostgrestQuery<ReleaseHydrated[]>(
10-
async () => await supabase.from(TABLES.releasesHydrated).select(),
11+
async () => await supabase.from(TABLES.releasesRich).select(),
1112
{
1213
errorMessage: 'Failed to fetch artist data',
1314
transform: sortReleasesByDate
@@ -31,7 +32,7 @@ export async function POST({ request }) {
3132
.name(`'${releaseName}' cover art`)
3233
.group(import.meta.env.PINATA_ARTWORK_GROUP);
3334

34-
return handlePostgrestQuery<ReleaseRaw>(
35+
return handlePostgrestQuery<Release>(
3536
async () =>
3637
await supabase
3738
.from(TABLES.releases)
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { TABLES } from '../../../../../shared/config';
21
import { handlePostgrestQuery, supabase } from '$lib/server/supabase';
3-
import type { ReleaseHydrated } from '../../../../../shared/types';
2+
import { TABLES } from '../../../../../shared/config';
3+
import type { ReleaseHydrated } from '../../../../../shared/types/hydrated';
44

55
export async function GET({ params }) {
66
return handlePostgrestQuery<ReleaseHydrated>(
7-
async () => await supabase.from(TABLES.releasesHydrated).select().eq('id', params.slug).single()
7+
async () => await supabase.from(TABLES.releasesRich).select().eq('id', params.slug).single(),
8+
{ errorMessage: 'Failed to fetch release' }
89
);
910
}

0 commit comments

Comments
 (0)