Search accounts w/ username or nick

This commit is contained in:
2024-07-30 18:20:45 +08:00
parent 7c09138ef7
commit 57b4b314fe
4 changed files with 28 additions and 6 deletions

View File

@ -2,9 +2,10 @@ package services
import (
"fmt"
"gorm.io/gorm/clause"
"time"
"gorm.io/gorm/clause"
"github.com/rs/zerolog/log"
"github.com/spf13/viper"
"gorm.io/datatypes"
@ -65,6 +66,15 @@ func LookupAccount(probe string) (models.Account, error) {
return account, fmt.Errorf("account was not found")
}
func SearchAccount(probe string) ([]models.Account, error) {
probe = "%" + probe + "%"
var accounts []models.Account
if err := database.C.Where("name LIKE ? OR nick LIKE ?", probe).Find(&accounts).Error; err != nil {
return accounts, err
}
return accounts, nil
}
func CreateAccount(name, nick, email, password string) (models.Account, error) {
user := models.Account{
Name: name,