aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/user/service.go
diff options
context:
space:
mode:
authorVidhu Kant Sharma <vidhukant@vidhukant.com>2025-10-12 00:05:30 +0530
committerVidhu Kant Sharma <vidhukant@vidhukant.com>2025-10-12 00:05:30 +0530
commita356803594ab36fa69e7dbcbd79261d8b46f4262 (patch)
tree0146efe4c52b1c65c1967ab1f412306c410c10d4 /user/service.go
parent193be465b21838d2796fafbe1c5d9854038a3f8c (diff)
removed useless user fields and functions, added rolesHEADv0.19.0master
Diffstat (limited to 'user/service.go')
-rw-r--r--user/service.go35
1 files changed, 6 insertions, 29 deletions
diff --git a/user/service.go b/user/service.go
index 222df4a..4dec8bc 100644
--- a/user/service.go
+++ b/user/service.go
@@ -1,5 +1,5 @@
/* openbills - Server for web based Libre Billing Software
- * Copyright (C) 2023-2024 Vidhu Kant Sharma <vidhukant@vidhukant.com>
+ * Copyright (C) 2023-2025 Vidhu Kant Sharma <vidhukant@vidhukant.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -27,14 +27,12 @@ func (u *User) Create() error {
return res.Error
}
-func GetUserWithAccountName(user *User, accountName, method string) error {
+func GetUserByAccountName(user *User, accountName, method string) error {
if method != "username" && method != "email" {
return e.ErrInvalidLoginMethod
}
- res := db.Where(method + " = ?", accountName).Find(&user)
-
- // TODO: handle potential errors
+ res := db.Where(method + " = ?", accountName).Preload("Roles").Find(&user)
if res.Error != nil {
return res.Error
}
@@ -46,10 +44,8 @@ func GetUserWithAccountName(user *User, accountName, method string) error {
return nil
}
-func GetUser(user *User, id uint) error {
- res := db.Find(&user, id)
-
- // TODO: handle potential errors
+func GetUserById(user *User, id uint) error {
+ res := db.Preload("Roles").Find(&user, id)
if res.Error != nil {
return res.Error
}
@@ -63,8 +59,6 @@ func GetUser(user *User, id uint) error {
func (u *User) del() error {
res := db.Delete(u)
-
- // TODO: handle potential errors
if res.Error != nil {
return res.Error
}
@@ -76,21 +70,4 @@ func (u *User) del() error {
return nil
}
-func (u *User) update(changes map[string]interface{}) error {
- res := db.Model(&u).
- Omit("email").
- Omit("password").
- Omit("username").
- Updates(changes)
-
- // TODO: handle potential errors
- if res.Error != nil {
- return res.Error
- }
-
- if res.RowsAffected == 0 {
- return e.ErrNotFound
- }
-
- return nil
-}
+// TODO: email/password updation (no username changes) with OTP verification or something