mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-16 02:36:19 +00:00
finshed get devices by room id
This commit is contained in:
91
src/device/controllers/device.controller.ts
Normal file
91
src/device/controllers/device.controller.ts
Normal file
@ -0,0 +1,91 @@
|
||||
import { DeviceService } from '../services/device.service';
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Get,
|
||||
Post,
|
||||
UseGuards,
|
||||
Query,
|
||||
Param,
|
||||
Put,
|
||||
Delete,
|
||||
} from '@nestjs/common';
|
||||
import { ApiTags, ApiBearerAuth } from '@nestjs/swagger';
|
||||
import { JwtAuthGuard } from '../../../libs/common/src/guards/jwt.auth.guard';
|
||||
import { AddDeviceDto } from '../dtos/add.device.dto';
|
||||
import { GetDeviceDto } from '../dtos/get.device.dto';
|
||||
import { ControlDeviceDto } from '../dtos/control.device.dto';
|
||||
import { RenameDeviceDto } from '../dtos/rename.device.dto copy';
|
||||
|
||||
@ApiTags('Device Module')
|
||||
@Controller({
|
||||
version: '1',
|
||||
path: 'device',
|
||||
})
|
||||
export class DeviceController {
|
||||
constructor(private readonly deviceService: DeviceService) {}
|
||||
|
||||
// @ApiBearerAuth()
|
||||
// @UseGuards(JwtAuthGuard)
|
||||
@Get('room')
|
||||
async getDevicesByRoomId(@Query() getDevicesDto: GetDeviceDto) {
|
||||
try {
|
||||
return await this.deviceService.getDevicesByRoomId(getDevicesDto);
|
||||
} catch (err) {
|
||||
throw new Error(err);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get(':deviceId')
|
||||
async getDevicesByDeviceId(@Param('deviceId') deviceId: number) {
|
||||
try {
|
||||
return await this.deviceService.getDevicesByDeviceId(deviceId);
|
||||
} catch (err) {
|
||||
throw new Error(err);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Post()
|
||||
async addDevice(@Body() addDeviceDto: AddDeviceDto) {
|
||||
try {
|
||||
return await this.deviceService.addDevice(addDeviceDto);
|
||||
} catch (err) {
|
||||
throw new Error(err);
|
||||
}
|
||||
}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Post('control')
|
||||
async controlDevice(@Body() controlDeviceDto: ControlDeviceDto) {
|
||||
try {
|
||||
return await this.deviceService.controlDevice(controlDeviceDto);
|
||||
} catch (err) {
|
||||
throw new Error(err);
|
||||
}
|
||||
}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Put('rename')
|
||||
async renameDevice(@Body() renameDeviceDto: RenameDeviceDto) {
|
||||
try {
|
||||
return await this.deviceService.renameDevice(renameDeviceDto);
|
||||
} catch (err) {
|
||||
throw new Error(err);
|
||||
}
|
||||
}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Delete(':deviceId')
|
||||
async deleteDevice(@Param('deviceId') deviceId: number) {
|
||||
try {
|
||||
return await this.deviceService.deleteDevice(deviceId);
|
||||
} catch (err) {
|
||||
throw new Error(err);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user