@@ -8,23 +8,67 @@ import {
88 HttpCode ,
99 HttpStatus ,
1010} from '@nestjs/common' ;
11+ import {
12+ ApiTags ,
13+ ApiOperation ,
14+ ApiResponse ,
15+ ApiBody ,
16+ ApiParam ,
17+ } from '@nestjs/swagger' ;
1118import { LimitsService } from './limits.service' ;
12- import { IsNumber , IsPositive } from 'class-validator' ;
13-
14- class SetLimitsDto {
15- @IsNumber ( )
16- @IsPositive ( )
17- dailyLimit : number ;
18-
19- @IsNumber ( )
20- @IsPositive ( )
21- perTransactionLimit : number ;
22- }
19+ import { SetLimitsDto } from './dto/set-limits.dto' ;
2320
21+ @ApiTags ( 'limits' )
2422@Controller ( 'wallets/:walletId/limits' )
2523export class LimitsController {
2624 constructor ( private readonly limitsService : LimitsService ) { }
2725
26+ @ApiOperation ( { summary : 'Set wallet transaction and daily limits' } )
27+ @ApiParam ( { name : 'walletId' , description : 'Wallet ID' } )
28+ @ApiBody ( {
29+ type : SetLimitsDto ,
30+ examples : {
31+ default : {
32+ value : {
33+ dailyLimit : 5000 ,
34+ perTransactionLimit : 1000 ,
35+ } ,
36+ } ,
37+ } ,
38+ } )
39+ @ApiResponse ( {
40+ status : 201 ,
41+ description : 'Limits set successfully' ,
42+ example : {
43+ walletId : '123e4567-e89b-12d3-a456-426614174000' ,
44+ dailyLimit : 5000 ,
45+ perTransactionLimit : 1000 ,
46+ } ,
47+ } )
48+ @ApiResponse ( {
49+ status : 400 ,
50+ description : 'Bad request - invalid input' ,
51+ example : {
52+ statusCode : 400 ,
53+ timestamp : '2024-06-24T12:34:56.789Z' ,
54+ path : '/wallets/123/limits' ,
55+ method : 'POST' ,
56+ message : [ 'dailyLimit must be positive' ] ,
57+ error : 'Bad Request' ,
58+ } ,
59+ } )
60+ @ApiResponse ( {
61+ status : 404 ,
62+ description : 'Wallet not found' ,
63+ example : {
64+ statusCode : 404 ,
65+ timestamp : '2024-06-24T12:34:56.789Z' ,
66+ path : '/wallets/invalid/limits' ,
67+ method : 'POST' ,
68+ message : 'Wallet not found' ,
69+ error : 'Not Found' ,
70+ } ,
71+ } )
2872 @Post ( )
2973 setLimits ( @Param ( 'walletId' ) walletId : string , @Body ( ) dto : SetLimitsDto ) {
3074 return this . limitsService . setLimits (
@@ -34,11 +78,52 @@ export class LimitsController {
3478 ) ;
3579 }
3680
81+ @ApiOperation ( { summary : 'Get wallet limits' } )
82+ @ApiParam ( { name : 'walletId' , description : 'Wallet ID' } )
83+ @ApiResponse ( {
84+ status : 200 ,
85+ description : 'Wallet limits retrieved successfully' ,
86+ example : {
87+ walletId : '123e4567-e89b-12d3-a456-426614174000' ,
88+ dailyLimit : 5000 ,
89+ perTransactionLimit : 1000 ,
90+ } ,
91+ } )
92+ @ApiResponse ( {
93+ status : 404 ,
94+ description : 'No limits found for wallet' ,
95+ example : {
96+ statusCode : 404 ,
97+ timestamp : '2024-06-24T12:34:56.789Z' ,
98+ path : '/wallets/123/limits' ,
99+ method : 'GET' ,
100+ message : 'No limits found for wallet' ,
101+ error : 'Not Found' ,
102+ } ,
103+ } )
37104 @Get ( )
38105 getLimits ( @Param ( 'walletId' ) walletId : string ) {
39106 return this . limitsService . getLimits ( walletId ) ;
40107 }
41108
109+ @ApiOperation ( { summary : 'Remove wallet limits' } )
110+ @ApiParam ( { name : 'walletId' , description : 'Wallet ID' } )
111+ @ApiResponse ( {
112+ status : 204 ,
113+ description : 'Limits removed successfully' ,
114+ } )
115+ @ApiResponse ( {
116+ status : 404 ,
117+ description : 'No limits found for wallet' ,
118+ example : {
119+ statusCode : 404 ,
120+ timestamp : '2024-06-24T12:34:56.789Z' ,
121+ path : '/wallets/123/limits' ,
122+ method : 'DELETE' ,
123+ message : 'No limits found for wallet 123' ,
124+ error : 'Not Found' ,
125+ } ,
126+ } )
42127 @Delete ( )
43128 @HttpCode ( HttpStatus . NO_CONTENT )
44129 removeLimits ( @Param ( 'walletId' ) walletId : string ) {
0 commit comments