mirror of
https://github.com/SyncrowIOT/backend.git
synced 2026-10-25 21:47:54 +00:00
Add floor module with controller, service, DTOs, and interfaces
This commit is contained in:
@@ -0,0 +1,102 @@
|
||||
import { FloorService } from '../services/floor.service';
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Get,
|
||||
HttpException,
|
||||
HttpStatus,
|
||||
Param,
|
||||
Post,
|
||||
Query,
|
||||
UseGuards,
|
||||
} from '@nestjs/common';
|
||||
import { ApiTags, ApiBearerAuth } from '@nestjs/swagger';
|
||||
import { JwtAuthGuard } from '../../../libs/common/src/guards/jwt.auth.guard';
|
||||
import { AddFloorDto } from '../dtos/add.floor.dto';
|
||||
import { GetFloorChildDto } from '../dtos/get.floor.dto';
|
||||
|
||||
@ApiTags('Floor Module')
|
||||
@Controller({
|
||||
version: '1',
|
||||
path: 'floor',
|
||||
})
|
||||
export class FloorController {
|
||||
constructor(private readonly floorService: FloorService) {}
|
||||
|
||||
// @ApiBearerAuth()
|
||||
// @UseGuards(JwtAuthGuard)
|
||||
@Post()
|
||||
async addFloor(@Body() addFloorDto: AddFloorDto) {
|
||||
try {
|
||||
await this.floorService.addFloor(addFloorDto);
|
||||
return { message: 'Floor added successfully' };
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get(':floorUuid')
|
||||
async getFloorByUuid(@Param('floorUuid') floorUuid: string) {
|
||||
try {
|
||||
const floor = await this.floorService.getFloorByUuid(floorUuid);
|
||||
return floor;
|
||||
} catch (error) {
|
||||
if (error.status === 404) {
|
||||
throw new HttpException('Floor not found', HttpStatus.NOT_FOUND);
|
||||
} else {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get('child/:floorUuid')
|
||||
async getFloorChildByUuid(
|
||||
@Param('floorUuid') floorUuid: string,
|
||||
@Query() query: GetFloorChildDto,
|
||||
) {
|
||||
try {
|
||||
const floor = await this.floorService.getFloorChildByUuid(
|
||||
floorUuid,
|
||||
query,
|
||||
);
|
||||
return floor;
|
||||
} catch (error) {
|
||||
if (error.status === 404) {
|
||||
throw new HttpException('Floor not found', HttpStatus.NOT_FOUND);
|
||||
} else {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get('parent/:floorUuid')
|
||||
async getFloorParentByUuid(@Param('floorUuid') floorUuid: string) {
|
||||
try {
|
||||
const floor = await this.floorService.getFloorParentByUuid(floorUuid);
|
||||
return floor;
|
||||
} catch (error) {
|
||||
if (error.status === 404) {
|
||||
throw new HttpException('Floor not found', HttpStatus.NOT_FOUND);
|
||||
} else {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export * from './floor.controller';
|
||||
Reference in New Issue
Block a user