21 lines
690 B
Go
21 lines
690 B
Go
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
|
|
}
|