@@ -5,11 +5,13 @@ import {
55 Inject ,
66 OnModuleInit ,
77 Param ,
8+ Post ,
89} from '@nestjs/common' ;
910import { ClientGrpc } from '@nestjs/microservices' ;
1011import {
1112 ApiBadRequestResponse ,
1213 ApiBearerAuth ,
14+ ApiCreatedResponse ,
1315 ApiNotFoundResponse ,
1416 ApiOkResponse ,
1517 ApiOperation ,
@@ -19,26 +21,39 @@ import {
1921import { AuthCommonProto , FileConfigProto } from 'juno-proto' ;
2022import { lastValueFrom } from 'rxjs' ;
2123import { ApiKey } from 'src/decorators/api_key.decorator' ;
22- import { FileConfigResponse } from 'src/models/file_config.dto' ;
24+ import {
25+ FileConfigResponse ,
26+ SetupFileServiceResponse ,
27+ } from 'src/models/file_config.dto' ;
2328
24- const { FILE_SERVICE_CONFIG_DB_SERVICE_NAME } = FileConfigProto ;
29+ const {
30+ FILE_SERVICE_CONFIG_DB_SERVICE_NAME ,
31+ FILE_SERVICE_CONFIG_SERVICE_NAME ,
32+ } = FileConfigProto ;
2533
2634@ApiBearerAuth ( 'api_key' )
2735@ApiTags ( 'file_config' )
2836@Controller ( 'file' )
2937export class FileConfigController implements OnModuleInit {
38+ private fileConfigService : FileConfigProto . FileServiceConfigServiceClient ;
3039 private fileConfigDBService : FileConfigProto . FileServiceConfigDbServiceClient ;
3140
3241 constructor (
3342 @Inject ( FILE_SERVICE_CONFIG_DB_SERVICE_NAME )
43+ private fileConfigDbClient : ClientGrpc ,
44+ @Inject ( FILE_SERVICE_CONFIG_SERVICE_NAME )
3445 private fileConfigClient : ClientGrpc ,
3546 ) { }
3647
3748 onModuleInit ( ) {
3849 this . fileConfigDBService =
39- this . fileConfigClient . getService < FileConfigProto . FileServiceConfigDbServiceClient > (
50+ this . fileConfigDbClient . getService < FileConfigProto . FileServiceConfigDbServiceClient > (
4051 FILE_SERVICE_CONFIG_DB_SERVICE_NAME ,
4152 ) ;
53+ this . fileConfigService =
54+ this . fileConfigClient . getService < FileConfigProto . FileServiceConfigServiceClient > (
55+ FILE_SERVICE_CONFIG_SERVICE_NAME ,
56+ ) ;
4257 }
4358
4459 @Get ( 'config/:projectId' )
@@ -75,4 +90,27 @@ export class FileConfigController implements OnModuleInit {
7590
7691 return new FileConfigResponse ( await lastValueFrom ( config ) ) ;
7792 }
93+
94+ @ApiOperation ( {
95+ summary : 'Sets up file services for the Project/Environment' ,
96+ } )
97+ @ApiCreatedResponse ( {
98+ description : 'File Services setup successfully' ,
99+ type : SetupFileServiceResponse ,
100+ } )
101+ @ApiUnauthorizedResponse ( { description : 'Unauthorized' } )
102+ @ApiBadRequestResponse ( { description : 'Bad Request' } )
103+ @Post ( 'config/setup' )
104+ async setup (
105+ @ApiKey ( ) apiKey : AuthCommonProto . ApiKey ,
106+ ) : Promise < SetupFileServiceResponse > {
107+ const setupResponse = await lastValueFrom (
108+ this . fileConfigService . setup ( {
109+ projectId : apiKey . project . id ,
110+ environment : apiKey . environment ,
111+ } ) ,
112+ ) ;
113+
114+ return new SetupFileServiceResponse ( setupResponse ) ;
115+ }
78116}
0 commit comments