Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 1x 12x 1x 1x 12x 2x 2x 2x 12x 1x 12x 1x 12x 1x 1x 1x 12x 1x 12x 1x 12x 1x 12x 1x 12x 1x 12x 1x | // src/modules/search/search.controller.ts
import {
Controller,
Get,
Query,
Post,
UsePipes,
ValidationPipe,
BadRequestException,
UseGuards,
Req,
Body,
Delete,
Param,
ParseIntPipe,
HttpCode,
HttpStatus,
Patch,
} from '@nestjs/common';
import { SearchService } from '@app/modules/search/search.service';
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
import { SearchFilterInput } from '@app/modules/search/dto/search-filter.input';
import { sanitizeInput } from '@app/utils/sanitize';
import { JwtAuthGuard } from '@common/guards/jwt-auth.guard';
import { User } from '@prisma/client';
import { SaveSearchDto } from '@app/modules/search/dto/save-search.dto';
@ApiTags('Search')
@Controller('search')
export class SearchController {
constructor(private readonly searchService: SearchService) {}
@Get('manifest')
@ApiOperation({ summary: 'Get search filter manifest' })
getFilterManifest() {
return this.searchService.getFilterManifest();
}
@Post('index')
@ApiOperation({ summary: 'Reindex all listings (admin task)' })
async indexAll() {
await this.searchService.indexAllListings();
return { status: 'indexed' };
}
@Get()
@UsePipes(new ValidationPipe({ whitelist: true, transform: true }))
@ApiOperation({ summary: 'Search listings' })
async query(@Query() query: SearchFilterInput) {
try {
const sanitized = sanitizeInput(query);
return this.searchService.search(sanitized);
} catch (_err) {
throw new BadRequestException('Invalid search parameters');
}
}
@Get('autocomplete')
@ApiOperation({ summary: 'Autocomplete listing titles/locations' })
async autocomplete(@Query('prefix') prefix: string) {
return this.searchService.autocomplete(prefix);
}
@Get('suggestions')
@ApiOperation({ summary: 'Suggest search queries' })
async suggestions(@Query('query') query: string) {
return this.searchService.suggest(query);
}
@Get('map')
@UsePipes(new ValidationPipe({ whitelist: true, transform: true }))
@ApiOperation({ summary: 'Map search (geo)' })
async mapSearch(@Query() query: SearchFilterInput) {
try {
const sanitized = sanitizeInput(query);
return this.searchService.mapSearch(sanitized);
} catch (_err) {
throw new BadRequestException('Invalid search parameters');
}
}
@Post('save')
@UseGuards(JwtAuthGuard)
@ApiBearerAuth()
@ApiOperation({ summary: 'Save a search', description: 'Requires authentication.' })
saveSearch(
@Req() req: { user: User },
@Body() saveSearchDto: SaveSearchDto,
) {
return this.searchService.saveSearch(req.user, saveSearchDto);
}
@Get('saved')
@UseGuards(JwtAuthGuard)
@ApiBearerAuth()
@ApiOperation({ summary: 'List saved searches', description: 'Requires authentication.' })
getSavedSearches(@Req() req: { user: User }) {
return this.searchService.getSavedSearches(req.user);
}
@Delete('saved/:id')
@UseGuards(JwtAuthGuard)
@HttpCode(HttpStatus.NO_CONTENT)
@ApiBearerAuth()
@ApiOperation({ summary: 'Delete a saved search', description: 'Requires authentication.' })
deleteSavedSearch(
@Req() req: { user: User },
@Param('id', ParseIntPipe) id: number,
) {
return this.searchService.deleteSavedSearch(req.user, id);
}
// New: saved search management
@Patch('saved/:id')
@UseGuards(JwtAuthGuard)
@ApiBearerAuth()
@ApiOperation({ summary: 'Update a saved search', description: 'Requires authentication.' })
updateSaved(
@Req() req: { user: User },
@Param('id', ParseIntPipe) id: number,
@Body() body: { name?: string; cadence?: string; channel?: string },
) {
return this.searchService.updateSavedSearch(req.user, id, body);
}
@Post('saved/:id/test')
@UseGuards(JwtAuthGuard)
@ApiBearerAuth()
@ApiOperation({ summary: 'Test a saved search', description: 'Requires authentication.' })
testSaved(@Req() req: { user: User }, @Param('id', ParseIntPipe) id: number) {
return this.searchService.testSavedSearch(req.user, id);
}
@Post('saved/:id/toggle')
@UseGuards(JwtAuthGuard)
@ApiBearerAuth()
@ApiOperation({ summary: 'Toggle a saved search on/off', description: 'Requires authentication.' })
toggleSaved(@Req() req: { user: User }, @Param('id', ParseIntPipe) id: number) {
return this.searchService.toggleSavedSearch(req.user, id);
}
} |