start lrt api client

This commit is contained in:
Jurgis Sakalauskas
2022-12-07 21:21:01 +02:00
parent 059904d745
commit 9d00d549b6
5 changed files with 118 additions and 13 deletions
+7 -11
View File
@@ -1,14 +1,13 @@
import { Controller, Get, Param, Query, Req } from '@nestjs/common';
import { Request } from 'express';
import { LrtService } from './lrt.service';
import { HttpService } from '@nestjs/axios';
import { firstValueFrom } from 'rxjs';
import { LrtApiClient } from './lrt-api.client';
@Controller('api/lrt')
export class LrtController {
constructor(
private readonly lrtService: LrtService,
private readonly httpService: HttpService,
private readonly lrtApiClient: LrtApiClient,
) {}
@Get()
@@ -27,19 +26,15 @@ export class LrtController {
@Get('recent')
async getRecent(@Req() request: Request) {
const resp = await firstValueFrom(
this.httpService.get('http://localhost:3000/api'),
);
return {
mod: 'lrt',
path: request.url,
recent: true,
resp: resp.data,
};
}
@Get('cat/:id')
getCategory(@Req() request: Request, @Param('id') id: number) {
async getCategory(@Req() request: Request, @Param('id') id: number) {
return {
mod: 'lrt - category',
path: request.url,
@@ -47,12 +42,13 @@ export class LrtController {
};
}
@Get('tema/:tema')
getTema(@Req() request: Request, @Param('tema') tema: string) {
@Get('tema/:topic')
async getTema(@Req() request: Request, @Param('topic') topic: string) {
const resp = await this.lrtApiClient.getSearch(topic);
return {
mod: 'lrt - category',
path: request.url,
tema: tema,
topic: resp,
};
}