Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/api-gateway/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { FileBucketModule } from './modules/file_bucket/file_bucket.module';
import { FileConfigModule } from './modules/file_config/file_config.module';
import { AnalyticsModule } from './modules/analytics/analytics.module';
import { AnalyticsConfigModule } from './modules/analytics_config/analytics_config.module';
import { FileDeleteModule } from './modules/file_delete/file_delete.module';

@Module({
imports: [
Expand All @@ -24,6 +25,7 @@ import { AnalyticsConfigModule } from './modules/analytics_config/analytics_conf
FileUploadModule,
FileBucketModule,
FileConfigModule,
FileDeleteModule,
AnalyticsModule,
AnalyticsConfigModule,
],
Expand Down
51 changes: 51 additions & 0 deletions packages/api-gateway/src/models/file_delete.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsArray, IsInt, IsNotEmpty, IsString, Min } from 'class-validator';
import { FileProto } from 'juno-proto';

export class DeleteFilesModel {
@ApiProperty({
type: 'string',
description: 'Name of the bucket containing the files',
})
@IsNotEmpty()
@IsString()
bucketName: string;

@ApiProperty({
type: 'number',
description: 'Configuration ID for the bucket',
})
@IsInt()
@Min(0)
@IsNotEmpty()
configId: number;

@ApiProperty({
type: [String],
description: 'List of file names to delete',
})
@IsArray()
@IsNotEmpty()
@IsString({ each: true })
@IsNotEmpty({ each: true })
fileNames: string[];
Comment thread
aakashg00 marked this conversation as resolved.
}

export class DeleteFilesResponse {
@ApiProperty({
type: 'string',
description: 'The name of the bucket from which files were deleted',
})
bucketName: string;

@ApiProperty({
type: [String],
description: 'List of file names that were deleted',
})
fileNames: string[];

constructor(res: FileProto.DeleteFilesResponse) {
this.bucketName = res.bucketName;
this.fileNames = res.fileNames;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import {
Body,
Controller,
Delete,
HttpStatus,
Inject,
OnModuleInit,
} from '@nestjs/common';
import { ClientGrpc } from '@nestjs/microservices';
import { lastValueFrom } from 'rxjs';
import { AuthCommonProto, FileProto } from 'juno-proto';
import {
ApiBearerAuth,
ApiOperation,
ApiResponse,
ApiTags,
} from '@nestjs/swagger';
import {
DeleteFilesModel,
DeleteFilesResponse,
} from 'src/models/file_delete.dto';
import { ApiKey } from 'src/decorators/api_key.decorator';

const { FILE_SERVICE_NAME } = FileProto;

@ApiBearerAuth('API_Key')
@ApiTags('file_delete')
@Controller('file')
export class FileDeleteController implements OnModuleInit {
private fileService: FileProto.FileServiceClient;

constructor(
@Inject(FILE_SERVICE_NAME)
private fileClient: ClientGrpc,
) {}

onModuleInit() {
this.fileService =
this.fileClient.getService<FileProto.FileServiceClient>(
FILE_SERVICE_NAME,
);
}

@Delete('delete')
@ApiOperation({ summary: 'Delete files from a bucket' })
@ApiResponse({
status: HttpStatus.BAD_REQUEST,
description: 'Parameters are invalid',
})
@ApiResponse({
status: HttpStatus.NOT_FOUND,
description: 'Bucket or file not found',
})
@ApiResponse({
status: HttpStatus.OK,
description: 'Returns the bucket name and list of deleted file names',
type: DeleteFilesResponse,
})
async deleteFiles(
@ApiKey() apiKey: AuthCommonProto.ApiKey,
@Body() params: DeleteFilesModel,
): Promise<DeleteFilesResponse> {
const res = await lastValueFrom(
this.fileService.deleteFiles({
bucketName: params.bucketName,
configId: params.configId,
configEnv: apiKey.environment,
fileNames: params.fileNames,
}),
);

return new DeleteFilesResponse(res);
}
}
72 changes: 72 additions & 0 deletions packages/api-gateway/src/modules/file_delete/file_delete.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import {
Module,
NestModule,
RequestMethod,
MiddlewareConsumer,
} from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { join } from 'path';
import { FileDeleteController } from './file_delete.controller';
import { ApiKeyMiddleware } from 'src/middleware/api_key.middleware';

import { ClientsModule, Transport } from '@nestjs/microservices';
import {
ApiKeyProtoFile,
FileProto,
FileProtoFile,
JwtProtoFile,
} from 'juno-proto';
import { FILE_SERVICE_NAME } from 'juno-proto/dist/gen/file';
import {
API_KEY_SERVICE_NAME,
JUNO_API_KEY_PACKAGE_NAME,
} from 'juno-proto/dist/gen/api_key';
import {
JWT_SERVICE_NAME,
JUNO_JWT_PACKAGE_NAME,
} from 'juno-proto/dist/gen/jwt';

@Module({
imports: [
ConfigModule.forRoot({
envFilePath: join(__dirname, '../../../../../.env.local'),
}),
ClientsModule.register([
{
name: API_KEY_SERVICE_NAME,
transport: Transport.GRPC,
options: {
url: process.env.AUTH_SERVICE_ADDR,
package: JUNO_API_KEY_PACKAGE_NAME,
protoPath: ApiKeyProtoFile,
},
},
{
name: JWT_SERVICE_NAME,
transport: Transport.GRPC,
options: {
url: process.env.AUTH_SERVICE_ADDR,
package: JUNO_JWT_PACKAGE_NAME,
protoPath: JwtProtoFile,
},
},
{
name: FILE_SERVICE_NAME,
transport: Transport.GRPC,
options: {
url: process.env.FILE_SERVICE_ADDR,
package: FileProto.JUNO_FILE_SERVICE_FILE_PACKAGE_NAME,
protoPath: FileProtoFile,
},
},
]),
],
controllers: [FileDeleteController],
})
export class FileDeleteModule implements NestModule {
configure(consumer: MiddlewareConsumer) {
consumer
.apply(ApiKeyMiddleware)
.forRoutes({ path: '/file/delete', method: RequestMethod.DELETE });
}
}
Loading
Loading