Skip to content
This repository has been archived by the owner on Dec 4, 2024. It is now read-only.

Commit

Permalink
Merge pull request #87 from swibly/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
devkcud authored Oct 27, 2024
2 parents 4d8391d + 1433c57 commit 5141150
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion internal/service/repository/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,8 @@ func (pr *projectRepository) Update(projectID uint, updateModel *dto.ProjectUpda

var upstreamPublication model.ProjectPublication
if err := tx.Where("project_id = ?", upstreamProject.ID).First(&upstreamPublication).Error; err != nil {
tx.Rollback()
if errors.Is(err, gorm.ErrRecordNotFound) {
tx.Rollback()
return ErrUpstreamNotPublic
}
return err
Expand Down Expand Up @@ -813,6 +813,11 @@ func (pr *projectRepository) UnsafeDelete(id uint) error {
return err
}

if err := tx.Model(&model.Project{}).Where("fork = ?", id).Update("fork", nil).Error; err != nil {
tx.Rollback()
return err
}

if err := tx.Commit().Error; err != nil {
tx.Rollback()
return err
Expand Down Expand Up @@ -924,6 +929,18 @@ func (pr *projectRepository) ClearTrash(userID uint) error {
return err
}

deletedProjectIDs := make([]uint, len(projects))
for i, project := range projects {
deletedProjectIDs[i] = project.ID
}

if len(deletedProjectIDs) > 0 {
if err := tx.Model(&model.Project{}).Where("fork IN ?", deletedProjectIDs).Update("fork", nil).Error; err != nil {
tx.Rollback()
return err
}
}

if err := tx.Commit().Error; err != nil {
tx.Rollback()
return err
Expand Down

0 comments on commit 5141150

Please sign in to comment.