Files
upstream-traggo/timespan/tagcheck.go
upstream-mirror cda7c1a474
Some checks failed
build / build (push) Failing after 3s
snapshot of https://github.com/traggo/server.git (master, 2026-09-16; blobs > 131072B omitted)
2026-09-16 05:24:45 +05:00

26 lines
588 B
Go

package timespan
import (
"fmt"
"github.com/jinzhu/gorm"
"github.com/traggo/server/model"
)
func tagsExist(db *gorm.DB, userID int, tags []model.TimeSpanTag) error {
existingTags := make(map[string]struct{})
for _, tag := range tags {
if _, ok := existingTags[tag.Key]; ok {
return fmt.Errorf("tag '%s' is present multiple times", tag.Key)
}
if db.Where("key = ?", tag.Key).Where("user_id = ?", userID).Find(new(model.TagDefinition)).RecordNotFound() {
return fmt.Errorf("tag '%s' does not exist", tag.Key)
}
existingTags[tag.Key] = struct{}{}
}
return nil
}