feat(backend): Suche und Filter (Modul 14)
SearchModule mit GET /search?q= über Bienenstände, Völker, Königinnen, Aufgaben und Honigchargen. Kombinierbare Filter (Status, Standort, Bienenstand) in den bestehenden List-Endpunkten.
This commit is contained in:
1 parent
55b9bc2587
commit
146b56d683
15 files changed
+337
-27
No files matched your search
@@ -1,6 +1,14 @@
|
||||
import { Body, Controller, Get, Param, Patch, Post } from '@nestjs/common';
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Get,
|
||||
Param,
|
||||
Patch,
|
||||
Post,
|
||||
Query,
|
||||
} from '@nestjs/common';
|
||||
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
||||
import { Role } from '../../generated/prisma';
|
||||
import { ApiaryStatus, Role } from '../../generated/prisma';
|
||||
import { Roles } from '../auth/decorators/roles.decorator';
|
||||
import { CurrentUser } from '../auth/decorators/current-user.decorator';
|
||||
import type { AuthenticatedUser } from '../auth/types/authenticated-user';
|
||||
@@ -15,8 +23,11 @@ export class ApiariesController {
|
||||
constructor(private readonly apiariesService: ApiariesService) {}
|
||||
|
||||
@Get()
|
||||
findAll() {
|
||||
return this.apiariesService.findAll();
|
||||
findAll(
|
||||
@Query('status') status?: ApiaryStatus,
|
||||
@Query('location') location?: string,
|
||||
) {
|
||||
return this.apiariesService.findAll({ status, location });
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
import { AuditLogService } from '../audit/audit-log.service';
|
||||
import { Apiary } from '../../generated/prisma';
|
||||
import { Apiary, ApiaryStatus } from '../../generated/prisma';
|
||||
import { CreateApiaryDto } from './dto/create-apiary.dto';
|
||||
import { UpdateApiaryDto } from './dto/update-apiary.dto';
|
||||
|
||||
export interface ApiaryFilter {
|
||||
status?: ApiaryStatus;
|
||||
location?: string;
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class ApiariesService {
|
||||
constructor(
|
||||
@@ -12,8 +17,16 @@ export class ApiariesService {
|
||||
private readonly auditLog: AuditLogService,
|
||||
) {}
|
||||
|
||||
async findAll(): Promise<Apiary[]> {
|
||||
return this.prisma.apiary.findMany({ orderBy: { name: 'asc' } });
|
||||
async findAll(filter: ApiaryFilter = {}): Promise<Apiary[]> {
|
||||
return this.prisma.apiary.findMany({
|
||||
where: {
|
||||
status: filter.status,
|
||||
location: filter.location
|
||||
? { contains: filter.location, mode: 'insensitive' }
|
||||
: undefined,
|
||||
},
|
||||
orderBy: { name: 'asc' },
|
||||
});
|
||||
}
|
||||
|
||||
async findById(id: string): Promise<Apiary> {
|
||||
|
||||
Reference in new issue
Block a user