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,20 @@
package projects
import (
"gorm.io/gorm"
"senlinai-agent/backend/internal/models"
)
// FindOwnedProject 同时按 owner_id 与公开 identity 查询,防止仅凭可猜测标识越权访问项目。
// 内部自增 ID 只在通过所有权校验后供关联查询使用,不进入 API 契约。
func FindOwnedProject(userID uint, identity string) (*models.SenlinAgentProject, error) {
var project models.SenlinAgentProject
result := models.DBService.Where("owner_id = ? AND identity = ?", userID, identity).Limit(1).Find(&project)
if result.Error != nil {
return nil, result.Error
}
if result.RowsAffected == 0 {
return nil, gorm.ErrRecordNotFound
}
return &project, nil
}