@@ -36,6 +36,9 @@ import {
36
36
ApiBody ,
37
37
ApiConsumes ,
38
38
ApiOperation ,
39
+ ApiParam ,
40
+ ApiQuery ,
41
+ ApiResponse ,
39
42
ApiTags ,
40
43
} from '@nestjs/swagger' ;
41
44
import type { Response } from 'express' ;
@@ -51,14 +54,10 @@ import { SongService } from './song.service';
51
54
@ApiTags ( 'song' )
52
55
export class SongController {
53
56
static multerConfig : MulterOptions = {
54
- limits : {
55
- fileSize : UPLOAD_CONSTANTS . file . maxSize ,
56
- } ,
57
+ limits : { fileSize : UPLOAD_CONSTANTS . file . maxSize } ,
57
58
fileFilter : ( req , file , cb ) => {
58
- if ( ! file . originalname . match ( / \. ( n b s ) $ / ) ) {
59
+ if ( ! file . originalname . match ( / \. ( n b s ) $ / ) )
59
60
return cb ( new Error ( 'Only .nbs files are allowed!' ) , false ) ;
60
- }
61
-
62
61
cb ( null , true ) ;
63
62
} ,
64
63
} ;
@@ -71,7 +70,89 @@ export class SongController {
71
70
72
71
@Get ( '/' )
73
72
@ApiOperation ( {
74
- summary : 'Get a filtered/sorted list of songs with pagination' ,
73
+ summary : 'Get songs with various filtering and browsing options' ,
74
+ description : `
75
+ Retrieves songs based on the provided query parameters. Supports multiple modes:
76
+
77
+ **Default mode** (no 'q' parameter): Returns paginated songs with sorting/filtering
78
+
79
+ **Special query modes** (using 'q' parameter):
80
+ - \`featured\`: Get recent popular songs with pagination
81
+ - \`recent\`: Get recently uploaded songs with pagination
82
+ - \`categories\`:
83
+ - Without 'id': Returns a record of available categories and their song counts
84
+ - With 'id': Returns songs from the specified category with pagination
85
+ - \`random\`: Returns random songs (requires 'count' parameter, 1-10 songs, optionally filtered by 'category')
86
+
87
+ **Query Parameters:**
88
+ - Standard pagination/sorting via PageQueryDTO (page, limit, sort, order, timespan)
89
+ - \`q\`: Special query mode ('featured', 'recent', 'categories', 'random')
90
+ - \`id\`: Category ID (used with q=categories to get songs from specific category)
91
+ - \`count\`: Number of random songs to return (1-10, used with q=random)
92
+ - \`category\`: Category filter for random songs (used with q=random)
93
+
94
+ **Return Types:**
95
+ - SongPreviewDto[]: Array of song previews (most cases)
96
+ - Record<string, number>: Category name to count mapping (when q=categories without id)
97
+ ` ,
98
+ } )
99
+ @ApiQuery ( {
100
+ name : 'q' ,
101
+ required : false ,
102
+ enum : [ 'featured' , 'recent' , 'categories' , 'random' ] ,
103
+ description :
104
+ 'Special query mode. If not provided, returns standard paginated song list.' ,
105
+ example : 'recent' ,
106
+ } )
107
+ @ApiParam ( {
108
+ name : 'id' ,
109
+ required : false ,
110
+ type : 'string' ,
111
+ description :
112
+ 'Category ID. Only used when q=categories to get songs from a specific category.' ,
113
+ example : 'pop' ,
114
+ } )
115
+ @ApiQuery ( {
116
+ name : 'count' ,
117
+ required : false ,
118
+ type : 'string' ,
119
+ description :
120
+ 'Number of random songs to return (1-10). Only used when q=random.' ,
121
+ example : '5' ,
122
+ } )
123
+ @ApiQuery ( {
124
+ name : 'category' ,
125
+ required : false ,
126
+ type : 'string' ,
127
+ description : 'Category filter for random songs. Only used when q=random.' ,
128
+ example : 'electronic' ,
129
+ } )
130
+ @ApiResponse ( {
131
+ status : 200 ,
132
+ description :
133
+ 'Success. Returns either an array of song previews or category counts.' ,
134
+ schema : {
135
+ oneOf : [
136
+ {
137
+ type : 'array' ,
138
+ items : { $ref : '#/components/schemas/SongPreviewDto' } ,
139
+ description :
140
+ 'Array of song previews (default behavior and most query modes)' ,
141
+ } ,
142
+ {
143
+ type : 'object' ,
144
+ additionalProperties : { type : 'number' } ,
145
+ description :
146
+ 'Category name to song count mapping (only when q=categories without id)' ,
147
+ example : { pop : 42 , rock : 38 , electronic : 15 } ,
148
+ } ,
149
+ ] ,
150
+ } ,
151
+ } )
152
+ @ApiResponse ( {
153
+ status : 400 ,
154
+ description :
155
+ 'Bad Request. Invalid query parameters (e.g., invalid count for random query).' ,
75
156
} )
76
157
public async getSongList (
77
158
@Query ( ) query : PageQueryDTO ,
0 commit comments