From f5bcd839b47d97c03b850e56f2c37bc3ae8646be Mon Sep 17 00:00:00 2001 From: Micha Vie Date: Tue, 9 Jan 2024 22:49:40 +0100 Subject: [PATCH] add api app endpoints --- .../api/src/endpoints/apps/apps.controller.ts | 25 +++++++++++++++++++ .../src/endpoints/apps/entities/app.value.ts | 21 ++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 apps/api/src/endpoints/apps/entities/app.value.ts diff --git a/apps/api/src/endpoints/apps/apps.controller.ts b/apps/api/src/endpoints/apps/apps.controller.ts index c9f5a65..001cf01 100644 --- a/apps/api/src/endpoints/apps/apps.controller.ts +++ b/apps/api/src/endpoints/apps/apps.controller.ts @@ -1,4 +1,5 @@ import { ApiResponse } from '@nestjs/swagger' +import { AppValue } from './entities/app.value' import { AppService, DelegationService } from '@mvx-monorepo/common' import { Controller, Get, NotFoundException, Param } from '@nestjs/common' @@ -9,6 +10,30 @@ export class AppsController { private readonly delegationService: DelegationService ) {} + // TODO: @UseGuards(NativeAuthGuard) + @Get('/apps') + @ApiResponse({ status: 200 }) + async index() { + const apps = await this.appService.getApps() + const values = apps.map((app) => AppValue.fromAppInfo(app)) + + return values + } + + // TODO: @UseGuards(NativeAuthGuard) + @Get('/apps/:appid') + @ApiResponse({ status: 200 }) + @ApiResponse({ status: 404 }) + async show(@Param('appid') appId: string) { + const app = await this.appService.getAppById(+appId) + + if (!app) { + throw new NotFoundException('App not found') + } + + return AppValue.fromAppInfo(app) + } + // TODO: @UseGuards(NativeAuthGuard) @Get('/apps/sync') @ApiResponse({ status: 200 }) diff --git a/apps/api/src/endpoints/apps/entities/app.value.ts b/apps/api/src/endpoints/apps/entities/app.value.ts new file mode 100644 index 0000000..1ee6a9c --- /dev/null +++ b/apps/api/src/endpoints/apps/entities/app.value.ts @@ -0,0 +1,21 @@ +import { AppInfo } from '@mvx-monorepo/common' + +export class AppValue { + id: number + name: string + manager: string + createdAt: number + dataCollections: string[] + + constructor(id: number, name: string, manager: string, createdAt: number, dataCollections: string[]) { + this.id = id + this.name = name + this.manager = manager + this.createdAt = createdAt + this.dataCollections = dataCollections + } + + static fromAppInfo(info: AppInfo): AppValue { + return new AppValue(info.id, info.name, info.manager, info.createdAt, info.dataCollections) + } +}