aides-repo-api/internal/services/taskservice/create.go
Maxim Slipenko 733cebfd81 feat: add database (#7)
Reviewed-on: https://code.alt-gnome.ru/aides-infra/aides-repo-api/pulls/7
Co-authored-by: Maxim Slipenko <no-reply@maxim.slipenko.com>
Co-committed-by: Maxim Slipenko <no-reply@maxim.slipenko.com>
2024-12-14 08:35:45 +00:00

31 lines
545 B
Go

package taskservice
import (
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/models"
)
func (s *Service) Create(repo string) (*models.Task, error) {
taskRepo := models.GitRepo{
Name: repo,
}
s.app.Db.Debug().
Where(&taskRepo).
FirstOrCreate(&taskRepo)
altRepo := models.ALTRepo{
Name: "Sisyphus",
}
s.app.Db.
Where(&altRepo).
FirstOrCreate(&altRepo)
task := models.Task{
RepoID: taskRepo.ID,
ALTRepo: altRepo,
Type: models.TypeUpsert,
}
result := s.app.Db.Create(&task)
return &task, result.Error
}