Skip to content

Commit

Permalink
feature/gap-search-api: Added controller function for gap search API
Browse files Browse the repository at this point in the history
  • Loading branch information
milos1991 committed Jun 24, 2024
1 parent e7ef953 commit aacefd3
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 1 deletion.
27 changes: 26 additions & 1 deletion backend/src/governance/api/governance.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import { UserPathGuard } from 'src/auth/guard/users-path.guard';
import { ApiPaginationQuery, Paginate, PaginateQuery } from 'nestjs-paginate';
import { VOTE_PAGINATION_CONFIG } from '../util/pagination/votes-pagination.config';
import { GovernanceActionMetadataResponse } from './response/gov-action-metadata.response';
import { GAP_PAGINATION_CONFIG } from '../util/pagination/gap-pagination.config';
import { GovernanceActionProposalResponse } from './response/gov-action-proposal.response';
@ApiTags('Governance')
@Controller('governance')
export class GovernanceController {
Expand All @@ -36,13 +38,36 @@ export class GovernanceController {
status: 404,
description: 'Governance action proposal with {id} not found',
})
@Get(':id')
@Get('proposals/:id')
async findOne(
@Param('id', ParseIntPipe) id: number,
): Promise<GovernanceActionMetadataResponse> {
return await this.governanceFacade.findGovActionProposalById(id);
}

@ApiOperation({ summary: 'Search GAP' })
@ApiBearerAuth('JWT-auth')
@ApiPaginationQuery(GAP_PAGINATION_CONFIG)
@ApiResponse({
status: 200,
description:
'Governance Action Proposals - returns GovernanceActionProposalResponse array within data',
isArray: true,
type: PaginatedResponse<GovernanceActionProposalResponse>,
})
@ApiResponse({
status: 404,
description: 'Governance action proposal with {id} not found',
})
@Get('proposals/users/:id/search')
@UseGuards(JwtAuthGuard, UserPathGuard)
async searchGovActionProposalsPaginated(
@Param('id', ParseUUIDPipe) id: string,
@Paginate() query: PaginateQuery,
): Promise<PaginatedResponse<GovernanceActionProposalResponse>> {
return await this.governanceFacade.searchGovActionProposals(query, id);
}

@ApiOperation({
summary: 'List of votes related to all governance action proposals',
})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { ApiProperty } from '@nestjs/swagger';
import { Expose } from 'class-transformer';
import { VoteStatus } from 'src/governance/enums/vote-status.enum';

export class GovernanceActionProposalResponse {
@ApiProperty({
description: 'Unique governance proposal ID',
example: '1',
})
@Expose({ name: 'id' })
id: number;

@ApiProperty({
description: 'Governance action proposal TX hash,',
example:
'28a5c50e900fbc155a98d78d2081e49ca4d6f004f2604e758a64357119db1b05#0',
})
@Expose({ name: 'tx_hash' })
txHash: string;

@ApiProperty({
description: 'Title of a governance action proposal',
example: 'Random title',
})
@Expose({ name: 'title' })
title: string;

@ApiProperty({
description: 'Category of a governance action proposal',
example: 'InfoAction',
})
@Expose({ name: 'category' })
category: string;

@ApiProperty({
description: 'Abstract of a governance action proposal',
example:
'This is a random abstract of a governance action proposal abstract. No longer than 2500 chars',
})
@Expose({ name: 'abstract' })
abstract: string;

@ApiProperty({
description: 'Metadata URL of a governance action proposal',
example: 'https://some.random.url',
})
@Expose({ name: 'metadata_url' })
metadataUrl: string;

@ApiProperty({
description: 'Vote Status for a Given Governance Action Proposal for a particular user.',
example: 'Pending',
})
@Expose({ name: 'vote_status' })
voteStatus: VoteStatus;
}
14 changes: 14 additions & 0 deletions backend/src/governance/enums/vote-status.enum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export enum VoteStatus {
/**
* Unvoted - There are neither votes nor reasoning for the associated GAP
*/
Unvoted = 'Unvoted',
/**
* Pending - There is no vote but there is a reasoning for the associated GAP
*/
Pending = 'Pending',
/**
* Voted - There are both votes and a reasoning for the associated GAP
*/
Voted = 'Voted',
}
9 changes: 9 additions & 0 deletions backend/src/governance/facade/governance.facade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { PaginateQuery } from 'nestjs-paginate';
import { PaginationDtoMapper } from 'src/util/pagination/mapper/pagination.mapper';
import { UserPhotoDto } from '../dto/user-photo.dto';
import { GovernanceActionMetadataResponse } from '../api/response/gov-action-metadata.response';
import { GovernanceActionProposalResponse } from '../api/response/gov-action-proposal.response';

@Injectable()
export class GovernanceFacade {
Expand All @@ -26,6 +27,14 @@ export class GovernanceFacade {
return GovernanceMapper.govActionMetaDtoToResponse(dto);
}

async searchGovActionProposals(
query: PaginateQuery,
userId: string,
): Promise<PaginatedResponse<GovernanceActionProposalResponse>> {
//TODO Impl
return null;
}

async searchGovVotes(
query: PaginateQuery,
userId?: string,
Expand Down
14 changes: 14 additions & 0 deletions backend/src/governance/util/pagination/gap-pagination.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { FilterOperator, PaginateConfig } from 'nestjs-paginate';
import { Vote } from 'src/governance/entities/vote.entity';

export const GAP_PAGINATION_CONFIG: PaginateConfig<Vote> = {
relations: ['govActionProposal'],
sortableColumns: ['submitTime', 'govActionProposal.title'],
filterableColumns: {
govActionType: [FilterOperator.EQ, FilterOperator.IN],
vote: [FilterOperator.EQ, FilterOperator.IN],
userId: [FilterOperator.EQ],
},
searchableColumns: ['govActionProposal.title'],
defaultSortBy: [['submitTime', 'DESC']],
};

0 comments on commit aacefd3

Please sign in to comment.