fix: hide blocked user content

This commit is contained in:
Krispire Admin
2026-06-13 00:46:51 +05:30
parent 0b24ab4b45
commit 1edee92865
5 changed files with 119 additions and 22 deletions
+25 -10
View File
@@ -94,21 +94,31 @@ type userSearchItem struct {
// the query carries an "@" prefix.
func (h *UserHandler) Search(w http.ResponseWriter, r *http.Request) {
q := strings.TrimSpace(r.URL.Query().Get("q"))
if q == "" {
response.JSON(w, http.StatusOK, map[string]any{
"query": "",
"results": []userSearchItem{},
})
return
}
limit := 20
if v := r.URL.Query().Get("limit"); v != "" {
if n, err := strconv.Atoi(v); err == nil && n > 0 && n <= 50 {
limit = n
}
}
if q == "" {
response.JSON(w, http.StatusOK, map[string]any{
"query": "",
"results": []userSearchItem{},
"total": 0,
"page": 1,
"limit": limit,
"total_pages": 0,
})
return
}
page := 1
if v := r.URL.Query().Get("page"); v != "" {
if n, err := strconv.Atoi(v); err == nil && n > 1 {
page = n
}
}
users, err := h.svc.Search(r.Context(), q, limit)
users, total, err := h.svc.Search(r.Context(), q, limit, (page-1)*limit)
if err != nil {
response.Error(w, http.StatusInternalServerError, "search failed")
return
@@ -122,9 +132,14 @@ func (h *UserHandler) Search(w http.ResponseWriter, r *http.Request) {
AvatarURL: u.AvatarURL,
})
}
totalPages := (total + limit - 1) / limit
response.JSON(w, http.StatusOK, map[string]any{
"query": q,
"results": items,
"query": q,
"results": items,
"total": total,
"page": page,
"limit": limit,
"total_pages": totalPages,
})
}