fix:#75 added hash function to dbEventService

This commit is contained in:
Elmar Kresse
2025-04-27 13:57:34 +02:00
parent 57c2fcb7ad
commit 0d0943935d
2 changed files with 9 additions and 3 deletions

View File

@ -22,6 +22,7 @@ import (
"github.com/pocketbase/pocketbase/core"
"github.com/pocketbase/pocketbase/tools/types"
"htwkalender/data-manager/model"
"htwkalender/data-manager/service/functions"
"log/slog"
"time"
@ -197,7 +198,7 @@ func NewEvent(collection *core.Collection, event model.Event) (*Event, error) {
ev.SetCompulsory(event.Compulsory)
if event.UUID == "" {
event.UUID = uuid.NewString()
event.UUID = functions.GenerateUUID(event)
}
ev.SetUUID(event.UUID)
return ev, nil

View File

@ -10,8 +10,13 @@ import (
func GenerateUUIDs(events []model.Event) []model.Event {
for i, event := range events {
// generate a hash value from the event name, course and semester
hash := uuid.NewSHA1(uuid.NameSpaceOID, []byte(event.Name+event.Course))
events[i].UUID = hash.String()
hash := GenerateUUID(event)
events[i].UUID = hash
}
return events
}
func GenerateUUID(event model.Event) string {
hash := uuid.NewSHA1(uuid.NameSpaceOID, []byte(event.Name+event.Course)).String()
return hash
}