Repository navigation
Akash/delete file #252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Akash/delete file #252
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7ed1c36
Implemented file delete feature
asarode06 d9f03cb
implemented e2e tests
asarode06 767fb5a
Prettier fix
asarode06 60e05ea
made greptile fixes
asarode06 d520126
prettier fix
asarode06 d6d2742
Fixed e2e test errors
asarode06 72acc44
prettier fix
asarode06 333f243
Hopefully fixed api gateway issue
asarode06 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| 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() | ||
| fileNames: string[]; | ||
| } | ||
|
|
||
| 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; | ||
| } | ||
| } | ||
74 changes: 74 additions & 0 deletions
74
packages/api-gateway/src/modules/file_delete/file_delete.controller.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
72
packages/api-gateway/src/modules/file_delete/file_delete.module.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 }); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.