Removed hardcoded string

- Roles are not hardcoded anymore (closes #4)
This commit is contained in:
2026-03-03 15:55:39 +01:00
parent 0afd5bfc3a
commit e7da8c9443
2 changed files with 19 additions and 1 deletions

View File

@@ -37,7 +37,7 @@ func Register(w http.ResponseWriter, r *http.Request) {
}
user.Password = hashed
user.ID = utils.GenerateUUID()
user.Role = "user"
user.Role = models.RoleUser
if err := storage.AddUser(&user); err != nil {
log.Println("POST [api/register] " + r.RemoteAddr + ": " + err.Error())

View File

@@ -24,3 +24,21 @@ type ExpenseShare struct {
UserID string `json:"user_id"`
ShareCents int64 `json:"share_cents"`
}
type Role int
const (
RoleUser = iota
RoleAdmin
)
func (r Role) String() string {
switch r {
case RoleUser:
return "user"
case RoleAdmin:
return "admin"
default:
return "unknown"
}
}