diff --git a/backend/src/waitlist/dto.ts b/backend/src/waitlist/dto.ts new file mode 100644 index 00000000..6fd85d6d --- /dev/null +++ b/backend/src/waitlist/dto.ts @@ -0,0 +1,4 @@ +export class JoinWaitlistDto { + workspaceId: string; + userId: string; +} diff --git a/backend/src/waitlist/waitlist.controller.ts b/backend/src/waitlist/waitlist.controller.ts new file mode 100644 index 00000000..c14f921c --- /dev/null +++ b/backend/src/waitlist/waitlist.controller.ts @@ -0,0 +1,20 @@ +import { Controller, Post, Body, Get, Param } from '@nestjs/common'; +import { WaitlistService } from './waitlist.service'; + +@Controller('waitlist') +export class WaitlistController { + constructor(private readonly waitlistService: WaitlistService) {} + + @Post('join') + joinWaitlist( + @Body('workspaceId') workspaceId: string, + @Body('userId') userId: string, + ) { + return this.waitlistService.queueMember(workspaceId, userId); + } + + @Get(':workspaceId') + getQueue(@Param('workspaceId') workspaceId: string) { + return this.waitlistService.getQueue(workspaceId); + } +} diff --git a/backend/src/waitlist/waitlist.module.ts b/backend/src/waitlist/waitlist.module.ts new file mode 100644 index 00000000..616bcefe --- /dev/null +++ b/backend/src/waitlist/waitlist.module.ts @@ -0,0 +1,10 @@ +import { Module } from '@nestjs/common'; +import { WaitlistController } from './waitlist.controller'; +import { WaitlistService } from './waitlist.service'; + +@Module({ + controllers: [WaitlistController], + providers: [WaitlistService], + exports: [WaitlistService], +}) +export class WaitlistModule {} diff --git a/backend/src/waitlist/waitlist.service.spec.ts b/backend/src/waitlist/waitlist.service.spec.ts new file mode 100644 index 00000000..56439bb2 --- /dev/null +++ b/backend/src/waitlist/waitlist.service.spec.ts @@ -0,0 +1,17 @@ +import { Test, TestingModule } from '@nestjs/testing'; +import { WaitlistService } from './waitlist.service'; + +describe('WaitlistService', () => { + let service: WaitlistService; + + beforeEach(async () => { + const module: TestingModule = await Test.createTestingModule({ + providers: [WaitlistService], + }).compile(); + service = module.get(WaitlistService); + }); + + it('should be defined', () => { + expect(service).toBeDefined(); + }); +}); diff --git a/backend/src/waitlist/waitlist.service.ts b/backend/src/waitlist/waitlist.service.ts new file mode 100644 index 00000000..9bffe617 --- /dev/null +++ b/backend/src/waitlist/waitlist.service.ts @@ -0,0 +1,16 @@ +import { Injectable } from '@nestjs/common'; + +@Injectable() +export class WaitlistService { + private queues: Record = {}; + + queueMember(workspaceId: string, userId: string) { + if (!this.queues[workspaceId]) this.queues[workspaceId] = []; + this.queues[workspaceId].push(userId); + return { status: 'queued', position: this.queues[workspaceId].length }; + } + + getQueue(workspaceId: string) { + return this.queues[workspaceId] || []; + } +}