first commit
This commit is contained in:
17
models/jsonResponse.go
Normal file
17
models/jsonResponse.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package models
|
||||
|
||||
type JsonResponse struct {
|
||||
Message string `json:"message,omitempty"`
|
||||
}
|
||||
|
||||
func NewJsonErrorResponse(err error) JsonResponse {
|
||||
return JsonResponse{
|
||||
Message: err.Error(),
|
||||
}
|
||||
}
|
||||
|
||||
func NewJsonMessageResponse(msg string) JsonResponse {
|
||||
return JsonResponse{
|
||||
Message: msg,
|
||||
}
|
||||
}
|
||||
37
models/permission.go
Normal file
37
models/permission.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"database/sql/driver"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type Permissions []Permission
|
||||
|
||||
func (r *Permissions) DefaultPermissions() {
|
||||
*r = append(*r,
|
||||
Permission{Name: "settings", Permission: 7},
|
||||
Permission{Name: "userSettings", Permission: 7},
|
||||
Permission{Name: "members", Permission: 7},
|
||||
Permission{Name: "events", Permission: 7},
|
||||
)
|
||||
}
|
||||
|
||||
// --- Implement driver.Valuer (for saving to DB)
|
||||
func (r Permissions) Value() (driver.Value, error) {
|
||||
return json.Marshal(r)
|
||||
}
|
||||
|
||||
// --- Implement sql.Scanner (for reading from DB)
|
||||
func (r *Permissions) Scan(value any) error {
|
||||
bytes, ok := value.([]byte)
|
||||
if !ok {
|
||||
return fmt.Errorf("failed to unmarshal Settings: %v", value)
|
||||
}
|
||||
return json.Unmarshal(bytes, r)
|
||||
}
|
||||
|
||||
type Permission struct {
|
||||
Name string `json:"name"`
|
||||
Permission int `json:"permission"`
|
||||
}
|
||||
7
models/role.go
Normal file
7
models/role.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package models
|
||||
|
||||
type Role struct {
|
||||
Id uint `gorm:"primaryKey" json:"id"`
|
||||
Role string `gorm:"column:role" json:"role"`
|
||||
Permissions Permissions `gorm:"type:json" json:"permissions"`
|
||||
}
|
||||
39
models/settings.go
Normal file
39
models/settings.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"database/sql/driver"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type Settings struct {
|
||||
PrimaryColor string `json:"primaryColor,omitempty"`
|
||||
PrimaryColorText string `json:"primaryColorText,omitempty"`
|
||||
SecondaryColor string `json:"secondaryColor,omitempty"`
|
||||
SecondaryColorText string `json:"secondaryColorText,omitempty"`
|
||||
Icon string `json:"icon,omitempty"`
|
||||
DatabaseName string `json:"databaseName,omitempty"`
|
||||
DatabaseToken string `json:"databaseToken,omitempty"`
|
||||
}
|
||||
|
||||
func (s *Settings) DefaultQuasarSettings() {
|
||||
s.DatabaseName = "members.dba"
|
||||
s.PrimaryColor = "#1976d2"
|
||||
s.PrimaryColorText = "#ffffff"
|
||||
s.SecondaryColor = "#26a69a"
|
||||
s.SecondaryColorText = "#ffffff"
|
||||
}
|
||||
|
||||
// --- Implement driver.Valuer (for saving to DB)
|
||||
func (s Settings) Value() (driver.Value, error) {
|
||||
return json.Marshal(s)
|
||||
}
|
||||
|
||||
// --- Implement sql.Scanner (for reading from DB)
|
||||
func (s *Settings) Scan(value any) error {
|
||||
bytes, ok := value.([]byte)
|
||||
if !ok {
|
||||
return fmt.Errorf("failed to unmarshal Settings: %v", value)
|
||||
}
|
||||
return json.Unmarshal(bytes, s)
|
||||
}
|
||||
14
models/user.go
Normal file
14
models/user.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package models
|
||||
|
||||
type User struct {
|
||||
Id uint `gorm:"primaryKey" json:"id"`
|
||||
Name string `gorm:"column:user_name" json:"user"`
|
||||
Email string `gorm:"column:email" json:"email"`
|
||||
Role string `gorm:"column:role" json:"role"`
|
||||
Password string `gorm:"column:password" json:"password"`
|
||||
Settings Settings `gorm:"type:json" json:"settings"`
|
||||
}
|
||||
|
||||
func (u *User) IsValid() bool {
|
||||
return u.Name != ""
|
||||
}
|
||||
Reference in New Issue
Block a user