feat: artist and genre illustration

This commit is contained in:
GitBluub
2023-05-30 00:51:46 +09:00
committed by Clément Le Bihan
parent 8dbb724a0f
commit 5c7648541f
2 changed files with 36 additions and 2 deletions
+18 -1
View File
@@ -6,12 +6,14 @@ import {
DefaultValuePipe,
Delete,
Get,
InternalServerErrorException,
NotFoundException,
Param,
ParseIntPipe,
Post,
Query,
Req,
StreamableFile,
} from '@nestjs/common';
import { Plage } from 'src/models/plage';
import { CreateArtistDto } from './dto/create-artist.dto';
@@ -19,11 +21,12 @@ import { Request } from 'express';
import { ArtistService } from './artist.service';
import { Prisma, Artist } from '@prisma/client';
import { ApiTags } from '@nestjs/swagger';
import { createReadStream } from 'fs';
@Controller('artist')
@ApiTags('artist')
export class ArtistController {
constructor(private readonly service: ArtistService) {}
constructor(private readonly service: ArtistService) { }
@Post()
async create(@Body() dto: CreateArtistDto) {
@@ -39,6 +42,20 @@ export class ArtistController {
return await this.service.delete({ id });
}
@Get(':id/illustration')
async getIllustration(@Param('id', ParseIntPipe) id: number) {
const artist = await this.service.get({ id });
if (!artist) throw new NotFoundException('Artist not found');
const path = `/assets/artists/${artist.name}/illustration.png`;
try {
const file = createReadStream(path);
return new StreamableFile(file);
} catch {
throw new InternalServerErrorException();
}
}
@Get()
async findAll(
@Req() req: Request,
+18 -1
View File
@@ -6,12 +6,14 @@ import {
DefaultValuePipe,
Delete,
Get,
InternalServerErrorException,
NotFoundException,
Param,
ParseIntPipe,
Post,
Query,
Req,
StreamableFile,
} from '@nestjs/common';
import { Plage } from 'src/models/plage';
import { CreateGenreDto } from './dto/create-genre.dto';
@@ -19,11 +21,12 @@ import { Request } from 'express';
import { GenreService } from './genre.service';
import { Prisma, Genre } from '@prisma/client';
import { ApiTags } from '@nestjs/swagger';
import { createReadStream } from 'fs';
@Controller('genre')
@ApiTags('genre')
export class GenreController {
constructor(private readonly service: GenreService) {}
constructor(private readonly service: GenreService) { }
@Post()
async create(@Body() dto: CreateGenreDto) {
@@ -39,6 +42,20 @@ export class GenreController {
return await this.service.delete({ id });
}
@Get(':id/illustration')
async getIllustration(@Param('id', ParseIntPipe) id: number) {
const genre = await this.service.get({ id });
if (!genre) throw new NotFoundException('Genre not found');
const path = `/assets/genres/${genre.name}/illustration.png`;
try {
const file = createReadStream(path);
return new StreamableFile(file);
} catch {
throw new InternalServerErrorException();
}
}
@Get()
async findAll(
@Req() req: Request,