feat: allow admin to user profile (#51)

Resolves #49
This commit is contained in:
Lakhan Samani
2021-09-21 08:23:40 +05:30
committed by GitHub
parent 1ba53e2c49
commit b3a52c2466
7 changed files with 319 additions and 4 deletions

View File

@@ -17,6 +17,7 @@ type Manager interface {
UpdateUser(user User) (User, error)
GetUsers() ([]User, error)
GetUserByEmail(email string) (User, error)
GetUserByID(email string) (User, error)
UpdateVerificationTime(verifiedAt int64, id uint) error
AddVerification(verification VerificationRequest) (VerificationRequest, error)
GetVerificationByToken(token string) (VerificationRequest, error)

View File

@@ -2,6 +2,7 @@ package db
import (
"log"
"time"
"gorm.io/gorm/clause"
)
@@ -37,6 +38,7 @@ func (mgr *manager) SaveUser(user User) (User, error) {
// UpdateUser function to update user with ID conflict
func (mgr *manager) UpdateUser(user User) (User, error) {
user.UpdatedAt = time.Now().Unix()
result := mgr.db.Clauses(
clause.OnConflict{
UpdateAll: true,
@@ -72,6 +74,17 @@ func (mgr *manager) GetUserByEmail(email string) (User, error) {
return user, nil
}
func (mgr *manager) GetUserByID(id string) (User, error) {
var user User
result := mgr.db.Where("id = ?", id).First(&user)
if result.Error != nil {
return user, result.Error
}
return user, nil
}
func (mgr *manager) UpdateVerificationTime(verifiedAt int64, id uint) error {
user := &User{
ID: id,