1
1
import { UPLOAD_CONSTANTS } from '@nbw/config' ;
2
- import type { UserDocument } from '@nbw/database' ;
3
- import { PageQueryDTO , SongPreviewDto , SongViewDto , UploadSongDto , UploadSongResponseDto , } from '@nbw/database' ;
2
+ import { PageDto , UserDocument , PageQueryDTO , SongPreviewDto , SongViewDto , UploadSongDto , UploadSongResponseDto , FeaturedSongsDto , } from '@nbw/database' ;
4
3
import type { RawBodyRequest } from '@nestjs/common' ;
5
4
import { BadRequestException , Body , Controller , Delete , Get , Headers , HttpStatus , Param , Patch , Post , Query , Req , Res , UnauthorizedException , UploadedFile , UseGuards , UseInterceptors , } from '@nestjs/common' ;
6
5
import { AuthGuard } from '@nestjs/passport' ;
@@ -12,7 +11,6 @@ import type { Response } from 'express';
12
11
import { FileService } from '@server/file/file.service' ;
13
12
import { GetRequestToken , validateUser } from '@server/lib/GetRequestUser' ;
14
13
15
- import { SongBrowserService } from './song-browser/song-browser.service' ;
16
14
import { SongService } from './song.service' ;
17
15
18
16
// Handles public-facing song routes.
@@ -29,7 +27,7 @@ export class SongController {
29
27
} ,
30
28
} ;
31
29
32
- constructor ( public readonly songService : SongService , public readonly fileService : FileService , public readonly songBrowserService : SongBrowserService , ) { }
30
+ constructor ( public readonly songService : SongService , public readonly fileService : FileService , ) { }
33
31
34
32
@Get ( '/' )
35
33
@ApiOperation ( {
@@ -95,33 +93,59 @@ export class SongController {
95
93
@Query ( 'q' ) q ?: 'featured' | 'recent' | 'categories' | 'random' ,
96
94
@Param ( 'id' ) id ?: string ,
97
95
@Query ( 'category' ) category ?: string ,
98
- ) : Promise < SongPreviewDto [ ] | Record < string , number > > {
96
+ ) : Promise < PageDto < SongPreviewDto > | Record < string , number > | FeaturedSongsDto > {
99
97
if ( q ) {
100
98
switch ( q ) {
101
99
case 'featured' :
102
- return await this . songBrowserService . getRecentSongs ( query ) ;
100
+ return await this . songService . getFeaturedSongs ( ) ;
103
101
case 'recent' :
104
- return await this . songBrowserService . getRecentSongs ( query ) ;
102
+ return new PageDto < SongPreviewDto > ( {
103
+ content : await this . songService . getRecentSongs ( query . page , query . limit , ) ,
104
+ page : query . page ,
105
+ limit : query . limit ,
106
+ total : 0 ,
107
+ } ) ;
105
108
case 'categories' :
106
109
if ( id ) {
107
- return await this . songBrowserService . getSongsByCategory ( id , query ) ;
110
+ return new PageDto < SongPreviewDto > ( {
111
+ content : await this . songService . getSongsByCategory (
112
+ category ,
113
+ query . page ,
114
+ query . limit ,
115
+ ) ,
116
+ page : query . page ,
117
+ limit : query . limit ,
118
+ total : 0 ,
119
+ } ) ;
108
120
}
109
- return await this . songBrowserService . getCategories ( ) ;
121
+ return await this . songService . getCategories ( ) ;
110
122
case 'random' : {
111
123
if ( query . limit && ( query . limit < 1 || query . limit > 10 ) ) {
112
124
throw new BadRequestException ( 'Invalid query parameters' ) ;
113
125
}
114
- return await this . songBrowserService . getRandomSongs (
126
+ const data = await this . songService . getRandomSongs (
115
127
query . limit ?? 1 ,
116
128
category ,
117
129
) ;
130
+ return new PageDto < SongPreviewDto > ( {
131
+ content : data ,
132
+ page : query . page ,
133
+ limit : query . limit ,
134
+ total : data . length ,
135
+ } ) ;
118
136
}
119
137
default :
120
138
throw new BadRequestException ( 'Invalid query parameters' ) ;
121
139
}
122
140
}
123
141
124
- return await this . songService . getSongByPage ( query ) ;
142
+ const data = await this . songService . getSongByPage ( query ) ;
143
+ return new PageDto < SongPreviewDto > ( {
144
+ content : data ,
145
+ page : query . page ,
146
+ limit : query . limit ,
147
+ total : data . length ,
148
+ } ) ;
125
149
}
126
150
127
151
@Get ( '/search' )
@@ -131,8 +155,14 @@ export class SongController {
131
155
public async searchSongs (
132
156
@Query ( ) query : PageQueryDTO ,
133
157
@Query ( 'q' ) q : string ,
134
- ) : Promise < SongPreviewDto [ ] > {
135
- return await this . songService . searchSongs ( query , q ?? '' ) ;
158
+ ) : Promise < PageDto < SongPreviewDto > > {
159
+ const data = await this . songService . searchSongs ( query , q ?? '' ) ;
160
+ return new PageDto < SongPreviewDto > ( {
161
+ content : data ,
162
+ page : query . page ,
163
+ limit : query . limit ,
164
+ total : data . length ,
165
+ } ) ;
136
166
}
137
167
138
168
@Get ( '/:id' )
0 commit comments