Bookmark List : GWM
This commit is contained in:
parent
37cfe63420
commit
8a063a55f4
69
main.go
69
main.go
@ -878,6 +878,75 @@ func main() {
|
||||
|
||||
})
|
||||
|
||||
e.Router.GET("/api/getUserBookmark", func(c echo.Context) error {
|
||||
|
||||
language := c.QueryParam("language")
|
||||
user_id := c.QueryParam("user_id")
|
||||
|
||||
// Define the struct for holding the query results
|
||||
bookmarks := []struct {
|
||||
UserId string `db:"user_id" json:"user_id"`
|
||||
Dataset string `db:"dataset" json:"dataset"`
|
||||
}{}
|
||||
|
||||
// Execute the query
|
||||
err := app.DB().
|
||||
Select("user_id", "dataset").
|
||||
From("bookmark").
|
||||
Where(dbx.HashExp{"user_id": user_id}).
|
||||
All(&bookmarks)
|
||||
// return c.JSON(http.StatusOK, bookmarks)
|
||||
if err != nil {
|
||||
log.Printf("Failed to fetch bookmark data: %v", err)
|
||||
return c.JSON(http.StatusInternalServerError, map[string]string{"error": "Failed to fetch records"})
|
||||
}
|
||||
|
||||
// If no records are found
|
||||
if len(bookmarks) == 0 {
|
||||
return c.JSON(http.StatusNotFound, map[string]string{"error": "No records found for Bookmark"})
|
||||
}
|
||||
|
||||
// Final result structure
|
||||
result := []map[string]interface{}{}
|
||||
|
||||
// Loop through main topics and fetch sub-topic data for each
|
||||
for _, bookmark := range bookmarks {
|
||||
dataSets := struct {
|
||||
DataSet string `db:"data_set" json:"data_set"`
|
||||
DataSetTileHeading string `db:"data_set_tile_heading" json:"data_set_tile_heading"`
|
||||
ValueSource string `db:"value_source" json:"value_source"`
|
||||
Value string `db:"value" json:"value"`
|
||||
}{}
|
||||
|
||||
languageSpecificColumn := "data_set_tile_heading_" + language
|
||||
query := ` SELECT data_set,` + languageSpecificColumn + ` AS data_set_tile_heading,value_source,value FROM uae_numbers_screen WHERE data_set = {:bookmark} `
|
||||
err := app.DB().
|
||||
NewQuery(query).
|
||||
Bind(dbx.Params{
|
||||
"bookmark": bookmark.Dataset,
|
||||
}).
|
||||
One(&dataSets)
|
||||
log.Printf("query %s: %v", bookmark.Dataset, query)
|
||||
if err != nil {
|
||||
log.Printf("Failed to fetch data-set for sub topic %s: %v", bookmark.Dataset, err)
|
||||
continue
|
||||
}
|
||||
|
||||
// Add the main topic and its sub-topics to the result
|
||||
result = append(result, map[string]interface{}{
|
||||
"data_set": dataSets.DataSet,
|
||||
"data_set_tile_heading": dataSets.DataSetTileHeading,
|
||||
"value_source": dataSets.ValueSource,
|
||||
"value": dataSets.Value,
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
// Send the combined result as JSON
|
||||
return c.JSON(http.StatusOK, result)
|
||||
|
||||
})
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
|
||||
BIN
pb_data/data.db
BIN
pb_data/data.db
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
pb_data/logs.db
BIN
pb_data/logs.db
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user