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 { ColonyStatus, 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';
|
||||
@@ -18,8 +26,11 @@ export class ColoniesController {
|
||||
constructor(private readonly coloniesService: ColoniesService) {}
|
||||
|
||||
@Get()
|
||||
findAll() {
|
||||
return this.coloniesService.findAll();
|
||||
findAll(
|
||||
@Query('status') status?: ColonyStatus,
|
||||
@Query('apiaryId') apiaryId?: string,
|
||||
) {
|
||||
return this.coloniesService.findAll({ status, apiaryId });
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
|
||||
@@ -5,13 +5,18 @@ import {
|
||||
} from '@nestjs/common';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
import { AuditLogService } from '../audit/audit-log.service';
|
||||
import { Colony } from '../../generated/prisma';
|
||||
import { Colony, ColonyStatus } from '../../generated/prisma';
|
||||
import { CreateColonyDto } from './dto/create-colony.dto';
|
||||
import { UpdateColonyDto } from './dto/update-colony.dto';
|
||||
import { MoveColonyDto } from './dto/move-colony.dto';
|
||||
import { SplitColonyDto } from './dto/split-colony.dto';
|
||||
import { MergeColonyDto } from './dto/merge-colony.dto';
|
||||
|
||||
export interface ColonyFilter {
|
||||
status?: ColonyStatus;
|
||||
apiaryId?: string;
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class ColoniesService {
|
||||
constructor(
|
||||
@@ -19,8 +24,11 @@ export class ColoniesService {
|
||||
private readonly auditLog: AuditLogService,
|
||||
) {}
|
||||
|
||||
async findAll(): Promise<Colony[]> {
|
||||
return this.prisma.colony.findMany({ orderBy: { code: 'asc' } });
|
||||
async findAll(filter: ColonyFilter = {}): Promise<Colony[]> {
|
||||
return this.prisma.colony.findMany({
|
||||
where: { status: filter.status, apiaryId: filter.apiaryId },
|
||||
orderBy: { code: 'asc' },
|
||||
});
|
||||
}
|
||||
|
||||
async findById(id: string): Promise<Colony> {
|
||||
|
||||
Reference in new issue
Block a user