Skip to content

Commit ac579fe

Browse files
committed
feat(api): add task table and relations
1 parent ea87b05 commit ac579fe

6 files changed

Lines changed: 200 additions & 0 deletions

File tree

src/server/api/go/docs/docs.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2315,6 +2315,17 @@ const docTemplate = `{
23152315
"session_task_process_status": {
23162316
"type": "string"
23172317
},
2318+
"task": {
2319+
"description": "Message \u003c-\u003e Task",
2320+
"allOf": [
2321+
{
2322+
"$ref": "#/definitions/model.Task"
2323+
}
2324+
]
2325+
},
2326+
"task_id": {
2327+
"type": "string"
2328+
},
23182329
"updated_at": {
23192330
"type": "string"
23202331
}
@@ -2392,6 +2403,13 @@ const docTemplate = `{
23922403
"space_id": {
23932404
"type": "string"
23942405
},
2406+
"tasks": {
2407+
"description": "Session \u003c-\u003e Task",
2408+
"type": "array",
2409+
"items": {
2410+
"$ref": "#/definitions/model.Task"
2411+
}
2412+
},
23952413
"updated_at": {
23962414
"type": "string"
23972415
}
@@ -2432,6 +2450,50 @@ const docTemplate = `{
24322450
}
24332451
}
24342452
},
2453+
"model.Task": {
2454+
"type": "object",
2455+
"properties": {
2456+
"created_at": {
2457+
"type": "string"
2458+
},
2459+
"id": {
2460+
"type": "string"
2461+
},
2462+
"is_planning_task": {
2463+
"type": "boolean"
2464+
},
2465+
"messages": {
2466+
"description": "Task \u003c-\u003e Message (one-to-many)",
2467+
"type": "array",
2468+
"items": {
2469+
"$ref": "#/definitions/model.Message"
2470+
}
2471+
},
2472+
"session": {
2473+
"description": "Task \u003c-\u003e Session",
2474+
"allOf": [
2475+
{
2476+
"$ref": "#/definitions/model.Session"
2477+
}
2478+
]
2479+
},
2480+
"session_id": {
2481+
"type": "string"
2482+
},
2483+
"task_data": {
2484+
"type": "object"
2485+
},
2486+
"task_order": {
2487+
"type": "integer"
2488+
},
2489+
"task_status": {
2490+
"type": "string"
2491+
},
2492+
"updated_at": {
2493+
"type": "string"
2494+
}
2495+
}
2496+
},
24352497
"serializer.Response": {
24362498
"type": "object",
24372499
"properties": {

src/server/api/go/docs/swagger.json

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2312,6 +2312,17 @@
23122312
"session_task_process_status": {
23132313
"type": "string"
23142314
},
2315+
"task": {
2316+
"description": "Message \u003c-\u003e Task",
2317+
"allOf": [
2318+
{
2319+
"$ref": "#/definitions/model.Task"
2320+
}
2321+
]
2322+
},
2323+
"task_id": {
2324+
"type": "string"
2325+
},
23152326
"updated_at": {
23162327
"type": "string"
23172328
}
@@ -2389,6 +2400,13 @@
23892400
"space_id": {
23902401
"type": "string"
23912402
},
2403+
"tasks": {
2404+
"description": "Session \u003c-\u003e Task",
2405+
"type": "array",
2406+
"items": {
2407+
"$ref": "#/definitions/model.Task"
2408+
}
2409+
},
23922410
"updated_at": {
23932411
"type": "string"
23942412
}
@@ -2429,6 +2447,50 @@
24292447
}
24302448
}
24312449
},
2450+
"model.Task": {
2451+
"type": "object",
2452+
"properties": {
2453+
"created_at": {
2454+
"type": "string"
2455+
},
2456+
"id": {
2457+
"type": "string"
2458+
},
2459+
"is_planning_task": {
2460+
"type": "boolean"
2461+
},
2462+
"messages": {
2463+
"description": "Task \u003c-\u003e Message (one-to-many)",
2464+
"type": "array",
2465+
"items": {
2466+
"$ref": "#/definitions/model.Message"
2467+
}
2468+
},
2469+
"session": {
2470+
"description": "Task \u003c-\u003e Session",
2471+
"allOf": [
2472+
{
2473+
"$ref": "#/definitions/model.Session"
2474+
}
2475+
]
2476+
},
2477+
"session_id": {
2478+
"type": "string"
2479+
},
2480+
"task_data": {
2481+
"type": "object"
2482+
},
2483+
"task_order": {
2484+
"type": "integer"
2485+
},
2486+
"task_status": {
2487+
"type": "string"
2488+
},
2489+
"updated_at": {
2490+
"type": "string"
2491+
}
2492+
}
2493+
},
24322494
"serializer.Response": {
24332495
"type": "object",
24342496
"properties": {

src/server/api/go/docs/swagger.yaml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,12 @@ definitions:
263263
type: string
264264
session_task_process_status:
265265
type: string
266+
task:
267+
allOf:
268+
- $ref: '#/definitions/model.Task'
269+
description: Message <-> Task
270+
task_id:
271+
type: string
266272
updated_at:
267273
type: string
268274
type: object
@@ -312,6 +318,11 @@ definitions:
312318
description: Session <-> Space
313319
space_id:
314320
type: string
321+
tasks:
322+
description: Session <-> Task
323+
items:
324+
$ref: '#/definitions/model.Task'
325+
type: array
315326
updated_at:
316327
type: string
317328
type: object
@@ -337,6 +348,34 @@ definitions:
337348
updated_at:
338349
type: string
339350
type: object
351+
model.Task:
352+
properties:
353+
created_at:
354+
type: string
355+
id:
356+
type: string
357+
is_planning_task:
358+
type: boolean
359+
messages:
360+
description: Task <-> Message (one-to-many)
361+
items:
362+
$ref: '#/definitions/model.Message'
363+
type: array
364+
session:
365+
allOf:
366+
- $ref: '#/definitions/model.Session'
367+
description: Task <-> Session
368+
session_id:
369+
type: string
370+
task_data:
371+
type: object
372+
task_order:
373+
type: integer
374+
task_status:
375+
type: string
376+
updated_at:
377+
type: string
378+
type: object
340379
serializer.Response:
341380
properties:
342381
code:

src/server/api/go/internal/modules/model/message.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,18 @@ type Message struct {
1919
PartsMeta datatypes.JSONType[Asset] `gorm:"type:jsonb;not null" swaggertype:"-" json:"-"`
2020
Parts []Part `gorm:"-" swaggertype:"array,object" json:"parts"`
2121

22+
TaskID *uuid.UUID `gorm:"type:uuid;index" json:"task_id"`
23+
2224
SessionTaskProcessStatus string `gorm:"type:text;not null;default:'pending';check:session_task_process_status IN ('success','failed','running','pending')" json:"session_task_process_status"`
2325

2426
CreatedAt time.Time `gorm:"autoCreateTime;index:idx_session_created,priority:2,sort:desc" json:"created_at"`
2527
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"`
2628

2729
// Message <-> Session
2830
Session *Session `gorm:"foreignKey:SessionID;references:ID;constraint:OnDelete:CASCADE,OnUpdate:CASCADE;" json:"session"`
31+
32+
// Message <-> Task
33+
Task *Task `gorm:"foreignKey:TaskID;references:ID;constraint:OnDelete:SET NULL,OnUpdate:CASCADE;" json:"task"`
2934
}
3035

3136
func (Message) TableName() string { return "messages" }

src/server/api/go/internal/modules/model/session.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ type Session struct {
2424

2525
// Session <-> Message
2626
Messages []Message `gorm:"constraint:OnDelete:CASCADE,OnUpdate:CASCADE;" json:"messages"`
27+
28+
// Session <-> Task
29+
Tasks []Task `gorm:"constraint:OnDelete:CASCADE,OnUpdate:CASCADE;" json:"tasks"`
2730
}
2831

2932
func (Session) TableName() string { return "sessions" }
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package model
2+
3+
import (
4+
"time"
5+
6+
"github.com/google/uuid"
7+
"gorm.io/datatypes"
8+
)
9+
10+
type Task struct {
11+
ID uuid.UUID `gorm:"type:uuid;default:gen_random_uuid();primaryKey" json:"id"`
12+
SessionID uuid.UUID `gorm:"type:uuid;not null;index:ix_session_session_id;index:ix_session_session_id_task_id,priority:1;index:ix_session_session_id_task_status,priority:1;uniqueIndex:uq_session_id_task_order,priority:1" json:"session_id"`
13+
14+
TaskOrder int `gorm:"not null;uniqueIndex:uq_session_id_task_order,priority:2" json:"task_order"`
15+
TaskData datatypes.JSONMap `gorm:"type:jsonb;not null" swaggertype:"object" json:"task_data"`
16+
TaskStatus string `gorm:"type:text;not null;default:'pending';check:task_status IN ('success','failed','running','pending');index:ix_session_session_id_task_status,priority:2" json:"task_status"`
17+
IsPlanningTask bool `gorm:"not null;default:false" json:"is_planning_task"`
18+
19+
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
20+
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"`
21+
22+
// Task <-> Session
23+
Session *Session `gorm:"foreignKey:SessionID;references:ID;constraint:OnDelete:CASCADE,OnUpdate:CASCADE;" json:"session"`
24+
25+
// Task <-> Message (one-to-many)
26+
Messages []Message `gorm:"constraint:OnDelete:SET NULL,OnUpdate:CASCADE;" json:"messages"`
27+
}
28+
29+
func (Task) TableName() string { return "tasks" }

0 commit comments

Comments
 (0)