mirror of
https://github.com/balzack/databag.git
synced 2025-02-11 19:19:16 +00:00
adding optional filter for account listing
This commit is contained in:
parent
889e6b4cc7
commit
8340290fab
@ -8,11 +8,21 @@ import (
|
||||
//GetAccountListing retrieves profile list of publicly accessible accounts
|
||||
func GetAccountListing(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
filter := r.FormValue("filter")
|
||||
var accounts []store.Account
|
||||
if err := store.DB.Preload("AccountDetail").Where("searchable = ? AND disabled = ?", true, false).Find(&accounts).Error; err != nil {
|
||||
ErrResponse(w, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
if filter == "" {
|
||||
if err := store.DB.Order("id desc").Limit(16).Preload("AccountDetail").Where("searchable = ? AND disabled = ?", true, false).Find(&accounts).Error; err != nil {
|
||||
ErrResponse(w, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
username := "%" + filter + "%"
|
||||
PrintMsg(username);
|
||||
if err := store.DB.Order("id desc").Limit(16).Preload("AccountDetail").Where("username LIKE ? AND searchable = ? AND disabled = ?", username, true, false).Find(&accounts).Error; err != nil {
|
||||
ErrResponse(w, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
profiles := []CardProfile{}
|
||||
for _, account := range accounts {
|
||||
|
Loading…
Reference in New Issue
Block a user