Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tmthecoder committed Nov 4, 2024
1 parent f4ad897 commit 16409e3
Show file tree
Hide file tree
Showing 7 changed files with 1,535 additions and 4,126 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ import { FileServiceConfigService } from './file_config.service';
import { RpcException } from '@nestjs/microservices';
import { status } from '@grpc/grpc-js';
import { FileConfigProto } from 'juno-proto';
import { FileServiceConfigDbServiceController } from 'juno-proto/dist/gen/file_config';
import { Prisma } from '@prisma/client';

@Controller()
@FileConfigProto.FileServiceConfigDbServiceControllerMethods()
export class FileConfigController
implements FileServiceConfigDbServiceController
implements FileConfigProto.FileServiceConfigDbServiceController
{
constructor(
private readonly fileServiceConfigService: FileServiceConfigService,
Expand All @@ -18,7 +17,7 @@ export class FileConfigController
async createConfig(
request: FileConfigProto.CreateFileServiceConfigRequest,
): Promise<FileConfigProto.FileServiceConfig> {
const configId = request.id.toString();
const configId = request.projectId.toString();

const existingConfig =
await this.fileServiceConfigService.getConfig(configId);
Expand All @@ -31,7 +30,11 @@ export class FileConfigController

const config = await this.fileServiceConfigService.createConfig(request);

return config;
return {
id: config.id,
files: [],
buckets: [],
};
}

async getConfig(
Expand All @@ -47,7 +50,11 @@ export class FileConfigController
});
}

return config;
return {
id: config.id,
files: [],
buckets: [],
};
}

async updateConfig(
Expand All @@ -59,7 +66,11 @@ export class FileConfigController
request,
);

return config;
return {
id: config.id,
files: [],
buckets: [],
};
} catch (e) {
if (
e instanceof Prisma.PrismaClientKnownRequestError &&
Expand All @@ -84,7 +95,11 @@ export class FileConfigController
const config = await this.fileServiceConfigService.deleteConfig(
request.id.toString(),
);
return config;
return {
id: config.id,
files: [],
buckets: [],
};
} catch (e) {
if (
e instanceof Prisma.PrismaClientKnownRequestError &&
Expand Down
74 changes: 36 additions & 38 deletions packages/db-service/src/modules/file_config/file_config.service.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,27 @@
import { Injectable } from '@nestjs/common';
import { FileServiceConfig } from '@prisma/client';
import { PrismaService } from 'src/prisma.service';
import { ConfigProto } from 'juno-proto';
import { FileConfigProto } from 'juno-proto';

@Injectable()
export class FileServiceConfigService {
constructor(private prisma: PrismaService) {}

async createConfig(
configData: ConfigProto.CreateFileServiceConfigRequest,
configData: FileConfigProto.CreateFileServiceConfigRequest,
): Promise<FileServiceConfig> {
return this.prisma.fileServiceConfig.create({
data: {
id: configData.id,
buckets: {
create: configData.buckets.map((bucket) => ({
bucketName: bucket.bucketName,
})),
},
project: {
Project: {
connect: {
id: configData.id,
id: configData.projectId,
},
},
files: {
create:
configData.files?.map((file) => ({
fileId: {
path: file.fileId.path,
bucketName: file.fileId.bucketName,
configId: file.fileId.configId,
},
metadata: file.metadata,
})) || [],
},
},
include: {
Project: true,
buckets: true,
FileServiceFile: true,
},
});
}
Expand All @@ -44,16 +32,16 @@ export class FileServiceConfigService {
id: Number(configId),
},
include: {
Project: true,
buckets: true,
project: true,
files: true,
FileServiceFile: true,
},
});
}

async updateConfig(
configId: string,
configData: ConfigProto.UpdateFileServiceConfigRequest,
configData: FileConfigProto.UpdateFileServiceConfigRequest,
): Promise<FileServiceConfig> {
return this.prisma.fileServiceConfig.update({
where: {
Expand All @@ -62,28 +50,33 @@ export class FileServiceConfigService {
data: {
buckets: {
deleteMany: {},
create: configData.buckets.map((bucket) => ({
bucketName: bucket.bucketName,
})),
// create: configData.buckets.map((bucket) => ({
// bucketName: bucket.bucketName,
// })),
},
project: {
Project: {
connect: {
id: configData.id,
},
},
files: {
FileServiceFile: {
deleteMany: {},
create:
configData.files?.map((file) => ({
fileId: {
path: file.fileId.path,
bucketName: file.fileId.bucketName,
configId: file.fileId.configId,
},
metadata: file.metadata,
})) || [],
// create:
// configData.files?.map((file) => ({
// fileId: {
// path: file.fileId.path,
// bucketName: file.fileId.bucketName,
// configId: file.fileId.configId,
// },
// metadata: file.metadata,
// })) || [],
},
},
include: {
Project: true,
buckets: true,
FileServiceFile: true,
},
});
}

Expand All @@ -92,6 +85,11 @@ export class FileServiceConfigService {
where: {
id: Number(configId),
},
include: {
Project: true,
buckets: true,
FileServiceFile: true,
},
});
}
}
10 changes: 3 additions & 7 deletions packages/proto/definitions/file_config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,15 @@ service FileServiceConfigDbService {
message FileServiceConfig {
int64 id = 1;
repeated config.Bucket buckets = 2;
project.Project project = 3;
repeated file.File files = 4;
}

message GetFileServiceConfigRequest {
int64 id = 1;
}
message GetFileServiceConfigRequest { int64 id = 1; }

message CreateFileServiceConfigRequest {
int64 project_id = 1;
repeated config.Bucket buckets = 2;
repeated file.File files = 3;
}

message UpdateFileServiceConfigRequest {
Expand All @@ -36,6 +34,4 @@ message UpdateFileServiceConfigRequest {
repeated file.File files = 3;
}

message DeleteFileServiceConfigRequest {
int64 id = 1;
}
message DeleteFileServiceConfigRequest { int64 id = 1; }
41 changes: 29 additions & 12 deletions packages/proto/src/gen/file_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,40 @@
/* eslint-disable */
import { GrpcMethod, GrpcStreamMethod } from '@nestjs/microservices';
import { Observable } from 'rxjs';
import { File } from './file';
import { Bucket } from './file_bucket';

export const protobufPackage = 'juno.file_service.config';

export interface FileServiceConfig {}
export interface FileServiceConfig {
id: number;
buckets: Bucket[];
files: File[];
}

export interface GetFileServiceConfigRequest {}
export interface GetFileServiceConfigRequest {
id: number;
}

export interface CreateFileServiceConfigRequest {}
export interface CreateFileServiceConfigRequest {
projectId: number;
buckets: Bucket[];
files: File[];
}

export interface UpdateFileServiceConfigRequest {}
export interface UpdateFileServiceConfigRequest {
id: number;
buckets: Bucket[];
files: File[];
}

export interface DeleteFileServiceConfigRequest {}
export interface DeleteFileServiceConfigRequest {
id: number;
}

export const JUNO_FILE_SERVICE_CONFIG_PACKAGE_NAME = 'juno.file_service.config';

export interface FileServiceFileServiceConfigDbServiceClient {
export interface FileServiceConfigDbServiceClient {
getConfig(
request: GetFileServiceConfigRequest,
): Observable<FileServiceConfig>;
Expand All @@ -40,7 +58,7 @@ export interface FileServiceFileServiceConfigDbServiceClient {
): Observable<FileServiceConfig>;
}

export interface FileServiceFileServiceConfigDbServiceController {
export interface FileServiceConfigDbServiceController {
getConfig(
request: GetFileServiceConfigRequest,
):
Expand Down Expand Up @@ -70,7 +88,7 @@ export interface FileServiceFileServiceConfigDbServiceController {
| FileServiceConfig;
}

export function FileServiceFileServiceConfigDbServiceControllerMethods() {
export function FileServiceConfigDbServiceControllerMethods() {
return function (constructor: Function) {
const grpcMethods: string[] = [
'getConfig',
Expand All @@ -83,7 +101,7 @@ export function FileServiceFileServiceConfigDbServiceControllerMethods() {
constructor.prototype,
method,
);
GrpcMethod('FileServiceFileServiceConfigDbService', method)(
GrpcMethod('FileServiceConfigDbService', method)(
constructor.prototype[method],
method,
descriptor,
Expand All @@ -95,7 +113,7 @@ export function FileServiceFileServiceConfigDbServiceControllerMethods() {
constructor.prototype,
method,
);
GrpcStreamMethod('FileServiceFileServiceConfigDbService', method)(
GrpcStreamMethod('FileServiceConfigDbService', method)(
constructor.prototype[method],
method,
descriptor,
Expand All @@ -104,5 +122,4 @@ export function FileServiceFileServiceConfigDbServiceControllerMethods() {
};
}

export const FILE_SERVICE_FILE_SERVICE_CONFIG_DB_SERVICE_NAME =
'FileServiceFileServiceConfigDbService';
export const FILE_SERVICE_CONFIG_DB_SERVICE_NAME = 'FileServiceConfigDbService';
30 changes: 25 additions & 5 deletions packages/proto/src/gen/file_provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,38 @@
/* eslint-disable */
import { GrpcMethod, GrpcStreamMethod } from '@nestjs/microservices';
import { Observable } from 'rxjs';
import { Bucket } from './file_bucket';

export const protobufPackage = 'juno.file_service.provider';

export interface FileProvider {}
export interface FileProvider {
providerName: string;
accessKey: string;
metadata: string;
bucket: Bucket[];
}

export interface GetFileProviderRequest {}
export interface GetFileProviderRequest {
providerName: string;
}

export interface CreateFileProviderRequest {}
export interface CreateFileProviderRequest {
providerName: string;
accessKey: string;
metadata: string;
bucket: Bucket[];
}

export interface UpdateFileProviderRequest {}
export interface UpdateFileProviderRequest {
providerName: string;
accessKey: string;
metadata: string;
bucket: Bucket[];
}

export interface DeleteFileProviderRequest {}
export interface DeleteFileProviderRequest {
providerName: string;
}

export const JUNO_FILE_SERVICE_PROVIDER_PACKAGE_NAME =
'juno.file_service.provider';
Expand Down
4 changes: 4 additions & 0 deletions packages/proto/src/gen/identifiers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,8 @@ export interface ApiKeyIdentifier {
hash?: string | undefined;
}

export interface FileConfigIdentifier {
id: number;
}

export const JUNO_IDENTIFIERS_PACKAGE_NAME = 'juno.identifiers';
Loading

0 comments on commit 16409e3

Please sign in to comment.