diff --git a/back/src/album/album.controller.spec.ts b/back/src/album/album.controller.spec.ts index 7c18a32..20efb84 100644 --- a/back/src/album/album.controller.spec.ts +++ b/back/src/album/album.controller.spec.ts @@ -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); - }); + controller = module.get(AlbumController); + }); - it('should be defined', () => { - expect(controller).toBeDefined(); - }); + it('should be defined', () => { + expect(controller).toBeDefined(); + }); }); diff --git a/back/src/album/album.controller.ts b/back/src/album/album.controller.ts index f721b57..f5b15f7 100644 --- a/back/src/album/album.controller.ts +++ b/back/src/album/album.controller.ts @@ -35,7 +35,7 @@ export class AlbumController { ...createAlbumDto, artist: createAlbumDto.artist ? { connect: { id: createAlbumDto.artist } } - : undefined + : undefined, }); } catch { throw new ConflictException( diff --git a/back/src/album/album.module.ts b/back/src/album/album.module.ts index 68f8261..1626552 100644 --- a/back/src/album/album.module.ts +++ b/back/src/album/album.module.ts @@ -5,7 +5,7 @@ import { AlbumService } from './album.service'; @Module({ imports: [PrismaModule], - controllers: [AlbumController], - providers: [AlbumService] + controllers: [AlbumController], + providers: [AlbumService], }) export class AlbumModule {} diff --git a/back/src/album/album.service.spec.ts b/back/src/album/album.service.spec.ts index d6fdab3..3bf8702 100644 --- a/back/src/album/album.service.spec.ts +++ b/back/src/album/album.service.spec.ts @@ -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); - }); + service = module.get(AlbumService); + }); - it('should be defined', () => { - expect(service).toBeDefined(); - }); + it('should be defined', () => { + expect(service).toBeDefined(); + }); }); diff --git a/back/src/app.module.ts b/back/src/app.module.ts index cab6384..a5e526e 100644 --- a/back/src/app.module.ts +++ b/back/src/app.module.ts @@ -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], }) diff --git a/back/src/artist/artist.controller.spec.ts b/back/src/artist/artist.controller.spec.ts index e35f48d..67d23b7 100644 --- a/back/src/artist/artist.controller.spec.ts +++ b/back/src/artist/artist.controller.spec.ts @@ -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); - }); + controller = module.get(ArtistController); + }); - it('should be defined', () => { - expect(controller).toBeDefined(); - }); + it('should be defined', () => { + expect(controller).toBeDefined(); + }); }); diff --git a/back/src/artist/artist.module.ts b/back/src/artist/artist.module.ts index fc73335..4455d6c 100644 --- a/back/src/artist/artist.module.ts +++ b/back/src/artist/artist.module.ts @@ -6,6 +6,6 @@ import { ArtistService } from './artist.service'; @Module({ imports: [PrismaModule], controllers: [ArtistController], - providers: [ArtistService] - }) + providers: [ArtistService], +}) export class ArtistModule {} diff --git a/back/src/artist/artist.service.spec.ts b/back/src/artist/artist.service.spec.ts index c0f568a..326d33c 100644 --- a/back/src/artist/artist.service.spec.ts +++ b/back/src/artist/artist.service.spec.ts @@ -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); - }); + service = module.get(ArtistService); + }); - it('should be defined', () => { - expect(service).toBeDefined(); - }); + it('should be defined', () => { + expect(service).toBeDefined(); + }); }); diff --git a/back/src/genre/genre.controller.spec.ts b/back/src/genre/genre.controller.spec.ts index f91a726..000686d 100644 --- a/back/src/genre/genre.controller.spec.ts +++ b/back/src/genre/genre.controller.spec.ts @@ -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); - }); + controller = module.get(GenreController); + }); - it('should be defined', () => { - expect(controller).toBeDefined(); - }); + it('should be defined', () => { + expect(controller).toBeDefined(); + }); }); diff --git a/back/src/genre/genre.module.ts b/back/src/genre/genre.module.ts index eebddba..f8b9c3c 100644 --- a/back/src/genre/genre.module.ts +++ b/back/src/genre/genre.module.ts @@ -5,7 +5,7 @@ import { GenreService } from './genre.service'; @Module({ imports: [PrismaModule], - controllers: [GenreController], - providers: [GenreService] + controllers: [GenreController], + providers: [GenreService], }) export class GenreModule {} diff --git a/back/src/genre/genre.service.spec.ts b/back/src/genre/genre.service.spec.ts index 2872336..f25cd9f 100644 --- a/back/src/genre/genre.service.spec.ts +++ b/back/src/genre/genre.service.spec.ts @@ -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); - }); + service = module.get(GenreService); + }); - it('should be defined', () => { - expect(service).toBeDefined(); - }); + it('should be defined', () => { + expect(service).toBeDefined(); + }); }); diff --git a/back/src/search/dto/search-song.dto.ts b/back/src/search/dto/search-song.dto.ts index d3bd2bf..9a94171 100644 --- a/back/src/search/dto/search-song.dto.ts +++ b/back/src/search/dto/search-song.dto.ts @@ -1,5 +1,4 @@ -import { ApiProperty } from "@nestjs/swagger"; - +import { ApiProperty } from '@nestjs/swagger'; export class SearchSongDto { @ApiProperty() diff --git a/back/src/search/search.controller.ts b/back/src/search/search.controller.ts index f91eb35..d719916 100644 --- a/back/src/search/search.controller.ts +++ b/back/src/search/search.controller.ts @@ -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 { - 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 { + async findAdvanced( + @Body() searchSongDto: SearchSongDto, + ): Promise { 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 { + async findByArtist( + @Param('artistId', ParseIntPipe) artistId: number, + ): Promise { 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 { + async findByGenre( + @Param('genreId', ParseIntPipe) genreId: number, + ): Promise { 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 { + async findByAlbum( + @Param('albumId', ParseIntPipe) albumId: number, + ): Promise { 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 { + @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 { 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); diff --git a/back/src/search/search.service.ts b/back/src/search/search.service.ts index 584d387..8c84c7a 100644 --- a/back/src/search/search.service.ts +++ b/back/src/search/search.service.ts @@ -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 { + async songByTitle( + songWhereUniqueInput: Prisma.SongWhereUniqueInput, + ): Promise { return this.prisma.song.findUnique({ where: songWhereUniqueInput, }); @@ -15,59 +23,57 @@ export class SearchService { async songsByArtist(artistId: number): Promise { return this.prisma.song.findMany({ where: { - artistId: artistId + artistId: artistId, }, - orderBy: [ - ] + orderBy: [], }); } async songsByGenre(genreId: number): Promise { return this.prisma.song.findMany({ where: { - genreId: genreId - } + genreId: genreId, + }, }); } - + async songsByAlbum(albumId: number): Promise { return this.prisma.song.findMany({ where: { - albumId: albumId - } + albumId: albumId, + }, }); } async artistByName(artistName: string): Promise { return this.prisma.artist.findUnique({ where: { - name: artistName - } + name: artistName, + }, }); } async guessSong(word: string): Promise { return this.prisma.song.findMany({ where: { - name: {contains: word} - } + name: { contains: word }, + }, }); } async guessArtist(word: string): Promise { return this.prisma.artist.findMany({ where: { - name: {contains: word}, - } + name: { contains: word }, + }, }); - } async guessAlbum(word: string): Promise { 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 { - 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, }); } }