Explorar el Código

feat(database): 添加 OCR 记录迁移文件

- 新增 OCR记录数据库迁移文件
- 创建 OCR 记录模型和控制器- 添加 OCR 记录的路由
wui hace 11 meses
padre
commit
4b939bc2bd

+ 22 - 0
app/Controllers/Http/OcrRecordController.ts

@@ -0,0 +1,22 @@
+import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
+import PaginationService from 'App/Services/PaginationService'
+import { schema } from '@ioc:Adonis/Core/Validator'
+import OcrRecord from 'App/Models/OcrRecord'
+
+export default class OcrRecordController {
+    private paginationService = new PaginationService(OcrRecord)
+
+    public async index({ request }: HttpContextContract) {
+        return await this.paginationService.paginate(request.all())
+    }
+
+    public async store({ request, bouncer }: HttpContextContract) {
+        await request.validate({
+            schema: schema.create({
+                deviceId: schema.string(),
+                record: schema.string()
+            })
+        })
+        return await OcrRecord.create(request.all())
+    }
+}

+ 20 - 0
app/Models/OcrRecord.ts

@@ -0,0 +1,20 @@
+import AppBaseModel from 'App/Models/AppBaseModel'
+import { column } from '@ioc:Adonis/Lucid/Orm'
+import { DateTime } from 'luxon'
+
+export default class OcrRecord extends AppBaseModel {
+    @column({ isPrimary: true })
+    public id: number
+
+    @column()
+    public deviceId: string
+
+    @column()
+    public record: string
+
+    @column.dateTime({ autoCreate: true })
+    public createdAt: DateTime
+
+    @column.dateTime({ autoCreate: true, autoUpdate: true })
+    public updatedAt: DateTime
+}

+ 19 - 0
database/migrations/1739691792622_ocr_records.ts

@@ -0,0 +1,19 @@
+import BaseSchema from '@ioc:Adonis/Lucid/Schema'
+
+export default class extends BaseSchema {
+  protected tableName = 'ocr_records'
+
+  public async up () {
+    this.schema.createTable(this.tableName, (table) => {
+        table.increments('id')
+        table.string('device_id').notNullable()
+        table.text('record').notNullable()
+        table.timestamp('created_at', { useTz: true })
+        table.timestamp('updated_at', { useTz: true })
+    })
+  }
+
+  public async down () {
+    this.schema.dropTable(this.tableName)
+  }
+}

+ 1 - 0
start/routes.ts

@@ -106,5 +106,6 @@ Route.group(() => {
         Route.resource('memberships', 'MembershipsController').apiOnly()
         Route.resource('textRecord', 'TextRecordController').apiOnly()
         Route.resource('filesRecord', 'FilesRecordController').apiOnly()
+        Route.resource('ocrRecord', 'OcrRecordController').apiOnly()
     }).middleware('auth:api')
 }).prefix('/api')