refactor(api): expose project identity DTOs

This commit is contained in:
2026-07-21 14:22:13 +08:00
parent 4bfeec8d2b
commit 5341b44cc5
6 changed files with 378 additions and 35 deletions

View File

@@ -0,0 +1,42 @@
package projects
import "senlinai-agent/backend/internal/models"
// ProjectDTO 是项目 API 的稳定响应ID 使用公开 identity避免泄漏数据库自增主键。
type ProjectDTO 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"`
}
// CreateProjectRequest 描述创建项目时允许客户端写入的字段。
type CreateProjectRequest struct {
Name string `json:"name"`
Identifier string `json:"identifier"`
Icon string `json:"icon"`
Background string `json:"background"`
Description string `json:"description"`
}
// UpdateProjectRequest 使用指针区分“未提供”和“显式清空”,且只开放项目设置字段。
type UpdateProjectRequest struct {
Name *string `json:"name"`
Identifier *string `json:"identifier"`
Icon *string `json:"icon"`
Background *string `json:"background"`
Description *string `json:"description"`
}
func projectDTO(project models.SenlinAgentProject) ProjectDTO {
return ProjectDTO{
ID: project.Identity,
Name: project.Name,
Identifier: project.Identifier,
Icon: project.Icon,
Background: project.Background,
Description: project.Description,
}
}