From 01f4f8f1b10379c0bc42fb361b01ce8769b01fa2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mads=20Stenk=C3=A6r?= Date: Mon, 1 Aug 2022 12:36:35 +0200 Subject: [PATCH 1/3] Added Get Adr Algorithms endpoint --- .../chirpstack/network-server.controller.ts | 36 +++++++++++++++++++ .../dto/chirpstack/adr-algorithm.dto.ts | 17 +++++++++ .../list-all-adr-algorithms-response.dto.ts | 5 +++ 3 files changed, 58 insertions(+) create mode 100644 src/controllers/admin-controller/chirpstack/network-server.controller.ts create mode 100644 src/entities/dto/chirpstack/adr-algorithm.dto.ts create mode 100644 src/entities/dto/chirpstack/list-all-adr-algorithms-response.dto.ts diff --git a/src/controllers/admin-controller/chirpstack/network-server.controller.ts b/src/controllers/admin-controller/chirpstack/network-server.controller.ts new file mode 100644 index 00000000..96870bfb --- /dev/null +++ b/src/controllers/admin-controller/chirpstack/network-server.controller.ts @@ -0,0 +1,36 @@ +import { ComposeAuthGuard } from '@auth/compose-auth.guard'; +import { + Controller, + Get, + Logger, + UseGuards, +} from "@nestjs/common"; +import { + ApiBearerAuth, + ApiOperation, + ApiProduces, + ApiTags, +} from "@nestjs/swagger"; + +import { Read, ApplicationAdmin } from "@auth/roles.decorator"; +import { RolesGuard } from "@auth/roles.guard"; +import {ChirpstackSetupNetworkServerService} from "@services/chirpstack/network-server.service"; +import {ListAllDeviceProfilesResponseDto} from "@dto/chirpstack/list-all-adr-algorithms-response.dto"; + +@ApiTags("Chirpstack") +@Controller("chirpstack/network-server") +@UseGuards(ComposeAuthGuard, RolesGuard) +@ApiBearerAuth() +@ApplicationAdmin() +export class NetworkServerController { + constructor(private networkServerService: ChirpstackSetupNetworkServerService) {} + private readonly logger = new Logger(NetworkServerController.name); + + @Get("adr-algorithms") + @ApiProduces("application/json") + @ApiOperation({ summary: "Find all ADR algorithms for the default network server" }) + @Read() + async getAllAdrAlgorithms(): Promise { + return await this.networkServerService.getAdrAlgorithmsForDefaultNetworkServer(); + } +} diff --git a/src/entities/dto/chirpstack/adr-algorithm.dto.ts b/src/entities/dto/chirpstack/adr-algorithm.dto.ts new file mode 100644 index 00000000..b0cbbd0d --- /dev/null +++ b/src/entities/dto/chirpstack/adr-algorithm.dto.ts @@ -0,0 +1,17 @@ +import { ApiProperty } from "@nestjs/swagger"; +import { + IsString, + Length, +} from "class-validator"; + +export class AdrAlgorithmDto { + @ApiProperty({ required: true }) + @IsString() + @Length(1, 1024) + id: string; + + @ApiProperty({ required: true }) + @IsString() + @Length(1, 1024) + name: string; +} diff --git a/src/entities/dto/chirpstack/list-all-adr-algorithms-response.dto.ts b/src/entities/dto/chirpstack/list-all-adr-algorithms-response.dto.ts new file mode 100644 index 00000000..03eb75d9 --- /dev/null +++ b/src/entities/dto/chirpstack/list-all-adr-algorithms-response.dto.ts @@ -0,0 +1,5 @@ +import {AdrAlgorithmDto} from "@dto/chirpstack/adr-algorithm.dto"; + +export class ListAllDeviceProfilesResponseDto { + adrAlgorithms: AdrAlgorithmDto[]; +} From 2e1dea41bdba43cd62befa35febddb983de6d200 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mads=20Stenk=C3=A6r?= Date: Mon, 1 Aug 2022 13:15:41 +0200 Subject: [PATCH 2/3] Missing part for list all adr algorithms --- .../chirpstack/network-server.controller.ts | 6 +++--- src/entities/dto/chirpstack/device-profile.dto.ts | 4 ++++ .../dto/chirpstack/list-all-adr-algorithms-response.dto.ts | 4 ++-- .../device-integrations/chirpstack-administration.module.ts | 2 ++ src/services/chirpstack/network-server.service.ts | 6 ++++++ 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/controllers/admin-controller/chirpstack/network-server.controller.ts b/src/controllers/admin-controller/chirpstack/network-server.controller.ts index 96870bfb..4016f3a8 100644 --- a/src/controllers/admin-controller/chirpstack/network-server.controller.ts +++ b/src/controllers/admin-controller/chirpstack/network-server.controller.ts @@ -14,8 +14,8 @@ import { import { Read, ApplicationAdmin } from "@auth/roles.decorator"; import { RolesGuard } from "@auth/roles.guard"; -import {ChirpstackSetupNetworkServerService} from "@services/chirpstack/network-server.service"; -import {ListAllDeviceProfilesResponseDto} from "@dto/chirpstack/list-all-adr-algorithms-response.dto"; +import { ChirpstackSetupNetworkServerService } from "@services/chirpstack/network-server.service"; +import { ListAllAdrAlgorithmsResponseDto } from "@dto/chirpstack/list-all-adr-algorithms-response.dto"; @ApiTags("Chirpstack") @Controller("chirpstack/network-server") @@ -30,7 +30,7 @@ export class NetworkServerController { @ApiProduces("application/json") @ApiOperation({ summary: "Find all ADR algorithms for the default network server" }) @Read() - async getAllAdrAlgorithms(): Promise { + async getAllAdrAlgorithms(): Promise { return await this.networkServerService.getAdrAlgorithmsForDefaultNetworkServer(); } } diff --git a/src/entities/dto/chirpstack/device-profile.dto.ts b/src/entities/dto/chirpstack/device-profile.dto.ts index 1301aedb..51df9b1c 100644 --- a/src/entities/dto/chirpstack/device-profile.dto.ts +++ b/src/entities/dto/chirpstack/device-profile.dto.ts @@ -27,6 +27,10 @@ export class DeviceProfileDto { @ApiProperty({ required: true }) regParamsRevision: "A" | "B"; + @ApiProperty({ required: false }) + @IsString() + adrAlgorithmID?: string; + @ApiProperty({ required: false }) @ValidateIf((o: DeviceProfileDto) => o.supportsClassB) @Min(0) diff --git a/src/entities/dto/chirpstack/list-all-adr-algorithms-response.dto.ts b/src/entities/dto/chirpstack/list-all-adr-algorithms-response.dto.ts index 03eb75d9..6ba12710 100644 --- a/src/entities/dto/chirpstack/list-all-adr-algorithms-response.dto.ts +++ b/src/entities/dto/chirpstack/list-all-adr-algorithms-response.dto.ts @@ -1,5 +1,5 @@ -import {AdrAlgorithmDto} from "@dto/chirpstack/adr-algorithm.dto"; +import { AdrAlgorithmDto } from "@dto/chirpstack/adr-algorithm.dto"; -export class ListAllDeviceProfilesResponseDto { +export class ListAllAdrAlgorithmsResponseDto { adrAlgorithms: AdrAlgorithmDto[]; } diff --git a/src/modules/device-integrations/chirpstack-administration.module.ts b/src/modules/device-integrations/chirpstack-administration.module.ts index bc1fc45c..f0bf743d 100644 --- a/src/modules/device-integrations/chirpstack-administration.module.ts +++ b/src/modules/device-integrations/chirpstack-administration.module.ts @@ -10,12 +10,14 @@ import { DeviceProfileService } from "@services/chirpstack/device-profile.servic import { GenericChirpstackConfigurationService } from "@services/chirpstack/generic-chirpstack-configuration.service"; import { ChirpstackSetupNetworkServerService } from "@services/chirpstack/network-server.service"; import { ServiceProfileService } from "@services/chirpstack/service-profile.service"; +import { NetworkServerController } from "@admin-controller/chirpstack/network-server.controller"; @Module({ controllers: [ ChirpstackGatewayController, ServiceProfileController, DeviceProfileController, + NetworkServerController ], imports: [HttpModule, ConfigModule.forRoot({ load: [configuration] })], providers: [ diff --git a/src/services/chirpstack/network-server.service.ts b/src/services/chirpstack/network-server.service.ts index 8a50325f..cf4d3298 100644 --- a/src/services/chirpstack/network-server.service.ts +++ b/src/services/chirpstack/network-server.service.ts @@ -6,6 +6,7 @@ import { ListAllNetworkServerResponseDto } from "@dto/chirpstack/list-all-networ import { NetworkServerDto } from "@dto/chirpstack/network-server.dto"; import { GenericChirpstackConfigurationService } from "./generic-chirpstack-configuration.service"; +import { ListAllAdrAlgorithmsResponseDto } from "@dto/chirpstack/list-all-adr-algorithms-response.dto"; @Injectable() export class ChirpstackSetupNetworkServerService @@ -68,4 +69,9 @@ export class ChirpstackSetupNetworkServerService return createNetworkServerDto; } + + public async getAdrAlgorithmsForDefaultNetworkServer(): Promise { + const networkServerId: string = await this.getDefaultNetworkServerId(); + return await this.get(`network-servers/${networkServerId}/adr-algorithms`); + } } From a333162af099cff1adea73891c4fdb7cafd89f60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mads=20Stenk=C3=A6r?= Date: Thu, 15 Sep 2022 11:16:22 +0200 Subject: [PATCH 3/3] Implicit type for networkServerId --- src/services/chirpstack/network-server.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/chirpstack/network-server.service.ts b/src/services/chirpstack/network-server.service.ts index cf4d3298..02cce160 100644 --- a/src/services/chirpstack/network-server.service.ts +++ b/src/services/chirpstack/network-server.service.ts @@ -71,7 +71,7 @@ export class ChirpstackSetupNetworkServerService } public async getAdrAlgorithmsForDefaultNetworkServer(): Promise { - const networkServerId: string = await this.getDefaultNetworkServerId(); + const networkServerId = await this.getDefaultNetworkServerId(); return await this.get(`network-servers/${networkServerId}/adr-algorithms`); } }