main
parent
b294df9cf5
commit
51b37886e0
File diff suppressed because one or more lines are too long
@ -1 +1 @@ |
|||||||
{"version":3,"file":"users.controller.js","sourceRoot":"","sources":["../../src/users/users.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAA6E;AAC7E,mDAA+C;AAC/C,mEAA8D;AAC9D,2DAAuD;AAEvD,6CAAwE;AACxE,yEAAmE;AAI5D,IAAM,eAAe,GAArB,MAAM,eAAe;IACG;IAA7B,YAA6B,WAAyB;QAAzB,gBAAW,GAAX,WAAW,CAAc;IAAG,CAAC;IAMpD,AAAN,KAAK,CAAC,cAAc,CACP,GAAgB,EACnB,GAAsB;QAE9B,MAAM,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAC5D,OAAO,MAAM,IAAI,CAAC,WAAW,CAAC,sBAAsB,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACxE,CAAC;CACF,CAAA;AAdY,0CAAe;AAOpB;IAJL,IAAA,cAAK,EAAC,UAAU,CAAC;IACjB,IAAA,kBAAS,EAAC,6BAAY,CAAC;IACvB,IAAA,uBAAa,GAAE;IACf,IAAA,uBAAa,EAAC,EAAE,WAAW,EAAE,IAAI,EAAE,IAAI,EAAE,4CAAmB,EAAE,CAAC;;IAE7D,WAAA,IAAA,gBAAO,GAAE,CAAA;IACT,WAAA,IAAA,aAAI,GAAE,CAAA;;6CAAM,uCAAiB;;qDAI/B;0BAbU,eAAe;IAF3B,IAAA,iBAAO,EAAC,KAAK,CAAC;IACd,IAAA,mBAAU,EAAC,OAAO,CAAC;qCAEwB,4BAAY;GAD3C,eAAe,CAc3B"} |
{"version":3,"file":"users.controller.js","sourceRoot":"","sources":["../../src/users/users.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAA6E;AAC7E,mDAA+C;AAC/C,mEAA8D;AAC9D,2DAAuD;AAEvD,6CAAsF;AACtF,yEAAmE;AAI5D,IAAM,eAAe,GAArB,MAAM,eAAe;IACG;IAA7B,YAA6B,WAAyB;QAAzB,gBAAW,GAAX,WAAW,CAAc;IAAG,CAAC;IAOpD,AAAN,KAAK,CAAC,cAAc,CACP,GAAgB,EACnB,GAAsB;QAE9B,MAAM,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAC5D,OAAO,MAAM,IAAI,CAAC,WAAW,CAAC,sBAAsB,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACxE,CAAC;CACF,CAAA;AAfY,0CAAe;AAQpB;IALL,IAAA,cAAK,EAAC,UAAU,CAAC;IACjB,IAAA,kBAAS,EAAC,6BAAY,CAAC;IACvB,IAAA,uBAAa,GAAE;IACf,IAAA,sBAAY,EAAC,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC;IACpC,IAAA,uBAAa,EAAC,EAAE,WAAW,EAAE,IAAI,EAAE,IAAI,EAAE,4CAAmB,EAAE,CAAC;;IAE7D,WAAA,IAAA,gBAAO,GAAE,CAAA;IACT,WAAA,IAAA,aAAI,GAAE,CAAA;;6CAAM,uCAAiB;;qDAI/B;0BAdU,eAAe;IAF3B,IAAA,iBAAO,EAAC,KAAK,CAAC;IACd,IAAA,mBAAU,EAAC,OAAO,CAAC;qCAEwB,4BAAY;GAD3C,eAAe,CAe3B"} |
@ -1,24 +1,108 @@ |
|||||||
import { Controller, Get, Param, ParseIntPipe } from '@nestjs/common'; |
import { |
||||||
|
Body, |
||||||
|
Controller, |
||||||
|
Request, |
||||||
|
Post, |
||||||
|
UseGuards, |
||||||
|
Get, |
||||||
|
ParseIntPipe, |
||||||
|
Param, |
||||||
|
Query, |
||||||
|
} from '@nestjs/common'; |
||||||
import { SensorsService } from './sensors.service'; |
import { SensorsService } from './sensors.service'; |
||||||
import { ApiOkResponse, ApiOperation, ApiTags } from '@nestjs/swagger'; |
import { ApiBearerAuth, ApiOkResponse, ApiOperation, ApiQuery, ApiTags } from '@nestjs/swagger'; |
||||||
import { Sensor } from './entities/sensor.entity'; |
import { Sensor } from './entities/sensor.entity'; |
||||||
|
import { JwtAuthGuard } from 'src/auth/jwt-auth.guard'; |
||||||
|
import { SensorGroupResponseDto } from './dto/sensor-group-response.dto'; |
||||||
|
import { AuthRequest } from 'src/common/interfaces/auth-request.interface'; |
||||||
|
import { CreateSensorGroupDto } from './dto/create-sensor-group.dto'; |
||||||
|
import { SensorResponseDto } from './dto/sensor-response.dto'; |
||||||
|
import { CreateSensorDto } from './dto/create-sensor.dto'; |
||||||
|
import { SensorDataResponseDto } from './dto/sensor-data-response.dto'; |
||||||
|
import { CreateSensorDataDto } from './dto/create-sensor-data.dto'; |
||||||
|
|
||||||
@ApiTags('센서') |
@ApiTags('센서') |
||||||
|
@ApiBearerAuth() |
||||||
|
@UseGuards(JwtAuthGuard) |
||||||
@Controller('sensors') |
@Controller('sensors') |
||||||
export class SensorsController { |
export class SensorsController { |
||||||
constructor(private readonly sensorService: SensorsService) {} |
constructor(private readonly sensorService: SensorsService) {} |
||||||
|
|
||||||
@Get() |
//#region Group
|
||||||
@ApiOperation({ summary: '센서 목록 조회' }) |
@Post('sensor-groups') |
||||||
@ApiOkResponse({ description: '센서 목록', type: [Sensor] }) |
@ApiOperation({ summary: '센서 그룹 생성' }) |
||||||
async findAll(): Promise<Sensor[]> { |
@ApiOkResponse({ description: '성공', type: SensorGroupResponseDto }) |
||||||
return this.findAll(); |
async createGroup( |
||||||
|
@Request() req: AuthRequest, |
||||||
|
@Body() dto: CreateSensorGroupDto, |
||||||
|
): Promise<SensorGroupResponseDto> { |
||||||
|
return this.sensorService.createGroup(req.user.userId, dto); |
||||||
} |
} |
||||||
|
|
||||||
@Get(':id') |
@Get('sensor-groups') |
||||||
@ApiOperation({ summary: '특정 센서 조회' }) |
@ApiOperation({ summary: '센서 그룹 목록' }) |
||||||
@ApiOkResponse({ description: '센서', type: [Sensor] }) |
@ApiOkResponse({ description: '성공', type: [SensorGroupResponseDto] }) |
||||||
async findOne(@Param('id', ParseIntPipe) id: number): Promise<Sensor | null> { |
async myGroup(@Request() req: AuthRequest): Promise<SensorGroupResponseDto[]> { |
||||||
return this.findOne(id); |
return this.sensorService.findMyGroups(req.user.userId); |
||||||
} |
} |
||||||
|
//#endregion
|
||||||
|
|
||||||
|
//#region Sensor
|
||||||
|
@Post('sensors') |
||||||
|
@ApiOperation({ summary: '센서 생성' }) |
||||||
|
@ApiOkResponse({ description: '성공', type: SensorResponseDto }) |
||||||
|
async createSensor( |
||||||
|
@Request() req: AuthRequest, |
||||||
|
@Body() dto: CreateSensorDto, |
||||||
|
): Promise<SensorResponseDto> { |
||||||
|
return this.sensorService.createSensor(req.user.userId, dto); |
||||||
|
} |
||||||
|
|
||||||
|
@Get('sensor-groups/:groupId/sensors') |
||||||
|
@ApiOperation({ summary: '센서 목록' }) |
||||||
|
@ApiOkResponse({ description: '성공', type: [SensorResponseDto] }) |
||||||
|
async sensorsInGroup( |
||||||
|
@Request() req: AuthRequest, |
||||||
|
@Param('groupId', ParseIntPipe) groupId: number, |
||||||
|
): Promise<SensorResponseDto[]> { |
||||||
|
return this.sensorService.findSensorsInGroup(req.user.userId, groupId); |
||||||
|
} |
||||||
|
//#endregion
|
||||||
|
|
||||||
|
//#region Data
|
||||||
|
@Post('sensors/:sensorId/data') |
||||||
|
@ApiOperation({ summary: '센서 데이터 생성' }) |
||||||
|
@ApiOkResponse({ description: '성공', type: SensorDataResponseDto }) |
||||||
|
async createData( |
||||||
|
@Request() req: AuthRequest, |
||||||
|
@Param('sensorId', ParseIntPipe) sensorId: number, |
||||||
|
@Body() dto: CreateSensorDataDto, |
||||||
|
): Promise<SensorDataResponseDto> { |
||||||
|
return this.sensorService.createSensorData(req.user.userId, sensorId, dto); |
||||||
|
} |
||||||
|
|
||||||
|
@Get('sensors/:sensorId/data') |
||||||
|
@ApiOperation({ summary: '센서 데이터 조회' }) |
||||||
|
@ApiQuery({ name: 'from', required: false, description: 'ISO날짜' }) |
||||||
|
@ApiQuery({ name: 'to', required: false, description: 'ISO날짜' }) |
||||||
|
@ApiQuery({ name: 'limit', required: false, description: '조회 개수 (기본50, 최대 500)' }) |
||||||
|
@ApiOkResponse({ description: '성공', type: [SensorDataResponseDto] }) |
||||||
|
async getData( |
||||||
|
@Request() req: AuthRequest, |
||||||
|
@Param('sensorId', ParseIntPipe) sensorId: number, |
||||||
|
@Query('from') from?: string, |
||||||
|
@Query('to') to?: string, |
||||||
|
@Query('limit') limit?: string, |
||||||
|
): Promise<SensorDataResponseDto[]> { |
||||||
|
const parsedFrom = from ? new Date(from) : undefined; |
||||||
|
const parsedTo = to ? new Date(to) : undefined; |
||||||
|
const parsedLimit = limit ? Number(limit) : undefined; |
||||||
|
|
||||||
|
return this.sensorService.findSensorData(req.user.userId, sensorId, { |
||||||
|
from: parsedFrom, |
||||||
|
to: parsedTo, |
||||||
|
limit: parsedLimit, |
||||||
|
}); |
||||||
|
} |
||||||
|
//#endregion
|
||||||
} |
} |
||||||
|
Loading…
Reference in new issue