From 5c362432e01bd9512a2250f00e930a2be1739463 Mon Sep 17 00:00:00 2001 From: Krystof Date: Thu, 5 Dec 2024 18:19:07 +0100 Subject: [PATCH] feat(be): infotexts --- apps/backend/src/app.module.ts | 2 ++ .../modules/infotexts/infotexts.controller.ts | 25 +++++++++++++++++++ .../src/modules/infotexts/infotexts.module.ts | 12 +++++++++ .../modules/infotexts/infotexts.service.ts | 12 +++++++++ 4 files changed, 51 insertions(+) create mode 100644 apps/backend/src/modules/infotexts/infotexts.controller.ts create mode 100644 apps/backend/src/modules/infotexts/infotexts.module.ts create mode 100644 apps/backend/src/modules/infotexts/infotexts.service.ts diff --git a/apps/backend/src/app.module.ts b/apps/backend/src/app.module.ts index bce2de1f..dbc5856f 100644 --- a/apps/backend/src/app.module.ts +++ b/apps/backend/src/app.module.ts @@ -10,6 +10,7 @@ import { configModuleConfig } from "src/config/config-module.config"; import { GRAPHQL_PATH } from "src/constants/api"; import { DepartureModule } from "src/modules/departure/departure.module"; import { ImportModule } from "src/modules/import/import.module"; +import { InfotextsModule } from "src/modules/infotexts/infotexts.module"; import { LoggerModule } from "src/modules/logger/logger.module"; import { PlatformModule } from "src/modules/platform/platform.module"; import { PrismaModule } from "src/modules/prisma/prisma.module"; @@ -24,6 +25,7 @@ import { StopModule } from "src/modules/stop/stop.module"; StopModule, PrismaModule, LoggerModule, + InfotextsModule, StatusModule, ConfigModule.forRoot(configModuleConfig), ScheduleModule.forRoot(), diff --git a/apps/backend/src/modules/infotexts/infotexts.controller.ts b/apps/backend/src/modules/infotexts/infotexts.controller.ts new file mode 100644 index 00000000..9fc9859a --- /dev/null +++ b/apps/backend/src/modules/infotexts/infotexts.controller.ts @@ -0,0 +1,25 @@ +import { CacheInterceptor } from "@nestjs/cache-manager"; +import { Controller, Get, UseInterceptors, Version } from "@nestjs/common"; +import { ApiQuery, ApiTags } from "@nestjs/swagger"; + +import { ApiDescription } from "src/decorators/swagger.decorator"; +import { EndpointVersion } from "src/enums/endpoint-version"; +import { InfotextsService } from "src/modules/infotexts/infotexts.service"; +import { metroOnlyQuery } from "src/swagger/query.swagger"; + +@ApiTags("infotexts") +@Controller("infotexts") +@UseInterceptors(CacheInterceptor) +export class InfotextsController { + constructor(private readonly infotextsService: InfotextsService) {} + + @Get("/all") + @Version([EndpointVersion.v1]) + @ApiDescription({ + summary: "PID Infotexts", + }) + @ApiQuery(metroOnlyQuery) + async getAllInfotexts() { + return await this.infotextsService.getInfotexts(); + } +} diff --git a/apps/backend/src/modules/infotexts/infotexts.module.ts b/apps/backend/src/modules/infotexts/infotexts.module.ts new file mode 100644 index 00000000..3b474a7f --- /dev/null +++ b/apps/backend/src/modules/infotexts/infotexts.module.ts @@ -0,0 +1,12 @@ +import { Module } from "@nestjs/common"; + +import { GolemioService } from "src/modules/golemio/golemio.service"; +import { InfotextsController } from "src/modules/infotexts/infotexts.controller"; +import { InfotextsService } from "src/modules/infotexts/infotexts.service"; + +@Module({ + controllers: [InfotextsController], + providers: [InfotextsService, GolemioService], + imports: [], +}) +export class InfotextsModule {} diff --git a/apps/backend/src/modules/infotexts/infotexts.service.ts b/apps/backend/src/modules/infotexts/infotexts.service.ts new file mode 100644 index 00000000..22d7d5c9 --- /dev/null +++ b/apps/backend/src/modules/infotexts/infotexts.service.ts @@ -0,0 +1,12 @@ +import { Injectable } from "@nestjs/common"; + +import { GolemioService } from "src/modules/golemio/golemio.service"; + +@Injectable() +export class InfotextsService { + constructor(private golemioService: GolemioService) {} + + async getInfotexts() { + return await this.golemioService.getGolemioData("/v3/pid/infotexts"); + } +}