ran prettier
This commit is contained in:
@@ -2,17 +2,17 @@ import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { AlbumController } from './album.controller';
|
||||
|
||||
describe('AlbumController', () => {
|
||||
let controller: AlbumController;
|
||||
let controller: AlbumController;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [AlbumController],
|
||||
}).compile();
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [AlbumController],
|
||||
}).compile();
|
||||
|
||||
controller = module.get<AlbumController>(AlbumController);
|
||||
});
|
||||
controller = module.get<AlbumController>(AlbumController);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
it('should be defined', () => {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -35,7 +35,7 @@ export class AlbumController {
|
||||
...createAlbumDto,
|
||||
artist: createAlbumDto.artist
|
||||
? { connect: { id: createAlbumDto.artist } }
|
||||
: undefined
|
||||
: undefined,
|
||||
});
|
||||
} catch {
|
||||
throw new ConflictException(
|
||||
|
||||
@@ -5,7 +5,7 @@ import { AlbumService } from './album.service';
|
||||
|
||||
@Module({
|
||||
imports: [PrismaModule],
|
||||
controllers: [AlbumController],
|
||||
providers: [AlbumService]
|
||||
controllers: [AlbumController],
|
||||
providers: [AlbumService],
|
||||
})
|
||||
export class AlbumModule {}
|
||||
|
||||
@@ -2,17 +2,17 @@ import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { AlbumService } from './album.service';
|
||||
|
||||
describe('AlbumService', () => {
|
||||
let service: AlbumService;
|
||||
let service: AlbumService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [AlbumService],
|
||||
}).compile();
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [AlbumService],
|
||||
}).compile();
|
||||
|
||||
service = module.get<AlbumService>(AlbumService);
|
||||
});
|
||||
service = module.get<AlbumService>(AlbumService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
+11
-1
@@ -17,7 +17,17 @@ import { SearchService } from './search/search.service';
|
||||
import { SearchModule } from './search/search.module';
|
||||
|
||||
@Module({
|
||||
imports: [UsersModule, PrismaModule, AuthModule, SongModule, LessonModule, GenreModule, ArtistModule, AlbumModule, SearchModule],
|
||||
imports: [
|
||||
UsersModule,
|
||||
PrismaModule,
|
||||
AuthModule,
|
||||
SongModule,
|
||||
LessonModule,
|
||||
GenreModule,
|
||||
ArtistModule,
|
||||
AlbumModule,
|
||||
SearchModule,
|
||||
],
|
||||
controllers: [AppController],
|
||||
providers: [AppService, PrismaService, ArtistService],
|
||||
})
|
||||
|
||||
@@ -2,17 +2,17 @@ import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { ArtistController } from './artist.controller';
|
||||
|
||||
describe('ArtistController', () => {
|
||||
let controller: ArtistController;
|
||||
let controller: ArtistController;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [ArtistController],
|
||||
}).compile();
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [ArtistController],
|
||||
}).compile();
|
||||
|
||||
controller = module.get<ArtistController>(ArtistController);
|
||||
});
|
||||
controller = module.get<ArtistController>(ArtistController);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
it('should be defined', () => {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -6,6 +6,6 @@ import { ArtistService } from './artist.service';
|
||||
@Module({
|
||||
imports: [PrismaModule],
|
||||
controllers: [ArtistController],
|
||||
providers: [ArtistService]
|
||||
})
|
||||
providers: [ArtistService],
|
||||
})
|
||||
export class ArtistModule {}
|
||||
|
||||
@@ -2,17 +2,17 @@ import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { ArtistService } from './artist.service';
|
||||
|
||||
describe('ArtistService', () => {
|
||||
let service: ArtistService;
|
||||
let service: ArtistService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [ArtistService],
|
||||
}).compile();
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [ArtistService],
|
||||
}).compile();
|
||||
|
||||
service = module.get<ArtistService>(ArtistService);
|
||||
});
|
||||
service = module.get<ArtistService>(ArtistService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -2,17 +2,17 @@ import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { GenreController } from './genre.controller';
|
||||
|
||||
describe('GenreController', () => {
|
||||
let controller: GenreController;
|
||||
let controller: GenreController;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [GenreController],
|
||||
}).compile();
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [GenreController],
|
||||
}).compile();
|
||||
|
||||
controller = module.get<GenreController>(GenreController);
|
||||
});
|
||||
controller = module.get<GenreController>(GenreController);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
it('should be defined', () => {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -5,7 +5,7 @@ import { GenreService } from './genre.service';
|
||||
|
||||
@Module({
|
||||
imports: [PrismaModule],
|
||||
controllers: [GenreController],
|
||||
providers: [GenreService]
|
||||
controllers: [GenreController],
|
||||
providers: [GenreService],
|
||||
})
|
||||
export class GenreModule {}
|
||||
|
||||
@@ -2,17 +2,17 @@ import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { GenreService } from './genre.service';
|
||||
|
||||
describe('GenreService', () => {
|
||||
let service: GenreService;
|
||||
let service: GenreService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [GenreService],
|
||||
}).compile();
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [GenreService],
|
||||
}).compile();
|
||||
|
||||
service = module.get<GenreService>(GenreService);
|
||||
});
|
||||
service = module.get<GenreService>(GenreService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { ApiProperty } from "@nestjs/swagger";
|
||||
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
|
||||
export class SearchSongDto {
|
||||
@ApiProperty()
|
||||
|
||||
@@ -1,4 +1,19 @@
|
||||
import { BadRequestException, Body, Controller, DefaultValuePipe, Get, HttpCode, HttpStatus, InternalServerErrorException, NotFoundException, Param, ParseIntPipe, Post, Query, Req } from '@nestjs/common';
|
||||
import {
|
||||
BadRequestException,
|
||||
Body,
|
||||
Controller,
|
||||
DefaultValuePipe,
|
||||
Get,
|
||||
HttpCode,
|
||||
HttpStatus,
|
||||
InternalServerErrorException,
|
||||
NotFoundException,
|
||||
Param,
|
||||
ParseIntPipe,
|
||||
Post,
|
||||
Query,
|
||||
Req,
|
||||
} from '@nestjs/common';
|
||||
import { ApiOperation, ApiParam, ApiTags } from '@nestjs/swagger';
|
||||
import { Song } from '@prisma/client';
|
||||
import { SongService } from 'src/song/song.service';
|
||||
@@ -8,7 +23,10 @@ import { SearchService } from './search.service';
|
||||
@ApiTags('search')
|
||||
@Controller('search')
|
||||
export class SearchController {
|
||||
constructor(private readonly searchService: SearchService, private readonly songService: SongService) {}
|
||||
constructor(
|
||||
private readonly searchService: SearchService,
|
||||
private readonly songService: SongService,
|
||||
) {}
|
||||
|
||||
@ApiOperation({
|
||||
summary: 'Get a song details by song name',
|
||||
@@ -16,8 +34,8 @@ export class SearchController {
|
||||
})
|
||||
@Get('song/:name')
|
||||
async findByName(@Param('name') name: string): Promise<Song | null> {
|
||||
const ret = await this.searchService.songByTitle({ name })
|
||||
if (!ret) throw new NotFoundException;
|
||||
const ret = await this.searchService.songByTitle({ name });
|
||||
if (!ret) throw new NotFoundException();
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -27,14 +45,16 @@ export class SearchController {
|
||||
})
|
||||
@Post('song/advanced')
|
||||
@HttpCode(200) // change from '201 created' to '200 OK' http default response code
|
||||
async findAdvanced(@Body() searchSongDto: SearchSongDto): Promise<Song[] | null> {
|
||||
async findAdvanced(
|
||||
@Body() searchSongDto: SearchSongDto,
|
||||
): Promise<Song[] | null> {
|
||||
try {
|
||||
const ret = await this.searchService.findAdvanced({
|
||||
albumId: searchSongDto.album ? + searchSongDto.album : undefined,
|
||||
artistId: searchSongDto.artist ? + searchSongDto.artist : undefined,
|
||||
genreId: searchSongDto.genre ? + searchSongDto.genre: undefined
|
||||
albumId: searchSongDto.album ? +searchSongDto.album : undefined,
|
||||
artistId: searchSongDto.artist ? +searchSongDto.artist : undefined,
|
||||
genreId: searchSongDto.genre ? +searchSongDto.genre : undefined,
|
||||
});
|
||||
if (!ret.length) throw new NotFoundException;
|
||||
if (!ret.length) throw new NotFoundException();
|
||||
else return ret;
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
@@ -47,9 +67,11 @@ export class SearchController {
|
||||
description: 'Get songs details by artist',
|
||||
})
|
||||
@Get('song/artist/:artistId')
|
||||
async findByArtist(@Param('artistId', ParseIntPipe) artistId: number): Promise<Song[] | null> {
|
||||
async findByArtist(
|
||||
@Param('artistId', ParseIntPipe) artistId: number,
|
||||
): Promise<Song[] | null> {
|
||||
const ret = await this.searchService.songsByArtist(artistId);
|
||||
if (!ret.length) throw new NotFoundException;
|
||||
if (!ret.length) throw new NotFoundException();
|
||||
else return ret;
|
||||
}
|
||||
|
||||
@@ -58,9 +80,11 @@ export class SearchController {
|
||||
description: 'Get songs details by genre',
|
||||
})
|
||||
@Get('song/genre/:genreId')
|
||||
async findByGenre(@Param('genreId', ParseIntPipe) genreId: number): Promise<Song[] | null> {
|
||||
async findByGenre(
|
||||
@Param('genreId', ParseIntPipe) genreId: number,
|
||||
): Promise<Song[] | null> {
|
||||
const ret = await this.searchService.songsByGenre(genreId);
|
||||
if (!ret.length) throw new NotFoundException;
|
||||
if (!ret.length) throw new NotFoundException();
|
||||
else return ret;
|
||||
}
|
||||
|
||||
@@ -69,9 +93,11 @@ export class SearchController {
|
||||
description: 'Get songs details by album',
|
||||
})
|
||||
@Get('song/album/:albumId')
|
||||
async findByAlbum(@Param('albumId', ParseIntPipe) albumId: number): Promise<Song[] | null> {
|
||||
async findByAlbum(
|
||||
@Param('albumId', ParseIntPipe) albumId: number,
|
||||
): Promise<Song[] | null> {
|
||||
const ret = await this.searchService.songsByAlbum(albumId);
|
||||
if (ret.length) throw new NotFoundException;
|
||||
if (ret.length) throw new NotFoundException();
|
||||
else return ret;
|
||||
}
|
||||
|
||||
@@ -80,9 +106,16 @@ export class SearchController {
|
||||
description: 'Guess elements details by keyword',
|
||||
})
|
||||
@Get('guess/:type/:word')
|
||||
@ApiParam({name: 'word', type: 'string', required: true, example: 'Yoko Shimomura'})
|
||||
@ApiParam({name: 'type', type: 'string', required: true, example: 'artist'})
|
||||
async guess(@Param() params: {'type': string, 'word': string}): Promise<any[] | null> {
|
||||
@ApiParam({
|
||||
name: 'word',
|
||||
type: 'string',
|
||||
required: true,
|
||||
example: 'Yoko Shimomura',
|
||||
})
|
||||
@ApiParam({ name: 'type', type: 'string', required: true, example: 'artist' })
|
||||
async guess(
|
||||
@Param() params: { type: string; word: string },
|
||||
): Promise<any[] | null> {
|
||||
try {
|
||||
let ret: any[];
|
||||
switch (params.type) {
|
||||
@@ -96,9 +129,9 @@ export class SearchController {
|
||||
ret = await this.searchService.guessSong(params.word);
|
||||
break;
|
||||
default:
|
||||
throw new BadRequestException;
|
||||
throw new BadRequestException();
|
||||
}
|
||||
if (!ret.length) throw new NotFoundException;
|
||||
if (!ret.length) throw new NotFoundException();
|
||||
else return ret;
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
import { DefaultValuePipe, Injectable, ParseIntPipe, Query, Req } from '@nestjs/common';
|
||||
import {
|
||||
DefaultValuePipe,
|
||||
Injectable,
|
||||
ParseIntPipe,
|
||||
Query,
|
||||
Req,
|
||||
} from '@nestjs/common';
|
||||
import { Album, Artist, Prisma, Song } from '@prisma/client';
|
||||
import { PrismaService } from 'src/prisma/prisma.service';
|
||||
|
||||
@@ -6,7 +12,9 @@ import { PrismaService } from 'src/prisma/prisma.service';
|
||||
export class SearchService {
|
||||
constructor(private prisma: PrismaService) {}
|
||||
|
||||
async songByTitle(songWhereUniqueInput: Prisma.SongWhereUniqueInput): Promise<Song | null> {
|
||||
async songByTitle(
|
||||
songWhereUniqueInput: Prisma.SongWhereUniqueInput,
|
||||
): Promise<Song | null> {
|
||||
return this.prisma.song.findUnique({
|
||||
where: songWhereUniqueInput,
|
||||
});
|
||||
@@ -15,59 +23,57 @@ export class SearchService {
|
||||
async songsByArtist(artistId: number): Promise<Song[]> {
|
||||
return this.prisma.song.findMany({
|
||||
where: {
|
||||
artistId: artistId
|
||||
artistId: artistId,
|
||||
},
|
||||
orderBy: [
|
||||
]
|
||||
orderBy: [],
|
||||
});
|
||||
}
|
||||
|
||||
async songsByGenre(genreId: number): Promise<Song[]> {
|
||||
return this.prisma.song.findMany({
|
||||
where: {
|
||||
genreId: genreId
|
||||
}
|
||||
genreId: genreId,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
async songsByAlbum(albumId: number): Promise<Song[]> {
|
||||
return this.prisma.song.findMany({
|
||||
where: {
|
||||
albumId: albumId
|
||||
}
|
||||
albumId: albumId,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async artistByName(artistName: string): Promise<Artist | null> {
|
||||
return this.prisma.artist.findUnique({
|
||||
where: {
|
||||
name: artistName
|
||||
}
|
||||
name: artistName,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async guessSong(word: string): Promise<Song[]> {
|
||||
return this.prisma.song.findMany({
|
||||
where: {
|
||||
name: {contains: word}
|
||||
}
|
||||
name: { contains: word },
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async guessArtist(word: string): Promise<Artist[]> {
|
||||
return this.prisma.artist.findMany({
|
||||
where: {
|
||||
name: {contains: word},
|
||||
}
|
||||
name: { contains: word },
|
||||
},
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
async guessAlbum(word: string): Promise<Album[]> {
|
||||
return this.prisma.album.findMany({
|
||||
where: {
|
||||
name: {contains: word},
|
||||
}
|
||||
name: { contains: word },
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -77,18 +83,23 @@ export class SearchService {
|
||||
artistId?: number;
|
||||
orderBy?: Prisma.SongOrderByWithRelationInput;
|
||||
}): Promise<Song[]> {
|
||||
const { albumId: albumId, genreId: genreId, artistId: artistId, orderBy: orderBy } = params;
|
||||
const {
|
||||
albumId: albumId,
|
||||
genreId: genreId,
|
||||
artistId: artistId,
|
||||
orderBy: orderBy,
|
||||
} = params;
|
||||
return this.prisma.song.findMany({
|
||||
where: {
|
||||
OR:[
|
||||
OR: [
|
||||
{
|
||||
albumId: { equals: albumId },
|
||||
genreId: { equals: genreId },
|
||||
artistId: { equals: artistId },
|
||||
}
|
||||
]
|
||||
},
|
||||
],
|
||||
},
|
||||
orderBy
|
||||
orderBy,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user