databag/net/server/internal/api_getAccountListing.go

43 lines
1.3 KiB
Go
Raw Normal View History

2022-03-09 07:05:04 +00:00
package databag
import (
2022-07-22 19:28:14 +00:00
"databag/internal/store"
"net/http"
2022-03-09 07:05:04 +00:00
)
2022-07-25 19:19:24 +00:00
//GetAccountListing retrieves profile list of publicly accessible accounts
2022-03-09 07:05:04 +00:00
func GetAccountListing(w http.ResponseWriter, r *http.Request) {
filter := r.FormValue("filter")
2022-07-22 19:28:14 +00:00
var accounts []store.Account
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
}
}
2022-03-09 07:05:04 +00:00
2022-07-22 19:28:14 +00:00
profiles := []CardProfile{}
for _, account := range accounts {
profiles = append(profiles, CardProfile{
GUID: account.GUID,
Handle: account.Username,
Name: account.AccountDetail.Name,
Description: account.AccountDetail.Description,
Location: account.AccountDetail.Location,
ImageSet: account.AccountDetail.Image != "",
Version: APPVersion,
Node: getStrConfigValue(CNFDomain, ""),
})
}
2022-03-09 07:05:04 +00:00
2022-07-22 19:28:14 +00:00
WriteResponse(w, &profiles)
2022-03-09 07:05:04 +00:00
}