diff --git a/apps/api/src/app/app.module.ts b/apps/api/src/app/app.module.ts index 67bb9e03c..ca19d63bc 100644 --- a/apps/api/src/app/app.module.ts +++ b/apps/api/src/app/app.module.ts @@ -25,6 +25,7 @@ import { AccessModule } from './access/access.module'; import { AccountModule } from './account/account.module'; import { AdminModule } from './admin/admin.module'; import { AppController } from './app.controller'; +import { AssetModule } from './asset/asset.module'; import { AuthDeviceModule } from './auth-device/auth-device.module'; import { AuthModule } from './auth/auth.module'; import { BenchmarkModule } from './benchmark/benchmark.module'; @@ -51,6 +52,7 @@ import { UserModule } from './user/user.module'; AdminModule, AccessModule, AccountModule, + AssetModule, AuthDeviceModule, AuthModule, BenchmarkModule, diff --git a/apps/api/src/app/asset/asset.controller.ts b/apps/api/src/app/asset/asset.controller.ts new file mode 100644 index 000000000..828320f82 --- /dev/null +++ b/apps/api/src/app/asset/asset.controller.ts @@ -0,0 +1,29 @@ +import { AdminService } from '@ghostfolio/api/app/admin/admin.service'; +import { TransformDataSourceInRequestInterceptor } from '@ghostfolio/api/interceptors/transform-data-source-in-request/transform-data-source-in-request.interceptor'; +import { TransformDataSourceInResponseInterceptor } from '@ghostfolio/api/interceptors/transform-data-source-in-response/transform-data-source-in-response.interceptor'; +import type { AdminMarketDataDetails } from '@ghostfolio/common/interfaces'; + +import { Controller, Get, Param, UseInterceptors } from '@nestjs/common'; +import { DataSource } from '@prisma/client'; +import { pick } from 'lodash'; + +@Controller('asset') +export class AssetController { + public constructor(private readonly adminService: AdminService) {} + + @Get(':dataSource/:symbol') + @UseInterceptors(TransformDataSourceInRequestInterceptor) + @UseInterceptors(TransformDataSourceInResponseInterceptor) + public async getAsset( + @Param('dataSource') dataSource: DataSource, + @Param('symbol') symbol: string + ): Promise { + const { assetProfile, marketData } = + await this.adminService.getMarketDataBySymbol({ dataSource, symbol }); + + return { + marketData, + assetProfile: pick(assetProfile, ['dataSource', 'name', 'symbol']) + }; + } +} diff --git a/apps/api/src/app/asset/asset.module.ts b/apps/api/src/app/asset/asset.module.ts new file mode 100644 index 000000000..168585ed8 --- /dev/null +++ b/apps/api/src/app/asset/asset.module.ts @@ -0,0 +1,17 @@ +import { AdminModule } from '@ghostfolio/api/app/admin/admin.module'; +import { TransformDataSourceInRequestModule } from '@ghostfolio/api/interceptors/transform-data-source-in-request/transform-data-source-in-request.module'; +import { TransformDataSourceInResponseModule } from '@ghostfolio/api/interceptors/transform-data-source-in-response/transform-data-source-in-response.module'; + +import { Module } from '@nestjs/common'; + +import { AssetController } from './asset.controller'; + +@Module({ + controllers: [AssetController], + imports: [ + AdminModule, + TransformDataSourceInRequestModule, + TransformDataSourceInResponseModule + ] +}) +export class AssetModule {} diff --git a/apps/api/src/app/benchmark/benchmark.controller.ts b/apps/api/src/app/benchmark/benchmark.controller.ts index 3f6db6256..b842ad8e5 100644 --- a/apps/api/src/app/benchmark/benchmark.controller.ts +++ b/apps/api/src/app/benchmark/benchmark.controller.ts @@ -30,14 +30,12 @@ import { REQUEST } from '@nestjs/core'; import { AuthGuard } from '@nestjs/passport'; import { DataSource } from '@prisma/client'; import { StatusCodes, getReasonPhrase } from 'http-status-codes'; -import { pick } from 'lodash'; import { BenchmarkService } from './benchmark.service'; @Controller('benchmark') export class BenchmarkController { public constructor( - private readonly adminService: AdminService, private readonly benchmarkService: BenchmarkService, @Inject(REQUEST) private readonly request: RequestWithUser ) {} @@ -106,23 +104,6 @@ export class BenchmarkController { }; } - @Get(':dataSource/:symbol') - @UseGuards(AuthGuard('jwt'), HasPermissionGuard) - @UseInterceptors(TransformDataSourceInRequestInterceptor) - @UseInterceptors(TransformDataSourceInResponseInterceptor) - public async getBenchmarkMarketData( - @Param('dataSource') dataSource: DataSource, - @Param('symbol') symbol: string - ): Promise { - const { assetProfile, marketData } = - await this.adminService.getMarketDataBySymbol({ dataSource, symbol }); - - return { - marketData, - assetProfile: pick(assetProfile, ['dataSource', 'name', 'symbol']) - }; - } - @Get(':dataSource/:symbol/:startDateString') @UseGuards(AuthGuard('jwt'), HasPermissionGuard) @UseInterceptors(TransformDataSourceInRequestInterceptor) diff --git a/apps/api/src/app/benchmark/benchmark.module.ts b/apps/api/src/app/benchmark/benchmark.module.ts index 7f0426797..d81754e4e 100644 --- a/apps/api/src/app/benchmark/benchmark.module.ts +++ b/apps/api/src/app/benchmark/benchmark.module.ts @@ -1,4 +1,3 @@ -import { AdminModule } from '@ghostfolio/api/app/admin/admin.module'; import { RedisCacheModule } from '@ghostfolio/api/app/redis-cache/redis-cache.module'; import { SubscriptionModule } from '@ghostfolio/api/app/subscription/subscription.module'; import { SymbolModule } from '@ghostfolio/api/app/symbol/symbol.module'; @@ -20,7 +19,6 @@ import { BenchmarkService } from './benchmark.service'; controllers: [BenchmarkController], exports: [BenchmarkService], imports: [ - AdminModule, DataProviderModule, ExchangeRateDataModule, MarketDataModule, diff --git a/apps/client/src/app/services/data.service.ts b/apps/client/src/app/services/data.service.ts index cc17ef26e..64e498d12 100644 --- a/apps/client/src/app/services/data.service.ts +++ b/apps/client/src/app/services/data.service.ts @@ -285,11 +285,11 @@ export class DataService { return this.http.get('/api/v1/access'); } - public fetchBenchmark({ + public fetchAsset({ dataSource, symbol }: UniqueAsset): Observable { - return this.http.get(`/api/v1/benchmark/${dataSource}/${symbol}`).pipe( + return this.http.get(`/api/v1/asset/${dataSource}/${symbol}`).pipe( map((data) => { for (const item of data.marketData) { item.date = parseISO(item.date); diff --git a/libs/ui/src/lib/benchmark/benchmark-detail-dialog/benchmark-detail-dialog.component.ts b/libs/ui/src/lib/benchmark/benchmark-detail-dialog/benchmark-detail-dialog.component.ts index f6b8d62aa..73af9e681 100644 --- a/libs/ui/src/lib/benchmark/benchmark-detail-dialog/benchmark-detail-dialog.component.ts +++ b/libs/ui/src/lib/benchmark/benchmark-detail-dialog/benchmark-detail-dialog.component.ts @@ -60,7 +60,7 @@ export class GfBenchmarkDetailDialogComponent implements OnDestroy, OnInit { public ngOnInit() { this.dataService - .fetchBenchmark({ + .fetchAsset({ dataSource: this.data.dataSource, symbol: this.data.symbol })