import { BadRequestException, Controller, Get, Query, Req } from '@nestjs/common'; import { SearchQuery, SearchResultView, searchQuerySchema } from '@dorfteich/shared'; import { AuthedRequest } from '../auth/auth.guard'; import { AuthenticatedOnly } from '../permissions/permission.decorators'; import { SearchProvider } from './search.provider'; /** Full-text search (issue #49, ADR 0010). */ @Controller() export class SearchController { constructor(private readonly search: SearchProvider) {} /** * `GET /search?q=…&pondId=…&labels=a,b` — ranked, permission-filtered hits. * `labels` is a comma-separated list; scope defaults to all readable ponds. */ @Get('search') @AuthenticatedOnly() // results are permission-filtered inside the provider async query( @Query('q') q: string, @Query('pondId') pondId: string | undefined, @Query('labels') labels: string | undefined, @Req() request: AuthedRequest, ): Promise { const parsed = searchQuerySchema.safeParse({ q, pondId: pondId || undefined, labels: labels ? labels.split(',').filter(Boolean) : undefined, } satisfies Record); if (!parsed.success) { throw new BadRequestException({ code: 'bad_request' }); } return this.search.search(parsed.data as SearchQuery, request.user!); } }