snapshot of https://github.com/traggo/server.git (master, 2026-09-16; blobs > 131072B omitted)
Some checks failed
build / build (push) Failing after 3s
Some checks failed
build / build (push) Failing after 3s
This commit is contained in:
25
timespan/tagcheck.go
Normal file
25
timespan/tagcheck.go
Normal file
@@ -0,0 +1,25 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user