adding optional filter for account listing

This commit is contained in:
Roland Osborne 2022-10-24 11:03:14 -07:00
parent 889e6b4cc7
commit 8340290fab

View File

@ -8,10 +8,20 @@ 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 {
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{}