65 lines
1.7 KiB
TypeScript
65 lines
1.7 KiB
TypeScript
import {
|
|
Body,
|
|
Controller,
|
|
Delete,
|
|
Get,
|
|
Param,
|
|
Post,
|
|
Put,
|
|
Query,
|
|
} from '@nestjs/common';
|
|
import { PetVarietyVo } from '@/pet-feeder/vo/pet-variety.vo';
|
|
import { PetVarietyService } from '@/pet-feeder/service/pet-variety.service';
|
|
import { PetVarietyMapper } from '@/pet-feeder/mapper/pet-variety.mapper';
|
|
import { PageResultMapper } from '@/core/mapper/page-result.mapper';
|
|
import { SearchPetVarietyFilter } from '@/pet-feeder/dto/search-pet-variety.filter';
|
|
|
|
@Controller('/pet-varieties')
|
|
export class PetVarietyController {
|
|
constructor(
|
|
private readonly petVarietyService: PetVarietyService,
|
|
private readonly petVarietyMapper: PetVarietyMapper,
|
|
) {}
|
|
|
|
@Post()
|
|
async create(@Body('name') name: string) {
|
|
return this.petVarietyMapper.toVo(
|
|
await this.petVarietyService.create(name),
|
|
);
|
|
}
|
|
|
|
@Get('/list')
|
|
async list() {
|
|
return this.petVarietyMapper.toVos(await this.petVarietyService.list());
|
|
}
|
|
@Get('/:id')
|
|
async get(@Param('id') id: string) {
|
|
return this.petVarietyMapper.toVo(await this.petVarietyService.get(id));
|
|
}
|
|
|
|
@Get()
|
|
async search(@Query() searchPetVarietyFilter: SearchPetVarietyFilter) {
|
|
const [data, total] = await this.petVarietyService.search(
|
|
searchPetVarietyFilter,
|
|
);
|
|
return PageResultMapper.toPageResult<PetVarietyVo>(
|
|
this.petVarietyMapper.toVos(data),
|
|
searchPetVarietyFilter.getPage(),
|
|
searchPetVarietyFilter.getSize(),
|
|
total,
|
|
);
|
|
}
|
|
|
|
@Delete('/:id')
|
|
async delete(@Param('id') id: string) {
|
|
await this.petVarietyService.delete(id);
|
|
}
|
|
|
|
@Put('/:id')
|
|
async update(@Param('id') id: string, @Body('name') name: string) {
|
|
return this.petVarietyMapper.toVo(
|
|
await this.petVarietyService.update(id, name),
|
|
);
|
|
}
|
|
}
|