GWM : notification api
This commit is contained in:
parent
e714c7d542
commit
0781524644
56
main.go
56
main.go
@ -568,29 +568,57 @@ func main() {
|
|||||||
return c.JSON(http.StatusBadRequest, map[string]string{"error": "language is required"})
|
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
|
categoryColumn := "category_" + language
|
||||||
titleColumn := "title_" + language
|
titleColumn := "title_" + language
|
||||||
messageColumn := "message_" + language
|
messageColumn := "message_" + language
|
||||||
query := ` SELECT id` + categoryColumn + ` AS category,` + titleColumn + ` AS title,` + messageColumn + ` AS message FROM notification `
|
|
||||||
err := app.DB().NewQuery(query).All(¬ification)
|
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(¬ification)
|
||||||
|
|
||||||
|
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(¬ifications)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("notification not found: %v", err)
|
log.Printf("notifications not found: %v", err)
|
||||||
return c.JSON(http.StatusNotFound, map[string]string{"error": "notification not found"})
|
return c.JSON(http.StatusNotFound, map[string]string{"error": "notifications not found"})
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.JSON(http.StatusOK, map[string]interface{}{
|
return c.JSON(http.StatusOK, map[string]interface{}{
|
||||||
"message": "Success",
|
"message": "Success",
|
||||||
"data": notification,
|
"data": notifications,
|
||||||
})
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
e.Router.GET("/api/pushNotification", func(c echo.Context) error {
|
e.Router.GET("/api/pushNotification", func(c echo.Context) error {
|
||||||
@ -812,7 +840,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var cardResults []map[string]string
|
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")`
|
// Extract `card_type` JSON from `record.Get("card_type")`
|
||||||
requestData := record.Get("card_type_json")
|
requestData := record.Get("card_type_json")
|
||||||
|
|||||||
BIN
pb_data/logs.db
BIN
pb_data/logs.db
Binary file not shown.
Loading…
Reference in New Issue
Block a user