feat: 标签接入mongodb
This commit is contained in:
parent
df826308dc
commit
72d3fc8619
|
@ -3,8 +3,8 @@ import { AppController } from './app.controller';
|
|||
import { AppService } from './app.service';
|
||||
import { NacosModule } from './nacos/nacos.module';
|
||||
import { ConfigModule } from '@nestjs/config';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { RetrievalModule } from './retrieval/retrieval.module';
|
||||
import { LabelModule } from './label/label.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
|
@ -14,6 +14,7 @@ import { RetrievalModule } from './retrieval/retrieval.module';
|
|||
}),
|
||||
NacosModule,
|
||||
RetrievalModule,
|
||||
LabelModule,
|
||||
],
|
||||
controllers: [AppController],
|
||||
providers: [AppService],
|
||||
|
|
13
apps/services/dicom/src/label/label.controller.ts
Normal file
13
apps/services/dicom/src/label/label.controller.ts
Normal file
|
@ -0,0 +1,13 @@
|
|||
import { Controller } from '@nestjs/common';
|
||||
import { EventPattern } from '@nestjs/microservices';
|
||||
import { LabelService } from './label.service';
|
||||
|
||||
@Controller()
|
||||
export class LabelController {
|
||||
constructor(private readonly labelService: LabelService) {}
|
||||
|
||||
@EventPattern({ cmd: 'dicom.label.create' })
|
||||
async createLabel(payload) {
|
||||
return await this.labelService.createLabel();
|
||||
}
|
||||
}
|
15
apps/services/dicom/src/label/label.module.ts
Normal file
15
apps/services/dicom/src/label/label.module.ts
Normal file
|
@ -0,0 +1,15 @@
|
|||
import { Module } from '@nestjs/common';
|
||||
import { LabelController } from './label.controller';
|
||||
import { Label, LabelSchema } from './schema/label.schema';
|
||||
import { LabelService } from './label.service';
|
||||
import { MongooseModule } from '@nestjs/mongoose';
|
||||
|
||||
@Module({
|
||||
controllers: [LabelController],
|
||||
imports: [
|
||||
MongooseModule.forRoot('mongodb://test:test@localhost:27017/tavi'),
|
||||
MongooseModule.forFeature([{ name: Label.name, schema: LabelSchema }]),
|
||||
],
|
||||
providers: [LabelService],
|
||||
})
|
||||
export class LabelModule {}
|
22
apps/services/dicom/src/label/label.service.ts
Normal file
22
apps/services/dicom/src/label/label.service.ts
Normal file
|
@ -0,0 +1,22 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import { Label, LabelDocument } from './schema/label.schema';
|
||||
import { InjectModel } from '@nestjs/mongoose';
|
||||
import { Model } from 'mongoose';
|
||||
|
||||
@Injectable()
|
||||
export class LabelService {
|
||||
constructor(
|
||||
@InjectModel(Label.name)
|
||||
private readonly labelModel: Model<LabelDocument>,
|
||||
) {}
|
||||
async createLabel() {
|
||||
// 创建一个新的 Label 实例
|
||||
const newLabel = new this.labelModel({
|
||||
name: '钙化',
|
||||
description: '钙化的关键词',
|
||||
});
|
||||
|
||||
// 使用 save 方法保存实例到数据库
|
||||
return await newLabel.save();
|
||||
}
|
||||
}
|
13
apps/services/dicom/src/label/schema/label.schema.ts
Normal file
13
apps/services/dicom/src/label/schema/label.schema.ts
Normal file
|
@ -0,0 +1,13 @@
|
|||
import { Schema, Document, model } from 'mongoose';
|
||||
|
||||
export interface LabelDocument extends Document {
|
||||
name: string;
|
||||
description?: string;
|
||||
}
|
||||
|
||||
export const LabelSchema = new Schema({
|
||||
name: { type: String, required: true },
|
||||
description: String,
|
||||
});
|
||||
|
||||
export const Label = model<LabelDocument>('Label', LabelSchema);
|
Loading…
Reference in New Issue
Block a user