Skip to content

Commit d5b6cc0

Browse files
Big ol' types rejig (and collection pages)
1 parent f91cf57 commit d5b6cc0

Some content is hidden

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

58 files changed

+458
-417
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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
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>(
6+
return handlePostgrestQuery<Artist>(
77
async () => await supabase.from(TABLES.artists).select().eq('id', params.slug).single()
88
);
99
}
1010

1111
export async function PATCH({ request, params }) {
12-
const body: Partial<ArtistRaw> = await request.json();
13-
return handlePostgrestQuery<ArtistRaw>(
12+
const body: Partial<Artist> = await request.json();
13+
return handlePostgrestQuery<Artist>(
1414
async () => await supabase.from(TABLES.artists).update(body).eq('id', params.slug)
1515
);
1616
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
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)
88
);
99
}
Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
1-
import { supabase } from "$lib/server/supabase";
2-
import { json } from "@sveltejs/kit";
3-
import { TABLES } from "../../../../shared/config";
1+
import { supabase } from '$lib/server/supabase';
2+
import { json } from '@sveltejs/kit';
3+
import { TABLES } from '../../../../shared/config';
44

55
export async function POST({ request }) {
6-
const { userId, name, description } = await request.json();
6+
const { userId, name, description } = await request.json();
77

8-
if (!name) {
9-
return json({ error: 'Missing collection name' }, { status: 400 });
10-
}
8+
if (!name) {
9+
return json({ error: 'Missing collection name' }, { status: 400 });
10+
}
1111

12-
const { error } = await supabase.from(TABLES.collections).insert({ user_id: userId, name, description });
12+
const { error } = await supabase
13+
.from(TABLES.collections)
14+
.insert({ user_id: userId, name, description });
1315

14-
if (error) {
15-
return json({ error: 'Failed to create collection' }, { status: 500 });
16-
}
16+
if (error) {
17+
return json({ error: 'Failed to create collection' }, { status: 500 });
18+
}
1719

18-
return json({ success: true });
19-
}
20+
return json({ success: true });
21+
}

api/src/routes/collections/[slug]/+server.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,22 @@ import { supabase } from '$lib/server/supabase';
22
import { json } from '@sveltejs/kit';
33
import { TABLES } from '../../../../../shared/config';
44

5+
export async function GET({ params }) {
6+
const collectionId = params.slug;
7+
const { data: collection, error } = await supabase
8+
.from(TABLES.collectionsRich)
9+
.select('*')
10+
.eq('id', collectionId)
11+
.single();
12+
13+
if (error) {
14+
console.error('Error fetching collection:', error);
15+
return json({ error: 'Failed to fetch collection' }, { status: 500 });
16+
}
17+
18+
return json(collection);
19+
}
20+
521
export async function PATCH({ request, params }) {
622
const collectionId = params.slug;
723
const { releaseId, addOrRemove } = await request.json();
@@ -39,7 +55,7 @@ export async function PATCH({ request, params }) {
3955

4056
export async function DELETE({ request, params }) {
4157
const collectionId = params.slug;
42-
const { userId} = await request.json();
58+
const { userId } = await request.json();
4359

4460
const { error } = await supabase
4561
.from(TABLES.collections)
@@ -53,4 +69,4 @@ export async function DELETE({ request, params }) {
5369
}
5470

5571
return json({ success: true });
56-
};
72+
}

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

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
1-
import { supabase } from "$lib/server/supabase";
2-
import { json } from "@sveltejs/kit";
3-
import { TABLES } from "../../../../shared/config";
1+
import { supabase } from '$lib/server/supabase';
2+
import { json } from '@sveltejs/kit';
3+
import { TABLES } from '../../../../shared/config';
44

55
export async function POST({ request }) {
6-
const { userId, name, description } = await request.json();
6+
const { userId, name, description } = await request.json();
77

8-
if (!name) {
9-
console.log('Mixtape name is missing');
10-
return json({ error: 'Missing mixtape name' }, { status: 400 });
11-
}
8+
if (!name) {
9+
console.log('Mixtape name is missing');
10+
return json({ error: 'Missing mixtape name' }, { status: 400 });
11+
}
1212

13-
const { error } = await supabase.from(TABLES.mixtapesHydrated).insert({ user_id: userId, name, description });
13+
const { error } = await supabase
14+
.from(TABLES.mixtapesRich)
15+
.insert({ user_id: userId, name, description });
1416

15-
if (error) {
16-
console.log('Error creating mixtape:', error);
17-
return json({ error: 'Failed to create mixtape' }, { status: 500 });
18-
}
17+
if (error) {
18+
console.log('Error creating mixtape:', error);
19+
return json({ error: 'Failed to create mixtape' }, { status: 500 });
20+
}
1921

20-
return json({ success: true });
21-
}
22+
return json({ success: true });
23+
}
Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,38 @@
1-
import { supabase } from "$lib/server/supabase";
2-
import { json } from "@sveltejs/kit";
3-
import { TABLES } from "../../../../../shared/config";
1+
import { supabase } from '$lib/server/supabase';
2+
import { json } from '@sveltejs/kit';
3+
import { TABLES } from '../../../../../shared/config';
44

55
export async function PATCH({ request, params }) {
6-
const mixtapeId = params.slug;
7-
const { trackId } = await request.json();
6+
const mixtapeId = params.slug;
7+
const { trackId } = await request.json();
88

9-
if (!trackId) {
10-
return json({ error: 'Missing track ID' }, { status: 400 });
11-
}
9+
if (!trackId) {
10+
return json({ error: 'Missing track ID' }, { status: 400 });
11+
}
1212

13-
const { error } = await supabase
14-
.from(TABLES.mixtapeTracks)
15-
.insert({ mixtape_id: mixtapeId, track_id: trackId });
13+
const { error } = await supabase
14+
.from(TABLES.mixtapeTracks)
15+
.insert({ mixtape_id: mixtapeId, track_id: trackId });
1616

17-
if (error) {
18-
return json({ error: 'Failed to add track to mixtape' }, { status: 500 });
19-
}
17+
if (error) {
18+
return json({ error: 'Failed to add track to mixtape' }, { status: 500 });
19+
}
2020

21-
return json({ success: true });
22-
}
21+
return json({ success: true });
22+
}
23+
24+
export async function GET({ params }) {
25+
const mixtapeId = params.slug;
26+
const { data: mixtape, error } = await supabase
27+
.from(TABLES.mixtapesRich)
28+
.select('*')
29+
.eq('id', mixtapeId)
30+
.single();
31+
32+
if (error) {
33+
console.error('Error fetching mixtape tracks:', error);
34+
return json({ error: 'Failed to fetch mixtape tracks' }, { status: 500 });
35+
}
36+
37+
return json(mixtape);
38+
}

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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
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()
88
);
99
}

0 commit comments

Comments
 (0)