Skip to content

Commit bcd1019

Browse files
committed
add application/:address
1 parent fdddc47 commit bcd1019

2 files changed

Lines changed: 43 additions & 10 deletions

File tree

src/endpoints/applications/applications.controller.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { Controller, DefaultValuePipe, Get, ParseIntPipe, Query } from "@nestjs/common";
1+
import { Controller, DefaultValuePipe, Get, Param, ParseIntPipe, Query } from "@nestjs/common";
22
import { ApiOkResponse, ApiOperation, ApiQuery, ApiTags } from "@nestjs/swagger";
33
import { SortOrder } from "src/common/entities/sort.order";
44
import { QueryPagination } from "src/common/entities/query.pagination";
55
import { ApplicationsService } from "./applications.service";
66
import { Applications } from "./entities/applications";
77
import { ApplicationFilter, UsersCountRange } from "./entities/application.filter";
88
import { ApplicationSort } from "./entities/application.sort";
9-
import { ParseAddressArrayPipe, ParseEnumPipe, ParseBoolPipe } from "@multiversx/sdk-nestjs-common";
9+
import { ParseAddressArrayPipe, ParseEnumPipe, ParseBoolPipe, ParseAddressPipe } from "@multiversx/sdk-nestjs-common";
1010

1111
@Controller()
1212
@ApiTags('applications')
@@ -86,4 +86,17 @@ export class ApplicationsController {
8686

8787
return await this.applicationsService.getApplicationsCount(filter);
8888
}
89+
90+
@Get('/applications/:address')
91+
@ApiOperation({ summary: 'Smart Contract Application', description: 'Returns a smart contract application' })
92+
@ApiOkResponse({ type: Applications })
93+
@ApiQuery({ name: 'usersCountRange', description: 'Range for users count calculation', required: false, enum: UsersCountRange })
94+
@ApiQuery({ name: 'feesRange', description: 'Range for fees captured calculation', required: false, enum: UsersCountRange })
95+
async getApplication(
96+
@Param('address', ParseAddressPipe) address: string,
97+
@Query('usersCountRange', new ParseEnumPipe(UsersCountRange)) usersCountRange?: UsersCountRange,
98+
@Query('feesRange', new ParseEnumPipe(UsersCountRange)) feesRange?: UsersCountRange,
99+
): Promise<Applications> {
100+
return await this.applicationsService.getApplication(address, usersCountRange, feesRange);
101+
}
89102
}

src/endpoints/applications/applications.service.ts

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,25 +131,45 @@ export class ApplicationsService {
131131
}
132132

133133
async getApplicationUsersCount(applicationAddress: string, range: UsersCountRange): Promise<number> {
134+
const cacheKey = CacheInfo.ApplicationUsersCount(applicationAddress, range).key;
135+
const cachedValue = await this.cachingService.get<number>(cacheKey);
136+
137+
if (cachedValue !== null && cachedValue !== undefined) {
138+
return cachedValue;
139+
}
140+
141+
// Fallback to direct elastic call if not in cache
134142
return await this.elasticIndexerService.getApplicationUsersCount(applicationAddress, range);
135143
}
136144

137145
async getApplicationFeesCaptured(applicationAddress: string, range: UsersCountRange): Promise<string> {
146+
const cacheKey = CacheInfo.ApplicationFeesCaptured(applicationAddress, range).key;
147+
const cachedValue = await this.cachingService.get<string>(cacheKey);
148+
149+
if (cachedValue !== null && cachedValue !== undefined) {
150+
return cachedValue;
151+
}
152+
138153
return await this.elasticIndexerService.getApplicationFeesCaptured(applicationAddress, range);
139154
}
140155

141-
async getApplication(address: string): Promise<Applications> {
142-
const application = await this.elasticIndexerService.getApplication(address);
143-
return new Applications({
144-
address: application.address,
145-
balance: application.balance || '0',
156+
async getApplication(address: string, usersCountRange?: UsersCountRange, feesRange?: UsersCountRange): Promise<Applications> {
157+
const indexResult = await this.elasticIndexerService.getApplication(address);
158+
159+
const application = new Applications({
160+
address: indexResult.address,
161+
balance: indexResult.balance || '0',
146162
usersCount: 0,
147163
feesCaptured: '0',
148164
deployedAt: 0,
149165
deployTxHash: '',
150-
isVerified: application.api_isVerified || false,
151-
txCount: application.api_transfersLast24h || 0,
152-
assets: application.api_assets,
166+
isVerified: indexResult.api_isVerified || false,
167+
txCount: indexResult.api_transfersLast24h || 0,
168+
assets: indexResult.api_assets,
153169
});
170+
171+
await this.enrichApplicationData(application, new ApplicationFilter({ usersCountRange, feesRange }));
172+
173+
return application;
154174
}
155175
}

0 commit comments

Comments
 (0)