Files
admin-panel/internal/handlers/newsletter.go
coderabbitai[bot] 2adb7e3605 📝 Add docstrings to feat/go-rewrite
Docstrings generation was requested by @blakeridgway.

* https://github.com/RideAware/admin-panel/pull/1#issuecomment-3528008426

The following files were modified:

* `cmd/admin-panel/main.go`
* `internal/config/config.go`
* `internal/database/database.go`
* `internal/email/email.go`
* `internal/handlers/auth.go`
* `internal/handlers/newsletter.go`
* `internal/handlers/subscribers.go`
* `internal/middleware/auth.go`
2025-11-13 14:11:06 +00:00

33 lines
997 B
Go

package handlers
import (
"net/http"
"github.com/rideaware/admin-panel/internal/email"
"github.com/gin-gonic/gin"
)
// SendUpdateGet renders the update form page using the "send_update.html" template and responds with HTTP 200 OK.
func SendUpdateGet(c *gin.Context) {
c.HTML(http.StatusOK, "send_update.html", gin.H{})
}
// SendUpdatePost handles POST requests to submit a newsletter update.
// It reads "subject" and "body" from the form, calls email.SendUpdate(subject, body),
// and renders the "send_update.html" template with gin.H{"error": message} when sending fails
// or gin.H{"success": message} when sending succeeds, returning HTTP 200 in both cases.
func SendUpdatePost(c *gin.Context) {
subject := c.PostForm("subject")
body := c.PostForm("body")
message, err := email.SendUpdate(subject, body)
if err != nil {
c.HTML(http.StatusOK, "send_update.html",
gin.H{"error": message})
return
}
c.HTML(http.StatusOK, "send_update.html",
gin.H{"success": message})
}