refactor(backend): isolate workspace aggregation
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
package projects
|
||||
|
||||
import "senlinai-agent/backend/internal/models"
|
||||
import (
|
||||
"time"
|
||||
|
||||
"senlinai-agent/backend/internal/models"
|
||||
)
|
||||
|
||||
// ProjectDTO 是项目 API 的稳定响应;ID 使用公开 identity,避免泄漏数据库自增主键。
|
||||
type ProjectDTO struct {
|
||||
@@ -30,6 +34,146 @@ type UpdateProjectRequest struct {
|
||||
Description *string `json:"description"`
|
||||
}
|
||||
|
||||
type CreateTaskInput struct {
|
||||
Title string
|
||||
Description string
|
||||
Status string
|
||||
DueAt *time.Time
|
||||
Tag string
|
||||
}
|
||||
|
||||
type UpdateTaskInput struct {
|
||||
Title string
|
||||
Description string
|
||||
Status string
|
||||
Completed bool
|
||||
NextProjectID uint
|
||||
Tag string
|
||||
}
|
||||
|
||||
type CreateFileSourceInput struct {
|
||||
Title string
|
||||
FilePath string
|
||||
}
|
||||
|
||||
type CreateCronPlanInput struct {
|
||||
Title string
|
||||
Schedule string
|
||||
Enabled bool
|
||||
NextRunAt *time.Time
|
||||
}
|
||||
|
||||
type Dashboard struct {
|
||||
ProjectID uint `json:"project_id"`
|
||||
PendingInboxCount int64 `json:"pending_inbox_count"`
|
||||
OpenTaskCount int64 `json:"open_task_count"`
|
||||
RecentNoteCount int64 `json:"recent_note_count"`
|
||||
RecentSessionCount int64 `json:"recent_session_count"`
|
||||
}
|
||||
|
||||
// WorkspaceDTO 是项目工作区首屏聚合响应,所有数据库对象均以公开 identity 关联。
|
||||
type WorkspaceDTO struct {
|
||||
Project WorkspaceProjectDTO `json:"project"`
|
||||
Channels []WorkspaceChannelDTO `json:"channels"`
|
||||
Tags []WorkspaceTagDTO `json:"tags"`
|
||||
RecentSessions []WorkspaceAISessionDTO `json:"recentSessions"`
|
||||
Inbox []WorkspaceInboxDTO `json:"inbox"`
|
||||
Tasks []WorkspaceTaskDTO `json:"tasks"`
|
||||
AISessions []WorkspaceAISessionDTO `json:"aiSessions"`
|
||||
NotesSources []WorkspaceNoteSourceDTO `json:"notesSources"`
|
||||
CronPlans []WorkspaceCronPlanDTO `json:"cronPlans"`
|
||||
}
|
||||
|
||||
// WorkspaceProjectDTO 补充工作区导航所需的项目摘要和未读计数。
|
||||
type WorkspaceProjectDTO struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Identifier string `json:"identifier"`
|
||||
Icon string `json:"icon"`
|
||||
Background string `json:"background"`
|
||||
Description string `json:"description"`
|
||||
Initials string `json:"initials"`
|
||||
UnreadCount int64 `json:"unreadCount"`
|
||||
}
|
||||
|
||||
// WorkspaceChannelDTO 描述系统频道或项目内自定义链接频道。
|
||||
type WorkspaceChannelDTO struct {
|
||||
ID string `json:"id"`
|
||||
ProjectID string `json:"projectId"`
|
||||
Type string `json:"type"`
|
||||
Title string `json:"title"`
|
||||
Icon string `json:"icon"`
|
||||
Count *int64 `json:"count,omitempty"`
|
||||
URL string `json:"url,omitempty"`
|
||||
SortOrder int `json:"sortOrder"`
|
||||
}
|
||||
|
||||
// WorkspaceTagDTO 是项目范围内的真实标签,不包含仅用于展示的虚拟标签。
|
||||
type WorkspaceTagDTO struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
// WorkspaceInboxDTO 是工作区 Inbox 行;Time 保留 UTC 时间语义供前端格式化。
|
||||
type WorkspaceInboxDTO struct {
|
||||
ID string `json:"id"`
|
||||
ProjectID string `json:"projectId"`
|
||||
Source string `json:"source"`
|
||||
Title string `json:"title"`
|
||||
Summary string `json:"summary"`
|
||||
Status string `json:"status"`
|
||||
Tag string `json:"tag"`
|
||||
Time time.Time `json:"time"`
|
||||
}
|
||||
|
||||
// WorkspaceTaskDTO 是工作区任务响应,标签和项目关联均使用 identity。
|
||||
type WorkspaceTaskDTO struct {
|
||||
ID string `json:"id"`
|
||||
ProjectID string `json:"projectId"`
|
||||
Title string `json:"title"`
|
||||
Summary string `json:"summary"`
|
||||
Completed bool `json:"completed"`
|
||||
Owner string `json:"owner"`
|
||||
Due *time.Time `json:"due"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
CompletedAt *time.Time `json:"completedAt"`
|
||||
TagID *string `json:"tagId"`
|
||||
Tag string `json:"tag"`
|
||||
}
|
||||
|
||||
// WorkspaceAISessionDTO 是工作区 AI 会话摘要。
|
||||
type WorkspaceAISessionDTO struct {
|
||||
ID string `json:"id"`
|
||||
ProjectID string `json:"projectId"`
|
||||
Title string `json:"title"`
|
||||
Summary string `json:"summary"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
References []string `json:"references"`
|
||||
}
|
||||
|
||||
// WorkspaceNoteSourceDTO 将笔记和资料合并为统一的工作区列表项。
|
||||
type WorkspaceNoteSourceDTO struct {
|
||||
ID string `json:"id"`
|
||||
ProjectID string `json:"projectId"`
|
||||
Kind string `json:"kind"`
|
||||
Title string `json:"title"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
Tag string `json:"tag"`
|
||||
Source string `json:"source"`
|
||||
}
|
||||
|
||||
// WorkspaceCronPlanDTO 是只展示元数据、不执行自主 Agent 的计划任务摘要。
|
||||
type WorkspaceCronPlanDTO struct {
|
||||
ID string `json:"id"`
|
||||
ProjectID string `json:"projectId"`
|
||||
Title string `json:"title"`
|
||||
Schedule string `json:"schedule"`
|
||||
NextRun *time.Time `json:"nextRun"`
|
||||
Enabled bool `json:"enabled"`
|
||||
LastResult string `json:"lastResult"`
|
||||
Owner string `json:"owner"`
|
||||
}
|
||||
|
||||
func projectDTO(project models.SenlinAgentProject) ProjectDTO {
|
||||
return ProjectDTO{
|
||||
ID: project.Identity,
|
||||
|
||||
Reference in New Issue
Block a user