new schema initial commit
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2024-01-08 14:30:16 +11:00
parent 7ecf27f7dc
commit d1eecc5c4f
14 changed files with 631 additions and 149 deletions

55
models/group.go Normal file
View File

@@ -0,0 +1,55 @@
package models
import (
"errors"
"log"
)
type Group struct {
GroupId int `db:"GroupId"`
GroupName string `db:"GroupName"`
LdapGroup bool `db:"LdapGroup"`
LdapDn string `db:"LdapDN"`
Admin bool `db:"Admin"`
}
// GroupGetByName queries the database for the specified group name
func GroupGetByName(groupname string) (Group, error) {
var g Group
// Query database for matching group object
err := db.QueryRowx("SELECT * FROM groups WHERE GroupName=?", groupname).StructScan(&g)
if err != nil {
return g, errors.New("group not found")
}
return g, nil
}
// GroupList returns a list of all groups in database
func GroupList() ([]Group, error) {
var results []Group
// Query database for role definitions
rows, err := db.Queryx("SELECT * FROM groups")
if err != nil {
log.Printf("GroupList error executing sql record : '%s'\n", err)
return results, err
} else {
// parse all the results into a slice
for rows.Next() {
var g Group
err = rows.StructScan(&g)
if err != nil {
log.Printf("GroupList error parsing sql record : '%s'\n", err)
return results, err
}
results = append(results, g)
}
log.Printf("GroupList retrieved '%d' results\n", len(results))
}
return results, nil
}