feat: disciple link
This commit is contained in:
@@ -9,10 +9,33 @@ import (
|
||||
|
||||
type DiscipleHandler struct {
|
||||
repo *repository.DiscipleRepo
|
||||
// users (Postgres) resolves which disciples have a platform account
|
||||
// linked by an admin. Separate store from the disciple records
|
||||
// themselves, hence the second dependency.
|
||||
users *repository.UserRepo
|
||||
}
|
||||
|
||||
func NewDiscipleHandler(repo *repository.DiscipleRepo) *DiscipleHandler {
|
||||
return &DiscipleHandler{repo: repo}
|
||||
func NewDiscipleHandler(repo *repository.DiscipleRepo, users *repository.UserRepo) *DiscipleHandler {
|
||||
return &DiscipleHandler{repo: repo, users: users}
|
||||
}
|
||||
|
||||
// Linked — GET /disciples/linked — every disciple that has a platform account,
|
||||
// as {disciple_id, handle, name, avatar_url}. Public and unpaged: only Śrīla
|
||||
// Prabhupāda's own disciples are ever linked, so the set is tiny and the
|
||||
// /disciples browser fetches it once to highlight the matching cards.
|
||||
func (h *DiscipleHandler) Linked(w http.ResponseWriter, r *http.Request) {
|
||||
if h.users == nil {
|
||||
// Degraded boot without Postgres — an empty set just means "no
|
||||
// highlights", which is a fine reading experience.
|
||||
response.JSON(w, http.StatusOK, []repository.DiscipleLink{})
|
||||
return
|
||||
}
|
||||
links, err := h.users.ListDiscipleLinks(r.Context())
|
||||
if err != nil {
|
||||
response.Error(w, http.StatusInternalServerError, "failed to fetch linked disciples")
|
||||
return
|
||||
}
|
||||
response.JSON(w, http.StatusOK, links)
|
||||
}
|
||||
|
||||
func (h *DiscipleHandler) List(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
Reference in New Issue
Block a user