From f6602f28236b3ac2242bd6a2708706695c6d91dc Mon Sep 17 00:00:00 2001 From: Nathan Coad Date: Wed, 3 Jan 2024 14:50:44 +1100 Subject: [PATCH] change json key names --- models/setup.go | 24 +++++++++++++++++++----- models/user.go | 8 ++++---- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/models/setup.go b/models/setup.go index 1927745..6b0d687 100644 --- a/models/setup.go +++ b/models/setup.go @@ -25,7 +25,8 @@ const createRoles string = ` RoleId INTEGER PRIMARY KEY ASC, RoleName VARCHAR, ReadOnly BOOLEAN, - Admin BOOLEAN + Admin BOOLEAN, + LdapGroup VARCHAR ); ` @@ -96,15 +97,15 @@ func CreateTables() { } rowCount, _ = CheckCount("roles") if rowCount == 0 { - if _, err = db.Exec("INSERT INTO roles VALUES(1, 'Admin', false, true);"); err != nil { + if _, err = db.Exec("INSERT INTO roles VALUES(1, 'Admin', false, true, '');"); err != nil { log.Printf("Error adding initial admin role : '%s'", err) os.Exit(1) } - if _, err = db.Exec("INSERT INTO roles VALUES(2, 'UserRole', false, false);"); err != nil { + if _, err = db.Exec("INSERT INTO roles VALUES(2, 'UserRole', false, false, '');"); err != nil { log.Printf("Error adding initial user role : '%s'", err) os.Exit(1) } - if _, err = db.Exec("INSERT INTO roles VALUES(3, 'GuestRole', true, false);"); err != nil { + if _, err = db.Exec("INSERT INTO roles VALUES(3, 'GuestRole', true, false, '');"); err != nil { log.Printf("Error adding initial guest role : '%s'", err) os.Exit(1) } @@ -145,10 +146,23 @@ func CreateTables() { schemaCheck, _ := CheckColumnExists("schema", "Version") if !schemaCheck { if _, err = db.Exec("INSERT INTO schema VALUES(1);"); err != nil { - log.Printf("Error adding initial scehama version : '%s'", err) + log.Printf("Error adding initial schema version : '%s'", err) os.Exit(1) } } + + // Database updates added after initial version released + ldapCheck, _ := CheckColumnExists("roles", "LdapGroup") + + if !ldapCheck { + // Add the column for LdapGroup in the roles table + _, err := db.Exec("ALTER TABLE roles ADD COLUMN LdapGroup VARCHAR;") + if err != nil { + log.Printf("Error altering roles table to add LdapGroup column : '%s'\n", err) + os.Exit(1) + } + } + } // Count the number of records in the sqlite database diff --git a/models/user.go b/models/user.go index d6ac0d2..5f5b941 100644 --- a/models/user.go +++ b/models/user.go @@ -1,19 +1,19 @@ package models import ( - "smt/utils/token" "errors" "log" "net/http" + "smt/utils/token" "github.com/gin-gonic/gin" "golang.org/x/crypto/bcrypt" ) type User struct { - UserId int `db:"UserId"` - RoleId int `db:"RoleId"` - UserName string `db:"UserName"` + UserId int `db:"UserId" json:"userId"` + RoleId int `db:"RoleId" json:"roleId"` + UserName string `db:"UserName" json:"userName"` Password string `db:"Password" json:"-"` }