Skip to content

Commit 0472320

Browse files
committed
feat: add GET /file/all endpoint in api-gateway
1 parent 429e4fe commit 0472320

3 files changed

Lines changed: 41 additions & 1 deletion

File tree

‎packages/api-gateway/src/models/file_bucket.dto.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,11 @@ export class FileBucket implements FileBucketProto.Bucket {
109109
this.FileServiceFile = fileBucket.FileServiceFile ?? [];
110110
}
111111
}
112+
113+
export class BucketWithFiles {
114+
[bucketName: string]: string[];
115+
116+
constructor(entry: FileBucketProto.Files) {
117+
this[entry.bucketName] = entry.files;
118+
}
119+
}

‎packages/api-gateway/src/modules/file_bucket/file_bucket.controller.ts‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { AuthCommonProto, FileBucketProto } from 'juno-proto';
2323
import { lastValueFrom } from 'rxjs';
2424
import { ApiKey } from 'src/decorators/api_key.decorator';
2525
import {
26+
BucketWithFiles,
2627
DeleteFileBucketModel,
2728
FileBucket,
2829
RegisterFileBucketModel,
@@ -132,4 +133,33 @@ export class FileBucketController implements OnModuleInit {
132133

133134
return bucketsData.buckets?.map((bucket) => new FileBucket(bucket)) ?? [];
134135
}
136+
137+
@Get('all/:configId')
138+
@ApiOperation({ summary: 'Get all files from all buckets for a config.' })
139+
@ApiBadRequestResponse({ description: 'Parameters are invalid' })
140+
@ApiUnauthorizedResponse({ description: 'Unauthorized' })
141+
@ApiOkResponse({
142+
description: 'Returned all files grouped by bucket name',
143+
type: [BucketWithFiles],
144+
})
145+
async getAllFiles(
146+
@ApiKey() apiKey: AuthCommonProto.ApiKey,
147+
@Param('configId') configId: string,
148+
): Promise<BucketWithFiles[]> {
149+
const id = parseInt(configId);
150+
if (Number.isNaN(id) || id < 0) {
151+
throw new BadRequestException(
152+
'Id must be an int greater than or equal to 0',
153+
);
154+
}
155+
156+
const grpcResponse = this.fileBucketService.getAllFiles({
157+
configId: id,
158+
configEnv: apiKey.environment,
159+
});
160+
161+
const data = await lastValueFrom(grpcResponse);
162+
163+
return (data.files ?? []).map((entry) => new BucketWithFiles(entry));
164+
}
135165
}

‎packages/api-gateway/src/modules/file_bucket/file_bucket.module.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ import {
7272
})
7373
export class FileBucketModule implements NestModule {
7474
configure(consumer: MiddlewareConsumer) {
75-
consumer.apply(ApiKeyMiddleware).forRoutes('/file/bucket', 'file/bucket/*');
75+
consumer
76+
.apply(ApiKeyMiddleware)
77+
.forRoutes('/file/bucket', 'file/bucket/*', '/file/all/*');
7678
}
7779
}

0 commit comments

Comments
 (0)