2023-09-20 13:16:33 +02:00
|
|
|
import {
|
2023-12-09 23:34:12 -05:00
|
|
|
AuthDto,
|
2023-09-20 13:16:33 +02:00
|
|
|
CreateLibraryDto as CreateDto,
|
|
|
|
|
LibraryService,
|
|
|
|
|
LibraryStatsResponseDto,
|
|
|
|
|
LibraryResponseDto as ResponseDto,
|
|
|
|
|
ScanLibraryDto,
|
|
|
|
|
UpdateLibraryDto as UpdateDto,
|
|
|
|
|
} from '@app/domain';
|
|
|
|
|
import { Body, Controller, Delete, Get, Param, Post, Put } from '@nestjs/common';
|
|
|
|
|
import { ApiTags } from '@nestjs/swagger';
|
2023-12-09 23:34:12 -05:00
|
|
|
import { Auth, Authenticated } from '../app.guard';
|
2023-09-20 13:16:33 +02:00
|
|
|
import { UseValidation } from '../app.utils';
|
|
|
|
|
import { UUIDParamDto } from './dto/uuid-param.dto';
|
|
|
|
|
|
|
|
|
|
@ApiTags('Library')
|
|
|
|
|
@Controller('library')
|
|
|
|
|
@Authenticated()
|
|
|
|
|
@UseValidation()
|
|
|
|
|
export class LibraryController {
|
|
|
|
|
constructor(private service: LibraryService) {}
|
|
|
|
|
|
|
|
|
|
@Get()
|
2023-12-09 23:34:12 -05:00
|
|
|
getLibraries(@Auth() auth: AuthDto): Promise<ResponseDto[]> {
|
|
|
|
|
return this.service.getAllForUser(auth);
|
2023-09-20 13:16:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Post()
|
2023-12-09 23:34:12 -05:00
|
|
|
createLibrary(@Auth() auth: AuthDto, @Body() dto: CreateDto): Promise<ResponseDto> {
|
|
|
|
|
return this.service.create(auth, dto);
|
2023-09-20 13:16:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Put(':id')
|
2023-12-09 23:34:12 -05:00
|
|
|
updateLibrary(@Auth() auth: AuthDto, @Param() { id }: UUIDParamDto, @Body() dto: UpdateDto): Promise<ResponseDto> {
|
|
|
|
|
return this.service.update(auth, id, dto);
|
2023-09-20 13:16:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Get(':id')
|
2023-12-09 23:34:12 -05:00
|
|
|
getLibraryInfo(@Auth() auth: AuthDto, @Param() { id }: UUIDParamDto): Promise<ResponseDto> {
|
|
|
|
|
return this.service.get(auth, id);
|
2023-09-20 13:16:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Delete(':id')
|
2023-12-09 23:34:12 -05:00
|
|
|
deleteLibrary(@Auth() auth: AuthDto, @Param() { id }: UUIDParamDto): Promise<void> {
|
|
|
|
|
return this.service.delete(auth, id);
|
2023-09-20 13:16:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Get(':id/statistics')
|
2023-12-09 23:34:12 -05:00
|
|
|
getLibraryStatistics(@Auth() auth: AuthDto, @Param() { id }: UUIDParamDto): Promise<LibraryStatsResponseDto> {
|
|
|
|
|
return this.service.getStatistics(auth, id);
|
2023-09-20 13:16:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Post(':id/scan')
|
2023-12-09 23:34:12 -05:00
|
|
|
scanLibrary(@Auth() auth: AuthDto, @Param() { id }: UUIDParamDto, @Body() dto: ScanLibraryDto) {
|
|
|
|
|
return this.service.queueScan(auth, id, dto);
|
2023-09-20 13:16:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Post(':id/removeOffline')
|
2023-12-09 23:34:12 -05:00
|
|
|
removeOfflineFiles(@Auth() auth: AuthDto, @Param() { id }: UUIDParamDto) {
|
|
|
|
|
return this.service.queueRemoveOffline(auth, id);
|
2023-09-20 13:16:33 +02:00
|
|
|
}
|
|
|
|
|
}
|