refactor(api): expose project identity DTOs
This commit is contained in:
20
backend/internal/logic/projects/ownership.go
Normal file
20
backend/internal/logic/projects/ownership.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user