feat: broadcast

This commit is contained in:
Krispire Admin
2026-08-29 18:34:07 +05:30
parent 44120efdec
commit f65f552c87
9 changed files with 869 additions and 0 deletions
+25
View File
@@ -77,6 +77,7 @@ type Server struct {
feedbackH *handler.FeedbackHandler
statsH *handler.StatsHandler
adminH *handler.AdminHandler
broadcastH *handler.BroadcastHandler
// Auth state (nil when Postgres is unavailable — /auth and /users return 503)
authIssuer *auth.Issuer
@@ -343,6 +344,14 @@ func (s *Server) initAuth(cfg *config.Config, logger *zap.Logger) {
adminRepo := repository.NewAdminRepo(s.pg)
adminSvc := service.NewAdminService(adminRepo, statsRepo, notifSvc, feedbackSvc, userRepo, s.discipleRepo, mail, logger, cfg.FrontendURL)
s.adminH = handler.NewAdminHandler(adminSvc)
// Broadcasts — admin announcements shown once per user. No notification
// rows: the modal is the surface, and push plus the realtime nudge only
// tell clients to go and check for one.
broadcastSvc := service.NewBroadcastService(
repository.NewBroadcastRepo(s.pg), pushSender, pushRepo,
notifPrefsRepo, rtClient, r2, logger)
s.broadcastH = handler.NewBroadcastHandler(broadcastSvc)
}
// initShortener wires Postgres + Redis + the shorturl handler/workers.
@@ -912,6 +921,15 @@ func (s *Server) setupRouter() {
// Chat — inbox, threads, messages. Every route requires a session;
// membership is re-checked per request in the service, so a
// conversation id on its own grants nothing.
if s.broadcastH != nil {
// Announcements: fetch the one waiting, and dismiss it.
r.Route("/broadcasts", func(r chi.Router) {
r.Use(middleware.RequireAuth(s.authIssuer, s.userRepo))
r.Get("/pending", s.broadcastH.Pending)
r.Post("/{id}/seen", s.broadcastH.Seen)
})
}
if s.chatH != nil {
r.Route("/chat", func(r chi.Router) {
r.Use(middleware.RequireAuth(s.authIssuer, s.userRepo))
@@ -1133,6 +1151,13 @@ func (s *Server) setupRouter() {
// Direct-disciple linking: mark an account as one of Śrīla
// Prabhupāda's initiated disciples (or clear the mark).
r.Get("/disciples", s.adminH.ListDisciples)
// Announcements composed and published from the admin panel.
r.Get("/broadcasts", s.broadcastH.List)
r.Post("/broadcasts", s.broadcastH.Create)
r.Post("/broadcasts/banner-presign", s.broadcastH.PresignBanner)
r.Post("/broadcasts/{id}/publish", s.broadcastH.Publish)
r.Delete("/broadcasts/{id}", s.broadcastH.Delete)
r.Post("/users/{id}/disciple", s.adminH.LinkDisciple)
r.Delete("/users/{id}/disciple", s.adminH.UnlinkDisciple)
r.Get("/posts", s.adminH.ListPosts)