phoenix/backend/groups.go

33 lines
576 B
Go
Raw Normal View History

2023-04-06 10:36:11 +05:00
package backend
import (
2023-04-06 10:37:48 +05:00
"gorm.io/gorm"
2023-04-06 10:36:11 +05:00
)
type Group struct {
2023-04-06 10:37:48 +05:00
ID uint64 `gorm:"primaryKey"`
2023-04-06 10:36:11 +05:00
Name string `gorm:"unique,notNull"`
Links []Link
}
func GetGroups(db *gorm.DB) ([]Group, error) {
2023-04-06 10:37:48 +05:00
var groups []Group
result := db.Model(&Group{}).Preload("Links").Find(&groups)
if result.Error != nil {
return nil, result.Error
}
return groups, nil
2023-04-06 10:36:11 +05:00
}
func CreateGroup(db *gorm.DB, groupName string) (Group, error) {
2023-04-06 10:37:48 +05:00
group := Group{
Name: groupName,
}
result := db.Create(&group)
if result.Error != nil {
return Group{}, result.Error
}
2023-04-06 10:36:11 +05:00
2023-04-06 10:37:48 +05:00
return group, nil
2023-04-06 10:36:11 +05:00
}