From 1881a7e6c45cd9d588bf88146663eec14393e41e Mon Sep 17 00:00:00 2001 From: Mathis Date: Mon, 23 Sep 2024 12:08:21 +0200 Subject: [PATCH] Add CRUD endpoints for GroupsController Implemented GET, POST, and DELETE endpoints in GroupsController to manage groups and associated files with pagination and optional search functionality. Created an ISearchQuery interface to standardize query parameters across methods. --- .../src/app/groups/groups.controller.ts | 38 ++++++++++++++++++- apps/backend/src/app/groups/groups.dto.ts | 0 apps/backend/src/app/groups/groups.types.ts | 5 +++ 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 apps/backend/src/app/groups/groups.dto.ts create mode 100644 apps/backend/src/app/groups/groups.types.ts diff --git a/apps/backend/src/app/groups/groups.controller.ts b/apps/backend/src/app/groups/groups.controller.ts index 728e29e..85569e5 100644 --- a/apps/backend/src/app/groups/groups.controller.ts +++ b/apps/backend/src/app/groups/groups.controller.ts @@ -1,7 +1,43 @@ -import { Controller } from '@nestjs/common'; +import { Controller, DefaultValuePipe, Delete, Get, Param, ParseIntPipe, Post, Query } from '@nestjs/common'; import { GroupsService } from './groups.service'; +import { ISearchQuery } from 'apps/backend/src/app/groups/groups.types'; @Controller('groups') export class GroupsController { constructor(private readonly groupsService: GroupsService) {} + + //GET all groups with limit and offset + optional search + @Get() + async findMany( + @Query("limit", new DefaultValuePipe(20), ParseIntPipe) limit: number, + @Query("offset", new DefaultValuePipe(0), ParseIntPipe) offset: number, + @Query("search", new DefaultValuePipe("")) search: string + ) { + const query = {limit, offset, search} + + } + + //POST a new group + @Post("new") + async newGroup() { + + } + + //DELETE a group + @Delete(":groupId") + async deleteGroup(@Param('groupId') groupId: string) { + + } + + //GET files associated to group with limit and offset + @Get(":groupId") + async getForGroup( + @Query("limit", new DefaultValuePipe(20), ParseIntPipe) limit: number, + @Query("offset", new DefaultValuePipe(0), ParseIntPipe) offset: number, + @Query("search", new DefaultValuePipe("")) search: string, + @Param('groupId') groupId: string + ) { + const query = {limit, offset, search} + + } } diff --git a/apps/backend/src/app/groups/groups.dto.ts b/apps/backend/src/app/groups/groups.dto.ts new file mode 100644 index 0000000..e69de29 diff --git a/apps/backend/src/app/groups/groups.types.ts b/apps/backend/src/app/groups/groups.types.ts new file mode 100644 index 0000000..5fcc2ee --- /dev/null +++ b/apps/backend/src/app/groups/groups.types.ts @@ -0,0 +1,5 @@ +export interface ISearchQuery { + limit: number; + offset: number; + search?: string; +} \ No newline at end of file