diff --git a/apps/backend/src/app/files/files.controller.ts b/apps/backend/src/app/files/files.controller.ts index 2f8b5b3..faac19d 100644 --- a/apps/backend/src/app/files/files.controller.ts +++ b/apps/backend/src/app/files/files.controller.ts @@ -1,14 +1,22 @@ -import { Controller, Get, Param, Post, StreamableFile } from '@nestjs/common'; +import { Controller, DefaultValuePipe, Get, Param, ParseIntPipe, Post, Query, StreamableFile } from '@nestjs/common'; import { FilesService } from "./files.service"; @Controller("files") export class FilesController { constructor(private readonly filesService: FilesService) {} - //TODO POST FILE @Post('new') async saveFile() { + } + + @Get('find') + async findMany( + @Query("limit", new DefaultValuePipe(20), ParseIntPipe) limit: number, + @Query("offset", new DefaultValuePipe(0), ParseIntPipe) offset: number, + @Query("search", new DefaultValuePipe("")) search: string, + ) { + } @Get(':fileId') diff --git a/apps/backend/src/app/files/files.dto.ts b/apps/backend/src/app/files/files.dto.ts new file mode 100644 index 0000000..8a1c616 --- /dev/null +++ b/apps/backend/src/app/files/files.dto.ts @@ -0,0 +1,19 @@ +import { IsUUID, MaxLength, MinLength } from 'class-validator'; +import { DefaultValuePipe } from '@nestjs/common'; + + +export class CreateFilesDto { + @MaxLength(128) + @MinLength(4) + fileName: string; + + @MaxLength(64) + @MinLength(2) + uploadedBy: string; + + isDocumentation?: boolean; + isRestricted?: boolean; + + @IsUUID() + groupId: string; +} \ No newline at end of file diff --git a/apps/backend/src/app/files/files.service.ts b/apps/backend/src/app/files/files.service.ts index 25d7ca2..929c93f 100644 --- a/apps/backend/src/app/files/files.service.ts +++ b/apps/backend/src/app/files/files.service.ts @@ -2,7 +2,7 @@ import { Injectable, NotFoundException, StreamableFile } from '@nestjs/common'; import { DbService } from 'apps/backend/src/app/db/db.service'; import { FilesTable } from 'apps/backend/src/app/db/schema'; import { StorageService } from 'apps/backend/src/app/storage/storage.service'; -import { eq } from 'drizzle-orm'; +import { eq, ilike } from 'drizzle-orm'; @Injectable() @@ -55,10 +55,20 @@ export class FilesService { }); } - //TODO list the files + public async search(limit: number, offset: number, searchField: string) { + return await this.database + .use() + .select() + .from(FilesTable) + .where(ilike(FilesTable.fileName, String(searchField))) + .limit(limit) + .offset(offset) + .prepare("searchFiles") + .execute(); + } //TODO save a file - public async set() { + public async save() { } }