Skip to content

Commit

Permalink
Merge pull request #9 from IntersectMBO/feat/implement-routes
Browse files Browse the repository at this point in the history
feat: implement proposal routes
  • Loading branch information
MSzalowski authored Oct 2, 2024
2 parents 9207e9f + 81e17b3 commit 50a2bd0
Show file tree
Hide file tree
Showing 16 changed files with 1,444 additions and 1,029 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ changes.
- add initial project configuration
- add eslint configuration
- integrate mui and design system
- add proposal API routes

### Fixed

Expand Down
2 changes: 1 addition & 1 deletion backend/dist/tsconfig.tsbuildinfo

Large diffs are not rendered by default.

74 changes: 69 additions & 5 deletions backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"@nestjs/common": "^10.0.0",
"@nestjs/core": "^10.0.0",
"@nestjs/platform-express": "^10.0.0",
"@nestjs/swagger": "^7.4.2",
"reflect-metadata": "^0.2.0",
"rxjs": "^7.8.1"
},
Expand Down
22 changes: 0 additions & 22 deletions backend/src/app.controller.spec.ts

This file was deleted.

12 changes: 0 additions & 12 deletions backend/src/app.controller.ts

This file was deleted.

9 changes: 4 additions & 5 deletions backend/src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { ProposalModule } from './proposal/proposal.module';

@Module({
imports: [],
controllers: [AppController],
providers: [AppService],
imports: [ProposalModule],
controllers: [],
providers: [],
})
export class AppModule {}
8 changes: 0 additions & 8 deletions backend/src/app.service.ts

This file was deleted.

12 changes: 12 additions & 0 deletions backend/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
import { NestFactory } from '@nestjs/core';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
import { AppModule } from './app.module';

async function bootstrap() {
const app = await NestFactory.create(AppModule);

const config = new DocumentBuilder()
.setTitle('GovTool Voting Pillar API')
.setDescription('API for the GovTool Voting Pillar')
.setVersion('1.0')
.addTag('proposal')
.build();

const document = SwaggerModule.createDocument(app, config);
SwaggerModule.setup('api', app, document);

await app.listen(3000);
}
bootstrap();
43 changes: 43 additions & 0 deletions backend/src/proposal/proposal.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Test, TestingModule } from '@nestjs/testing';

import { ProposalController } from './proposal.controller';
import { ProposalService } from './proposal.service';
import { ProposalSort, ProposalType } from '../types/proposal';

describe('ProposalController', () => {
let controller: ProposalController;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [ProposalController],
providers: [ProposalService],
}).compile();

controller = module.get<ProposalController>(ProposalController);
});

it('should be defined', () => {
expect(controller).toBeDefined();
});

it('should return a list of proposals', async () => {
const proposals = await controller.getProposalList({
type: ProposalType.InfoAction,
sort: ProposalSort.NewestCreated,
page: 0,
pageSize: 10,
drepId: '123',
search: 'cardano',
});
expect(proposals.page).toBe(0);
expect(proposals.pageSize).toBe(10);
expect(proposals.total).toBeGreaterThan(0);
expect(proposals.elements.length).toBeGreaterThan(0);
});

it('should return a proposal by ID', async () => {
const proposal = await controller.getProposal('12abcd', '123');
expect(proposal).toBeDefined();
expect(proposal.txHash).toBe('12abcd');
});
});
81 changes: 81 additions & 0 deletions backend/src/proposal/proposal.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { Controller, Get, Param } from '@nestjs/common';

import { ApiOperation, ApiResponse, ApiTags, ApiParam } from '@nestjs/swagger';

import { ProposalService, proposalList } from './proposal.service';
import { GetProposalListParams } from '../types/proposal';

@ApiTags('proposal')
@Controller('proposal')
export class ProposalController {
constructor(private proposalService: ProposalService) {}

@Get('list')
@ApiOperation({ summary: 'Get a list of proposals' })
@ApiParam({
name: 'type',
enum: [
'ParameterChange',
'HardForkInitiation',
'TreasuryWithdrawals',
'NoConfidence',
'NewCommittee',
'NewConstitution',
'InfoAction',
],
required: false,
})
@ApiParam({
name: 'sort',
enum: ['SoonestToExpire', 'NewestCreated', 'MostYesVotes'],
required: false,
})
@ApiParam({ name: 'page', type: 'number', required: false })
@ApiParam({ name: 'pageSize', type: 'number', required: false })
@ApiParam({
name: 'drepId',
type: 'string',
format: 'hex',
required: false,
})
@ApiParam({ name: 'search', required: false })
@ApiResponse({
status: 200,
description: 'List of proposals',
example: {
page: 0,
pageSize: 10,
total: proposalList.length,
elements: proposalList,
},
})
async getProposalList(@Param() params: GetProposalListParams) {
return this.proposalService.getProposalList(params);
}

@Get('get/:proposalId')
@ApiOperation({ summary: 'Get a proposal by ID' })
@ApiParam({
name: 'proposalId',
type: 'string',
format: 'hash#index',
required: true,
})
@ApiParam({
name: 'drepId',
type: 'string',
format: 'hex',
required: false,
})
@ApiResponse({
status: 200,
description: 'Proposal',
example: proposalList[0],
})
async getProposal(
@Param('proposalId') proposalId: string,
@Param('drepId') drepId?: string,
) {
return this.proposalService.getProposal(proposalId, drepId);
}
}
10 changes: 10 additions & 0 deletions backend/src/proposal/proposal.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Module } from '@nestjs/common';

import { ProposalController } from './proposal.controller';
import { ProposalService } from './proposal.service';

@Module({
controllers: [ProposalController],
providers: [ProposalService],
})
export class ProposalModule {}
Loading

0 comments on commit 50a2bd0

Please sign in to comment.