refactor: shorten model and table prefixes
This commit is contained in:
@@ -39,11 +39,11 @@ func (s *Service) database() *gorm.DB {
|
||||
// Assign 在同一事务内由用户 identity 解析内部主键,并同步两个指派字段,避免 DTO 返回陈旧 identity。
|
||||
func (s *Service) Assign(taskID uint, assigneeIdentity string) error {
|
||||
return s.database().Transaction(func(tx *gorm.DB) error {
|
||||
var task models.SenlinAgentTask
|
||||
var task models.SaTask
|
||||
if err := tx.First(&task, taskID).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
var assignee models.SenlinAgentUser
|
||||
var assignee models.SaUser
|
||||
if err := tx.Where("identity = ?", assigneeIdentity).First(&assignee).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -52,7 +52,7 @@ func (s *Service) Assign(taskID uint, assigneeIdentity string) error {
|
||||
}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return tx.Create(&models.SenlinAgentProjectEvent{
|
||||
return tx.Create(&models.SaProjectEvent{
|
||||
ProjectID: task.ProjectID,
|
||||
ActorID: task.CreatedBy,
|
||||
EventType: "task_assigned",
|
||||
@@ -76,10 +76,10 @@ func (s *Service) ShareObject(taskID uint, objectType string, objectID uint) err
|
||||
if err := ensureSharedObjectInProject(tx, task.ProjectID, objectType, objectID); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := tx.Create(&models.SenlinAgentTaskShare{TaskID: taskID, ObjectType: objectType, ObjectID: objectID}).Error; err != nil {
|
||||
if err := tx.Create(&models.SaTaskShare{TaskID: taskID, ObjectType: objectType, ObjectID: objectID}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return tx.Create(&models.SenlinAgentProjectEvent{
|
||||
return tx.Create(&models.SaProjectEvent{
|
||||
ProjectID: task.ProjectID,
|
||||
ActorID: task.CreatedBy,
|
||||
EventType: "task_object_shared",
|
||||
@@ -92,14 +92,14 @@ func (s *Service) ShareObject(taskID uint, objectType string, objectID uint) err
|
||||
|
||||
// VisibleLinkedObjects 对被指派人也只返回显式分享记录,不因任务可见而扩大关联对象权限。
|
||||
func (s *Service) VisibleLinkedObjects(taskID uint, viewerID uint) ([]LinkedObject, error) {
|
||||
var task models.SenlinAgentTask
|
||||
var task models.SaTask
|
||||
if err := s.database().First(&task, taskID).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if task.AssigneeID == nil || *task.AssigneeID != viewerID {
|
||||
return []LinkedObject{}, nil
|
||||
}
|
||||
var shares []models.SenlinAgentTaskShare
|
||||
var shares []models.SaTaskShare
|
||||
if err := s.database().Where("task_id = ?", taskID).Find(&shares).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -132,7 +132,7 @@ func (s *Service) Create(ownerID uint, projectIdentity string, input CreateTaskI
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
task := models.SenlinAgentTask{
|
||||
task := models.SaTask{
|
||||
ProjectID: project.ID, CreatedBy: ownerID, TagID: tagID,
|
||||
Title: title, Description: strings.TrimSpace(input.Description), Status: status, DueAt: utcOptionalTime(input.DueAt),
|
||||
}
|
||||
@@ -194,7 +194,7 @@ func (s *Service) Update(ownerID uint, projectIdentity, taskIdentity string, inp
|
||||
task.TagIdentity = tagIdentity
|
||||
if targetProject.ID != currentProject.ID {
|
||||
// 现有分享都在原项目边界内;移动后必须清空,避免旧项目 note/source 继续对被指派人可见。
|
||||
if err := tx.Where("task_id = ?", task.ID).Delete(&models.SenlinAgentTaskShare{}).Error; err != nil {
|
||||
if err := tx.Where("task_id = ?", task.ID).Delete(&models.SaTaskShare{}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -207,24 +207,24 @@ func (s *Service) Update(ownerID uint, projectIdentity, taskIdentity string, inp
|
||||
return result, err
|
||||
}
|
||||
|
||||
func lockTaskByID(tx *gorm.DB, taskID uint) (*models.SenlinAgentTask, error) {
|
||||
var task models.SenlinAgentTask
|
||||
func lockTaskByID(tx *gorm.DB, taskID uint) (*models.SaTask, error) {
|
||||
var task models.SaTask
|
||||
if err := tx.Clauses(clause.Locking{Strength: "UPDATE"}).First(&task, taskID).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &task, nil
|
||||
}
|
||||
|
||||
func lockTaskByIdentity(tx *gorm.DB, taskIdentity string) (*models.SenlinAgentTask, error) {
|
||||
var task models.SenlinAgentTask
|
||||
func lockTaskByIdentity(tx *gorm.DB, taskIdentity string) (*models.SaTask, error) {
|
||||
var task models.SaTask
|
||||
if err := tx.Clauses(clause.Locking{Strength: "UPDATE"}).Where("identity = ?", taskIdentity).First(&task).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &task, nil
|
||||
}
|
||||
|
||||
func findOwnedProject(tx *gorm.DB, ownerID uint, identity string) (*models.SenlinAgentProject, error) {
|
||||
var project models.SenlinAgentProject
|
||||
func findOwnedProject(tx *gorm.DB, ownerID uint, identity string) (*models.SaProject, error) {
|
||||
var project models.SaProject
|
||||
if err := tx.Where("owner_id = ? AND identity = ?", ownerID, identity).First(&project).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -236,21 +236,21 @@ func findOrCreateProjectTag(tx *gorm.DB, projectID uint, value string) (*uint, *
|
||||
if name == "" {
|
||||
return nil, nil, "", nil
|
||||
}
|
||||
candidate := models.SenlinAgentTag{ProjectID: projectID, Name: name}
|
||||
candidate := models.SaTag{ProjectID: projectID, Name: name}
|
||||
if err := tx.Clauses(clause.OnConflict{
|
||||
Columns: []clause.Column{{Name: "project_id"}, {Name: "name"}},
|
||||
DoNothing: true,
|
||||
}).Create(&candidate).Error; err != nil {
|
||||
return nil, nil, "", err
|
||||
}
|
||||
var tag models.SenlinAgentTag
|
||||
var tag models.SaTag
|
||||
if err := tx.Where("project_id = ? AND name = ?", projectID, name).First(&tag).Error; err != nil {
|
||||
return nil, nil, "", err
|
||||
}
|
||||
return &tag.ID, &tag.Identity, tag.Name, nil
|
||||
}
|
||||
|
||||
func makeTaskDTO(task models.SenlinAgentTask, projectIdentity string, tagIdentity *string, tagName string) TaskDTO {
|
||||
func makeTaskDTO(task models.SaTask, projectIdentity string, tagIdentity *string, tagName string) TaskDTO {
|
||||
return TaskDTO{
|
||||
ID: task.Identity, ProjectID: projectIdentity, Title: task.Title, Description: task.Description,
|
||||
Status: task.Status, Completed: task.Status == "done", DueAt: utcOptionalTime(task.DueAt),
|
||||
@@ -271,7 +271,7 @@ func ensureSharedObjectInProject(tx *gorm.DB, projectID uint, objectType string,
|
||||
switch objectType {
|
||||
case "note":
|
||||
var count int64
|
||||
if err := tx.Model(&models.SenlinAgentNote{}).Where("id = ? AND project_id = ?", objectID, projectID).Count(&count).Error; err != nil {
|
||||
if err := tx.Model(&models.SaNote{}).Where("id = ? AND project_id = ?", objectID, projectID).Count(&count).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if count == 0 {
|
||||
@@ -279,7 +279,7 @@ func ensureSharedObjectInProject(tx *gorm.DB, projectID uint, objectType string,
|
||||
}
|
||||
case "source":
|
||||
var count int64
|
||||
if err := tx.Model(&models.SenlinAgentSource{}).Where("id = ? AND project_id = ?", objectID, projectID).Count(&count).Error; err != nil {
|
||||
if err := tx.Model(&models.SaSource{}).Where("id = ? AND project_id = ?", objectID, projectID).Count(&count).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if count == 0 {
|
||||
|
||||
Reference in New Issue
Block a user