rhythia-api 175.0.0 → 177.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/api/addCollectionMap.ts +12 -0
- package/api/createCollection.ts +13 -6
- package/api/getCollections.ts +48 -19
- package/index.ts +11 -2
- package/package.json +1 -1
- package/types/database.ts +24 -1
package/api/addCollectionMap.ts
CHANGED
|
@@ -37,6 +37,18 @@ export async function handler(data: (typeof Schema)["input"]["_type"]) {
|
|
|
37
37
|
return NextResponse.json({ error: "Can't find user" });
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
let { data: queryCollectionRelation, error: collectionRelationError } =
|
|
41
|
+
await supabase
|
|
42
|
+
.from("collectionRelations")
|
|
43
|
+
.select("*")
|
|
44
|
+
.eq("collection", data.collection)
|
|
45
|
+
.eq("beatmapPage", data.beatmapPage)
|
|
46
|
+
.single();
|
|
47
|
+
|
|
48
|
+
if (queryCollectionRelation) {
|
|
49
|
+
return NextResponse.json({ error: "Map already in collection" });
|
|
50
|
+
}
|
|
51
|
+
|
|
40
52
|
let { data: queryCollectionData, error: collectionError } = await supabase
|
|
41
53
|
.from("beatmapCollections")
|
|
42
54
|
.select("*")
|
package/api/createCollection.ts
CHANGED
|
@@ -11,6 +11,7 @@ export const Schema = {
|
|
|
11
11
|
title: z.string(),
|
|
12
12
|
}),
|
|
13
13
|
output: z.object({
|
|
14
|
+
id: z.number(),
|
|
14
15
|
error: z.string().optional(),
|
|
15
16
|
}),
|
|
16
17
|
};
|
|
@@ -36,11 +37,17 @@ export async function handler(data: (typeof Schema)["input"]["_type"]) {
|
|
|
36
37
|
return NextResponse.json({ error: "Can't find user" });
|
|
37
38
|
}
|
|
38
39
|
|
|
39
|
-
await supabase
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
const inserted = await supabase
|
|
41
|
+
.from("beatmapCollections")
|
|
42
|
+
.insert({
|
|
43
|
+
title: data.title,
|
|
44
|
+
description: "",
|
|
45
|
+
owner: queryUserData.id,
|
|
46
|
+
})
|
|
47
|
+
.select("*")
|
|
48
|
+
.single();
|
|
44
49
|
|
|
45
|
-
return NextResponse.json({
|
|
50
|
+
return NextResponse.json({
|
|
51
|
+
id: inserted.data!.id,
|
|
52
|
+
});
|
|
46
53
|
}
|
package/api/getCollections.ts
CHANGED
|
@@ -6,6 +6,8 @@ import { supabase } from "../utils/supabase";
|
|
|
6
6
|
export const Schema = {
|
|
7
7
|
input: z.strictObject({
|
|
8
8
|
session: z.string(),
|
|
9
|
+
page: z.number().optional().default(1),
|
|
10
|
+
itemsPerPage: z.number().optional().default(10),
|
|
9
11
|
}),
|
|
10
12
|
output: z.object({
|
|
11
13
|
collections: z.array(
|
|
@@ -14,10 +16,16 @@ export const Schema = {
|
|
|
14
16
|
title: z.string(),
|
|
15
17
|
description: z.string(),
|
|
16
18
|
beatmapCount: z.number(),
|
|
17
|
-
|
|
18
|
-
|
|
19
|
+
starRatingDistribution: z.array(
|
|
20
|
+
z.object({
|
|
21
|
+
stars: z.number(),
|
|
22
|
+
count: z.number(),
|
|
23
|
+
})
|
|
24
|
+
),
|
|
25
|
+
createdAt: z.string(),
|
|
19
26
|
})
|
|
20
27
|
),
|
|
28
|
+
totalPages: z.number(),
|
|
21
29
|
error: z.string().optional(),
|
|
22
30
|
}),
|
|
23
31
|
};
|
|
@@ -32,41 +40,62 @@ export async function POST(request: Request) {
|
|
|
32
40
|
}
|
|
33
41
|
|
|
34
42
|
export async function handler(data: (typeof Schema)["input"]["_type"]) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
*,
|
|
41
|
-
collectionRelations!left(count)
|
|
42
|
-
`
|
|
43
|
-
)
|
|
43
|
+
const { data: collections, error } = await supabase
|
|
44
|
+
.rpc("get_collections_v1", {
|
|
45
|
+
page_number: data.page,
|
|
46
|
+
items_per_page: data.itemsPerPage,
|
|
47
|
+
})
|
|
44
48
|
.returns<
|
|
45
|
-
|
|
49
|
+
{
|
|
46
50
|
id: number;
|
|
47
51
|
title: string;
|
|
48
52
|
description: string;
|
|
49
|
-
created_at: string
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
+
created_at: string;
|
|
54
|
+
beatmap_count: number;
|
|
55
|
+
star1: number;
|
|
56
|
+
star2: number;
|
|
57
|
+
star3: number;
|
|
58
|
+
star4: number;
|
|
59
|
+
star5: number;
|
|
60
|
+
star6: number;
|
|
61
|
+
star7: number;
|
|
62
|
+
star8: number;
|
|
63
|
+
star9: number;
|
|
64
|
+
star10: number;
|
|
65
|
+
total_pages: number;
|
|
66
|
+
}[]
|
|
53
67
|
>();
|
|
54
68
|
|
|
55
|
-
if (
|
|
69
|
+
if (error) {
|
|
56
70
|
return NextResponse.json({ error: "Error fetching collections" });
|
|
57
71
|
}
|
|
58
72
|
|
|
73
|
+
// Get the total pages from the first row (all rows will have the same value)
|
|
74
|
+
const totalPages = collections?.[0]?.total_pages ?? 1;
|
|
75
|
+
|
|
59
76
|
const formattedCollections =
|
|
60
77
|
collections?.map((collection) => ({
|
|
61
78
|
id: collection.id,
|
|
62
79
|
title: collection.title,
|
|
63
80
|
description: collection.description,
|
|
64
|
-
beatmapCount: collection.
|
|
81
|
+
beatmapCount: collection.beatmap_count,
|
|
82
|
+
starRatingDistribution: [
|
|
83
|
+
{ stars: 1, count: collection.star1 },
|
|
84
|
+
{ stars: 2, count: collection.star2 },
|
|
85
|
+
{ stars: 3, count: collection.star3 },
|
|
86
|
+
{ stars: 4, count: collection.star4 },
|
|
87
|
+
{ stars: 5, count: collection.star5 },
|
|
88
|
+
{ stars: 6, count: collection.star6 },
|
|
89
|
+
{ stars: 7, count: collection.star7 },
|
|
90
|
+
{ stars: 8, count: collection.star8 },
|
|
91
|
+
{ stars: 9, count: collection.star9 },
|
|
92
|
+
{ stars: 10, count: collection.star10 },
|
|
93
|
+
],
|
|
65
94
|
createdAt: collection.created_at,
|
|
66
|
-
updatedAt: collection.updated_at,
|
|
67
95
|
})) || [];
|
|
68
96
|
|
|
69
97
|
return NextResponse.json({
|
|
70
98
|
collections: formattedCollections,
|
|
99
|
+
totalPages,
|
|
71
100
|
});
|
|
72
101
|
}
|
package/index.ts
CHANGED
|
@@ -104,6 +104,7 @@ export const Schema = {
|
|
|
104
104
|
title: z.string(),
|
|
105
105
|
}),
|
|
106
106
|
output: z.object({
|
|
107
|
+
id: z.number(),
|
|
107
108
|
error: z.string().optional(),
|
|
108
109
|
}),
|
|
109
110
|
};*/
|
|
@@ -491,6 +492,8 @@ export const getCollection = handleApi({url:"/api/getCollection",...GetCollectio
|
|
|
491
492
|
export const Schema = {
|
|
492
493
|
input: z.strictObject({
|
|
493
494
|
session: z.string(),
|
|
495
|
+
page: z.number().optional().default(1),
|
|
496
|
+
itemsPerPage: z.number().optional().default(10),
|
|
494
497
|
}),
|
|
495
498
|
output: z.object({
|
|
496
499
|
collections: z.array(
|
|
@@ -499,10 +502,16 @@ export const Schema = {
|
|
|
499
502
|
title: z.string(),
|
|
500
503
|
description: z.string(),
|
|
501
504
|
beatmapCount: z.number(),
|
|
502
|
-
|
|
503
|
-
|
|
505
|
+
starRatingDistribution: z.array(
|
|
506
|
+
z.object({
|
|
507
|
+
stars: z.number(),
|
|
508
|
+
count: z.number(),
|
|
509
|
+
})
|
|
510
|
+
),
|
|
511
|
+
createdAt: z.string(),
|
|
504
512
|
})
|
|
505
513
|
),
|
|
514
|
+
totalPages: z.number(),
|
|
506
515
|
error: z.string().optional(),
|
|
507
516
|
}),
|
|
508
517
|
};*/
|
package/package.json
CHANGED
package/types/database.ts
CHANGED
|
@@ -505,7 +505,30 @@ export type Database = {
|
|
|
505
505
|
[_ in never]: never
|
|
506
506
|
}
|
|
507
507
|
Functions: {
|
|
508
|
-
|
|
508
|
+
get_collections_v1: {
|
|
509
|
+
Args: {
|
|
510
|
+
page_number?: number
|
|
511
|
+
items_per_page?: number
|
|
512
|
+
}
|
|
513
|
+
Returns: {
|
|
514
|
+
id: number
|
|
515
|
+
title: string
|
|
516
|
+
description: string
|
|
517
|
+
created_at: string
|
|
518
|
+
beatmap_count: number
|
|
519
|
+
star1: number
|
|
520
|
+
star2: number
|
|
521
|
+
star3: number
|
|
522
|
+
star4: number
|
|
523
|
+
star5: number
|
|
524
|
+
star6: number
|
|
525
|
+
star7: number
|
|
526
|
+
star8: number
|
|
527
|
+
star9: number
|
|
528
|
+
star10: number
|
|
529
|
+
total_pages: number
|
|
530
|
+
}[]
|
|
531
|
+
}
|
|
509
532
|
}
|
|
510
533
|
Enums: {
|
|
511
534
|
banTypes: "cool" | "silenced" | "restricted" | "excluded"
|