Skip to content

Commit

Permalink
improve the api doc decoration
Browse files Browse the repository at this point in the history
  • Loading branch information
marc-aurele-besner committed Jan 6, 2025
1 parent df71c91 commit 4d0e981
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 26 deletions.
7 changes: 5 additions & 2 deletions indexers/api/src/controllers/accounts.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { Accounts } from '../entities/consensus/accounts.entity';

@ApiTags('accounts')
@ApiTags('Accounts')
@Controller('accounts')
export class AccountsController {
constructor(
Expand All @@ -13,7 +13,10 @@ export class AccountsController {
) {}

@Get(':accountId')
@ApiOperation({ summary: 'Get account details by ID' })
@ApiOperation({
operationId: 'getAccountById',
summary: 'Get account details by ID',
})
@ApiParam({ name: 'accountId', description: 'Account ID or address' })
@ApiResponse({
status: 200,
Expand Down
21 changes: 18 additions & 3 deletions indexers/api/src/controllers/blocks.controller.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,40 @@
import { Controller, Get, NotFoundException, Param } from '@nestjs/common';
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
import { ApiOperation, ApiParam, ApiResponse, ApiTags } from '@nestjs/swagger';
import { Blocks } from '../entities/consensus/blocks.entity';
import { BlocksService } from '../services/blocks.service';

@ApiTags('blocks')
@ApiTags('Blocks')
@Controller('blocks')
export class BlocksController {
constructor(private readonly blocksService: BlocksService) {}

@Get('latest')
@ApiOperation({ summary: 'Get latest block' })
@ApiOperation({
operationId: 'getLatestBlock',
summary: 'Get latest block',
})
@ApiResponse({
status: 200,
description: 'Returns the latest block',
type: Blocks,
})
@ApiResponse({ status: 404, description: 'No blocks found' })
async getLatestBlock(): Promise<Blocks> {
return this.blocksService.findLatest();
}

@Get(':height')
@ApiOperation({
operationId: 'getBlockByHeight',
summary: 'Get block by height',
})
@ApiParam({ name: 'height', description: 'Block height' })
@ApiResponse({
status: 200,
description: 'Returns the block details',
type: Blocks,
})
@ApiResponse({ status: 404, description: 'Block not found' })
async getBlockByHeight(@Param('height') height: string) {
const block = await this.blocksService.findByHeight(Number(height));

Expand Down
21 changes: 0 additions & 21 deletions indexers/api/src/entities/account.entity.ts

This file was deleted.

8 changes: 8 additions & 0 deletions indexers/api/src/entities/consensus/accounts.entity.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,34 @@
import { ApiProperty } from '@nestjs/swagger';
import { Column, Entity } from 'typeorm';
import { BaseEntity } from './base.entity';

@Entity('accounts', { schema: 'consensus' })
export class Accounts extends BaseEntity {
@ApiProperty()
@Column('text')
id: string;

@ApiProperty()
@Column('numeric')
nonce: number;

@ApiProperty()
@Column('numeric')
free: number;

@ApiProperty()
@Column('numeric')
reserved: number;

@ApiProperty()
@Column('numeric', { nullable: true })
total: number;

@ApiProperty()
@Column('numeric')
created_at: number;

@ApiProperty()
@Column('numeric')
updated_at: number;
}
23 changes: 23 additions & 0 deletions indexers/api/src/entities/consensus/blocks.entity.ts
Original file line number Diff line number Diff line change
@@ -1,71 +1,94 @@
import { ApiProperty } from '@nestjs/swagger';
import { Column, Entity } from 'typeorm';
import { BaseEntity } from './base.entity';

@Entity('blocks', { schema: 'consensus' })
export class Blocks extends BaseEntity {
@ApiProperty()
@Column('text')
id: string;

@ApiProperty()
@Column('text')
sort_id: string;

@ApiProperty()
@Column('numeric')
height: number;

@ApiProperty()
@Column('text')
hash: string;

@ApiProperty()
@Column('timestamp without time zone')
timestamp: Date;

@ApiProperty()
@Column('text')
parent_hash: string;

@ApiProperty()
@Column('text')
spec_id: string;

@ApiProperty()
@Column('text')
state_root: string;

@ApiProperty()
@Column('text')
extrinsics_root: string;

@ApiProperty()
@Column('numeric')
space_pledged: number;

@ApiProperty()
@Column('numeric')
blockchain_size: number;

@ApiProperty()
@Column('integer')
extrinsics_count: number;

@ApiProperty()
@Column('integer')
events_count: number;

@ApiProperty()
@Column('integer')
transfers_count: number;

@ApiProperty()
@Column('integer')
rewards_count: number;

@ApiProperty()
@Column('integer')
block_rewards_count: number;

@ApiProperty()
@Column('integer')
vote_rewards_count: number;

@ApiProperty()
@Column('numeric')
transfer_value: number;

@ApiProperty()
@Column('numeric')
reward_value: number;

@ApiProperty()
@Column('numeric')
block_reward_value: number;

@ApiProperty()
@Column('numeric')
vote_reward_value: number;

@ApiProperty()
@Column('text')
author_id: string;
}
21 changes: 21 additions & 0 deletions indexers/api/src/entities/consensus/extrinsics.entity.ts
Original file line number Diff line number Diff line change
@@ -1,65 +1,86 @@
import { ApiProperty } from '@nestjs/swagger';
import { Column, Entity } from 'typeorm';
import { BaseEntity } from './base.entity';

@Entity('extrinsics', { schema: 'consensus' })
export class Extrinsics extends BaseEntity {
@ApiProperty()
@Column('text')
id: string;

@ApiProperty()
@Column('text')
sort_id: string;

@ApiProperty()
@Column('text')
hash: string;

@ApiProperty()
@Column('numeric')
block_height: number;

@ApiProperty()
@Column('text')
block_hash: string;

@ApiProperty()
@Column('text')
section: string;

@ApiProperty()
@Column('text')
module: string;

@ApiProperty()
@Column('text')
name: string;

@ApiProperty()
@Column('integer')
index_in_block: number;

@ApiProperty()
@Column('boolean')
success: boolean;

@ApiProperty()
@Column('timestamp without time zone')
timestamp: Date;

@ApiProperty()
@Column('numeric')
nonce: number;

@ApiProperty()
@Column('text')
signer: string;

@ApiProperty()
@Column('text')
signature: string;

@ApiProperty()
@Column('text')
args: string;

@ApiProperty()
@Column('text')
error: string;

@ApiProperty()
@Column('numeric')
tip: number;

@ApiProperty()
@Column('numeric')
fee: number;

@ApiProperty()
@Column('integer')
pos: number;

@ApiProperty()
@Column('text', { nullable: true })
cid: string;
}

0 comments on commit 4d0e981

Please sign in to comment.