| 1 | import { Controller, Get, Query } from '@nestjs/common'; |
| 2 | import { |
| 3 | ApiBadRequestResponse, |
| 4 | ApiOkResponse, |
| 5 | ApiOperation, |
| 6 | ApiServiceUnavailableResponse, |
| 7 | ApiTags, |
| 8 | } from '@nestjs/swagger'; |
| 9 | import { OptionalAuth } |
| 10 | |
| 11 | import { ErrorResponseDTO } |
| 12 | import { GetRepositoriesQueryDTO } |
| 13 | import { |
| 14 | SearchCodeQueryDTO, |
| 15 | SearchCodeResponseDTO, |
| 16 | } from './dto/search-code.dto.js'; |
| 17 | import { SearchRepositoriesResponseDTO } |
| 18 | import { RepositoriesService } |
| 19 | |
| 20 | @Controller('search') |
| 21 | @ApiTags('Search') |
| 22 | export class SearchController |
| 23 | constructor(private readonly |
| 24 | |
| 25 | @Get('repositories' |
| 26 | @OptionalAuth() |
| 27 | @ApiOperation({ |
| 28 | summary: 'Search repositories', |
| 29 | description: |
| 30 | 'Public repositories whose name or description matches, most recently pushed first. Pages are cursor-based: pass a response `nextCursor` back as `cursor`.', |
| 31 | }) |
| 32 | @ApiOkResponse({ type |
| 33 | @ApiBadRequestResponse({ type |
| 34 | searchRepositories( |
| 35 | @Query() query |
| 36 | ): Promise<SearchRepositoriesResponseDTO |
| 37 | return this.repositoriesService |
| 38 | } |
| 39 | |
| 40 | @Get('code' |
| 41 | @OptionalAuth() |
| 42 | @ApiOperation({ |
| 43 | summary: 'Search code', |
| 44 | description: |
| 45 | 'Full-text and regex search over the default branch of public repositories, powered by zoekt.', |
| 46 | }) |
| 47 | @ApiOkResponse({ type |
| 48 | @ApiBadRequestResponse({ type |
| 49 | @ApiServiceUnavailableResponse({ type |
| 50 | searchCode( |
| 51 | @Query() query |
| 52 | ): Promise<SearchCodeResponseDTO |
| 53 | return this.repositoriesService |
| 54 | query: query.q |
| 55 | limit: query.limit |
| 56 | }); |
| 57 | } |
| 58 | } |