Skip to content

Commit 4c7ccf3

Browse files
committed
feat: implement SongBrowserService and controller with endpoints for featured, recent, categories, and random songs
1 parent 2cd6196 commit 4c7ccf3

File tree

5 files changed

+47
-12
lines changed

5 files changed

+47
-12
lines changed

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,17 @@ import {
88
} from '@nestjs/common';
99
import { ApiOperation, ApiTags } from '@nestjs/swagger';
1010

11-
import { SongBrowserService } from './song-browser.service';
12-
1311
@Controller('song-browser')
1412
@ApiTags('song-browser')
1513
@ApiTags('song')
1614
export class SongBrowserController {
17-
constructor(public readonly songBrowserService: SongBrowserService) {}
15+
constructor /*public readonly songBrowserService: SongBrowserService*/() {}
1816

1917
@Get('/featured')
2018
@ApiOperation({ summary: 'Get a list of featured songs' })
2119
public async getFeaturedSongs(): Promise<FeaturedSongsDto> {
22-
return await this.songBrowserService.getFeaturedSongs();
20+
throw new Error('Unimplemented');
21+
//return await this.songBrowserService.getFeaturedSongs();
2322
}
2423

2524
@Get('/recent')
@@ -29,13 +28,15 @@ export class SongBrowserController {
2928
public async getSongList(
3029
@Query() query: PageQueryDTO,
3130
): Promise<SongPreviewDto[]> {
32-
return await this.songBrowserService.getRecentSongs(query);
31+
throw new Error('Unimplemented');
32+
//return await this.songBrowserService.getRecentSongs(query);
3333
}
3434

3535
@Get('/categories')
3636
@ApiOperation({ summary: 'Get a list of song categories and song counts' })
3737
public async getCategories(): Promise<Record<string, number>> {
38-
return await this.songBrowserService.getCategories();
38+
throw new Error('Unimplemented');
39+
//return await this.songBrowserService.getCategories();
3940
}
4041

4142
@Get('/categories/:id')
@@ -44,7 +45,8 @@ export class SongBrowserController {
4445
@Param('id') id: string,
4546
@Query() query: PageQueryDTO,
4647
): Promise<SongPreviewDto[]> {
47-
return await this.songBrowserService.getSongsByCategory(id, query);
48+
throw new Error('Unimplemented');
49+
//return await this.songBrowserService.getSongsByCategory(id, query);
4850
}
4951

5052
@Get('/random')
@@ -59,6 +61,7 @@ export class SongBrowserController {
5961
throw new BadRequestException('Invalid query parameters');
6062
}
6163

62-
return await this.songBrowserService.getRandomSongs(countInt, category);
64+
throw new Error('Unimplemented');
65+
//return await this.songBrowserService.getRandomSongs(countInt, category);
6366
}
6467
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ import { Module } from '@nestjs/common';
33
import { SongModule } from '@server/song/song.module';
44

55
import { SongBrowserController } from './song-browser.controller';
6-
import { SongBrowserService } from './song-browser.service';
76

87
@Module({
9-
providers: [SongBrowserService],
8+
providers: [],
109
controllers: [SongBrowserController],
1110
imports: [SongModule],
1211
})

apps/backend/src/song-browser/song-browser.service.spec.ts renamed to apps/backend/src/song/song-browser/song-browser.service.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { PageQueryDTO, SongPreviewDto, SongWithUser } from '@nbw/database';
22
import { HttpException } from '@nestjs/common';
33
import { Test, TestingModule } from '@nestjs/testing';
44

5-
import { SongService } from '@server/song/song.service';
5+
import { SongService } from '../song.service';
66

77
import { SongBrowserService } from './song-browser.service';
88

File renamed without changes.

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

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import {
88
UploadSongResponseDto,
99
} from '@nbw/database';
1010
import type { RawBodyRequest } from '@nestjs/common';
11+
import { SongBrowserService } from './song-browser/song-browser.service';
1112
import {
13+
BadRequestException,
1214
Body,
1315
Controller,
1416
Delete,
@@ -64,6 +66,7 @@ export class SongController {
6466
constructor(
6567
public readonly songService: SongService,
6668
public readonly fileService: FileService,
69+
public readonly songBrowserService: SongBrowserService,
6770
) {}
6871

6972
@Get('/')
@@ -72,7 +75,37 @@ export class SongController {
7275
})
7376
public async getSongList(
7477
@Query() query: PageQueryDTO,
75-
): Promise<SongPreviewDto[]> {
78+
@Query('q') q?: 'featured' | 'recent' | 'categories' | 'random',
79+
@Param('id') id?: string,
80+
@Query('count') count?: string,
81+
@Query('category') category?: string,
82+
): Promise<SongPreviewDto[] | Record<string, number>> {
83+
if (q) {
84+
switch (q) {
85+
case 'featured':
86+
return await this.songBrowserService.getRecentSongs(query);
87+
case 'recent':
88+
return await this.songBrowserService.getRecentSongs(query);
89+
case 'categories':
90+
if (id) {
91+
return await this.songBrowserService.getSongsByCategory(id, query);
92+
}
93+
return await this.songBrowserService.getCategories();
94+
case 'random': {
95+
const countInt = parseInt(count);
96+
if (isNaN(countInt) || countInt < 1 || countInt > 10) {
97+
throw new BadRequestException('Invalid query parameters');
98+
}
99+
return await this.songBrowserService.getRandomSongs(
100+
countInt,
101+
category,
102+
);
103+
}
104+
default:
105+
throw new BadRequestException('Invalid query parameters');
106+
}
107+
}
108+
76109
return await this.songService.getSongByPage(query);
77110
}
78111

0 commit comments

Comments
 (0)