GWM : notification api

This commit is contained in:
Gowtham M 2025-03-07 11:40:39 +05:30
parent e714c7d542
commit 0781524644
2 changed files with 42 additions and 14 deletions

56
main.go
View File

@ -568,29 +568,57 @@ func main() {
return c.JSON(http.StatusBadRequest, map[string]string{"error": "language is required"})
}
notification := []struct {
Id string `db:"category" json:"id"`
Category string `db:"category" json:"category"`
Title string `db:"title" json:"title"`
Message string `db:"message" json:"message"`
}{}
categoryColumn := "category_" + language
titleColumn := "title_" + language
messageColumn := "message_" + language
query := ` SELECT id` + categoryColumn + ` AS category,` + titleColumn + ` AS title,` + messageColumn + ` AS message FROM notification `
err := app.DB().NewQuery(query).All(&notification)
id := c.QueryParam("id")
if id != "" {
// Define a single notification struct, not a slice
var notification struct {
Id string `db:"id" json:"id"`
Category string `db:"category" json:"category"`
Title string `db:"title" json:"title"`
Message string `db:"message" json:"message"`
Created string `db:"created" json:"created"`
}
query := `SELECT id, created, ` + categoryColumn + ` AS category, ` + titleColumn + ` AS title, ` + messageColumn + ` AS message FROM notification WHERE id = {:id}`
err := app.DB().NewQuery(query).Bind(dbx.Params{"id": id}).One(&notification)
if err != nil {
log.Printf("notification not found: %v", err)
return c.JSON(http.StatusNotFound, map[string]string{"error": "notification not found"})
}
return c.JSON(http.StatusOK, map[string]interface{}{
"message": "Success",
"data": notification,
})
}
// Fetch all notifications if no ID is provided
var notifications []struct {
Id string `db:"id" json:"id"`
Category string `db:"category" json:"category"`
Title string `db:"title" json:"title"`
Message string `db:"message" json:"message"`
Created string `db:"created" json:"created"`
}
query := `SELECT id, created, ` + categoryColumn + ` AS category, ` + titleColumn + ` AS title, ` + messageColumn + ` AS message FROM notification`
err := app.DB().NewQuery(query).All(&notifications)
if err != nil {
log.Printf("notification not found: %v", err)
return c.JSON(http.StatusNotFound, map[string]string{"error": "notification not found"})
log.Printf("notifications not found: %v", err)
return c.JSON(http.StatusNotFound, map[string]string{"error": "notifications not found"})
}
return c.JSON(http.StatusOK, map[string]interface{}{
"message": "Success",
"data": notification,
"data": notifications,
})
})
e.Router.GET("/api/pushNotification", func(c echo.Context) error {
@ -812,7 +840,7 @@ func main() {
}
var cardResults []map[string]string
if record.GetString("is_chart") == "false" { // card data calculation
if record.GetString("is_chart") == "false" { // card data calculations
// Extract `card_type` JSON from `record.Get("card_type")`
requestData := record.Get("card_type_json")

Binary file not shown.