Skip to content

Commit dd9e241

Browse files
committed
refactor: remove SongBrowser module and controller, update SongController to enhance song retrieval with detailed query options
1 parent 332d67c commit dd9e241

File tree

5 files changed

+88
-187
lines changed

5 files changed

+88
-187
lines changed

apps/backend/src/app.module.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import { ParseTokenPipe } from './lib/parseToken';
1414
import { MailingModule } from './mailing/mailing.module';
1515
import { SeedModule } from './seed/seed.module';
1616
import { SongModule } from './song/song.module';
17-
import { SongBrowserModule } from './song-browser/song-browser.module';
1817
import { UserModule } from './user/user.module';
1918

2019
@Module({

apps/backend/src/song-browser/song-browser.controller.spec.ts

Lines changed: 0 additions & 100 deletions
This file was deleted.

apps/backend/src/song-browser/song-browser.controller.ts

Lines changed: 0 additions & 67 deletions
This file was deleted.

apps/backend/src/song-browser/song-browser.module.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

apps/backend/src/song/song.controller.ts

Lines changed: 88 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ import {
3636
ApiBody,
3737
ApiConsumes,
3838
ApiOperation,
39+
ApiParam,
40+
ApiQuery,
41+
ApiResponse,
3942
ApiTags,
4043
} from '@nestjs/swagger';
4144
import type { Response } from 'express';
@@ -51,14 +54,10 @@ import { SongService } from './song.service';
5154
@ApiTags('song')
5255
export class SongController {
5356
static multerConfig: MulterOptions = {
54-
limits: {
55-
fileSize: UPLOAD_CONSTANTS.file.maxSize,
56-
},
57+
limits: { fileSize: UPLOAD_CONSTANTS.file.maxSize },
5758
fileFilter: (req, file, cb) => {
58-
if (!file.originalname.match(/\.(nbs)$/)) {
59+
if (!file.originalname.match(/\.(nbs)$/))
5960
return cb(new Error('Only .nbs files are allowed!'), false);
60-
}
61-
6261
cb(null, true);
6362
},
6463
};
@@ -71,7 +70,89 @@ export class SongController {
7170

7271
@Get('/')
7372
@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).',
75156
})
76157
public async getSongList(
77158
@Query() query: PageQueryDTO,

0 commit comments

Comments
 (0)