Skip to content

Commit 9f3a58d

Browse files
Tidying
Of sorts
1 parent d5b6cc0 commit 9f3a58d

File tree

17 files changed

+187
-114
lines changed

17 files changed

+187
-114
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ import type { Artist } from '../../../../../shared/types/core';
44

55
export async function GET({ params }) {
66
return handlePostgrestQuery<Artist>(
7-
async () => await supabase.from(TABLES.artists).select().eq('id', params.slug).single()
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 }) {
1213
const body: Partial<Artist> = await request.json();
1314
return handlePostgrestQuery<Artist>(
14-
async () => await supabase.from(TABLES.artists).update(body).eq('id', params.slug)
15+
async () => await supabase.from(TABLES.artists).update(body).eq('id', params.slug),
16+
{ errorMessage: 'Failed to update artist details' }
1517
);
1618
}

api/src/routes/artists/[slug]/releases/+server.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { ReleaseHydrated } from '../../../../../../shared/types/hydrated';
44

55
export async function GET({ params }) {
66
return handlePostgrestQuery<ReleaseHydrated[]>(
7-
async () => await supabase.from(TABLES.releasesRich).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
}

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

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

55
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);
6+
return handlePostgrestQuery(
7+
async () => supabase.from(TABLES.collectionsRich).select('*').eq('id', params.slug).single(),
8+
{ errorMessage: 'Failed to fetch collection' }
9+
);
1910
}
2011

2112
export async function PATCH({ request, params }) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export async function POST({ request }) {
1111
}
1212

1313
const { error } = await supabase
14-
.from(TABLES.mixtapesRich)
14+
.from(TABLES.mixtapes)
1515
.insert({ user_id: userId, name, description });
1616

1717
if (error) {

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

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1-
import { supabase } from '$lib/server/supabase';
1+
import { handlePostgrestQuery, 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+
return handlePostgrestQuery(
7+
async () => supabase.from(TABLES.mixtapesRich).select('*').eq('id', params.slug).single(),
8+
{ errorMessage: 'Failed to fetch mixtape' }
9+
);
10+
}
11+
512
export async function PATCH({ request, params }) {
613
const mixtapeId = params.slug;
714
const { trackId } = await request.json();
@@ -21,18 +28,20 @@ export async function PATCH({ request, params }) {
2128
return json({ success: true });
2229
}
2330

24-
export async function GET({ params }) {
31+
export const DELETE = async ({ request, params }) => {
2532
const mixtapeId = params.slug;
26-
const { data: mixtape, error } = await supabase
27-
.from(TABLES.mixtapesRich)
28-
.select('*')
33+
const { userId } = await request.json();
34+
35+
const { error } = await supabase
36+
.from(TABLES.mixtapes)
37+
.delete()
2938
.eq('id', mixtapeId)
30-
.single();
39+
.eq('user_id', userId);
3140

3241
if (error) {
33-
console.error('Error fetching mixtape tracks:', error);
34-
return json({ error: 'Failed to fetch mixtape tracks' }, { status: 500 });
42+
console.error('Error deleting mixtape:', error);
43+
return json({ error: 'Failed to delete mixtape' }, { status: 500 });
3544
}
3645

37-
return json(mixtape);
38-
}
46+
return json({ success: true });
47+
};

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { ReleaseHydrated } from '../../../../../shared/types/hydrated';
44

55
export async function GET({ params }) {
66
return handlePostgrestQuery<ReleaseHydrated>(
7-
async () => await supabase.from(TABLES.releasesRich).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
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { supabase } from '$lib/server/supabase';
2-
import type { SearchResult } from '../../../../shared/types';
2+
import type { SearchResult } from '../../../../shared/types/core';
33
import type { RequestHandler } from './$types';
44
import { json } from '@sveltejs/kit';
55

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,9 @@
1-
import { supabase } from '$lib/server/supabase';
2-
import { json } from '@sveltejs/kit';
1+
import { handlePostgrestQuery, supabase } from '$lib/server/supabase';
32
import { TABLES } from '../../../../../../shared/config/index';
43

54
export async function GET({ params }) {
6-
const userId = params.slug;
7-
const { data: collections, error } = await supabase
8-
.from(TABLES.collectionsRich)
9-
.select('*')
10-
.eq('user_id', userId);
11-
12-
if (error) {
13-
console.error('Error fetching collections:', error);
14-
return json({ error: 'Failed to fetch collections' }, { status: 500 });
15-
}
16-
17-
return json(collections);
5+
return handlePostgrestQuery(
6+
async () => supabase.from(TABLES.collectionsRich).select('*').eq('user_id', params.slug),
7+
{ errorMessage: 'Failed to fetch collections' }
8+
);
189
}
Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,9 @@
1-
import { supabase } from '$lib/server/supabase';
2-
import { json } from '@sveltejs/kit';
1+
import { handlePostgrestQuery, supabase } from '$lib/server/supabase';
32
import { TABLES } from '../../../../../../shared/config';
43

54
export async function GET({ params }) {
6-
const userId = params.slug;
7-
const { data: mixtapes, error } = await supabase
8-
.from(TABLES.mixtapesRich)
9-
.select('*')
10-
.eq('user_id', userId);
11-
12-
if (error) {
13-
console.error('Error fetching mixtapes:', error);
14-
return json({ error: 'Failed to fetch mixtapes' }, { status: 500 });
15-
}
16-
17-
return json(mixtapes);
5+
return handlePostgrestQuery(
6+
async () => supabase.from(TABLES.mixtapesRich).select('*').eq('user_id', params.slug),
7+
{ errorMessage: 'Failed to fetch mixtapes' }
8+
);
189
}

app/src/lib/components/audio-player/AudioPlayer.svelte

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,11 @@
3838
</script>
3939

4040
<div class="audio-player">
41-
<div>
42-
“{track.title}” by <a href={`/artists/${release.artist_id}`}>{release.artist.name}</a>
41+
<div class="now-playing-info">
42+
<div>
43+
“{track.title}” by <a href={`/artists/${release.artist_id}`}>{release.artist.name}</a>
44+
</div>
45+
<TrackLikeButton trackID={track.id} {likedTracks} lightOrDark={'dark'} />
4346
</div>
4447
<audio
4548
src={songUrl}
@@ -67,7 +70,6 @@
6770
autoplay
6871
controlsList="nodownload noplaybackrate"
6972
></audio>
70-
<TrackLikeButton trackID={track.id} {likedTracks} lightOrDark={'dark'} />
7173
</div>
7274

7375
<style>
@@ -88,6 +90,12 @@
8890
a {
8991
color: black;
9092
}
93+
.now-playing-info {
94+
display: flex;
95+
flex-direction: row;
96+
align-items: center;
97+
gap: 0.5rem;
98+
}
9199
@media (min-width: 600px) {
92100
.audio-player {
93101
flex-direction: row;

0 commit comments

Comments
 (0)