rhythia-api 175.0.0 → 176.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.
@@ -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
- createdAt: z.string().nullable().optional(),
18
- updatedAt: z.string().nullable().optional(),
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
- // First get all collections
36
- let { data: collections, error: collectionsError } = await supabase
37
- .from("beatmapCollections")
38
- .select(
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
- Array<{
49
+ {
46
50
  id: number;
47
51
  title: string;
48
52
  description: string;
49
- created_at: string | null;
50
- updated_at: string | null;
51
- collectionRelations: Array<{ count: number }>;
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 (collectionsError) {
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.collectionRelations?.[0]?.count ?? 0,
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
@@ -491,6 +491,8 @@ export const getCollection = handleApi({url:"/api/getCollection",...GetCollectio
491
491
  export const Schema = {
492
492
  input: z.strictObject({
493
493
  session: z.string(),
494
+ page: z.number().optional().default(1),
495
+ itemsPerPage: z.number().optional().default(10),
494
496
  }),
495
497
  output: z.object({
496
498
  collections: z.array(
@@ -499,10 +501,16 @@ export const Schema = {
499
501
  title: z.string(),
500
502
  description: z.string(),
501
503
  beatmapCount: z.number(),
502
- createdAt: z.string().nullable().optional(),
503
- updatedAt: z.string().nullable().optional(),
504
+ starRatingDistribution: z.array(
505
+ z.object({
506
+ stars: z.number(),
507
+ count: z.number(),
508
+ })
509
+ ),
510
+ createdAt: z.string(),
504
511
  })
505
512
  ),
513
+ totalPages: z.number(),
506
514
  error: z.string().optional(),
507
515
  }),
508
516
  };*/
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rhythia-api",
3
- "version": "175.0.0",
3
+ "version": "176.0.0",
4
4
  "main": "index.ts",
5
5
  "author": "online-contributors",
6
6
  "scripts": {
package/types/database.ts CHANGED
@@ -505,7 +505,30 @@ export type Database = {
505
505
  [_ in never]: never
506
506
  }
507
507
  Functions: {
508
- [_ in never]: never
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"