Language changes in all 3 api : GWM
This commit is contained in:
parent
b6d8c51394
commit
f7f87ef47d
100
main.go
100
main.go
@ -405,6 +405,8 @@ func main() {
|
|||||||
e.Router.GET("/api/getDataSet", func(c echo.Context) error {
|
e.Router.GET("/api/getDataSet", func(c echo.Context) error {
|
||||||
|
|
||||||
dataset := c.QueryParam("dataset")
|
dataset := c.QueryParam("dataset")
|
||||||
|
language := c.QueryParam("language")
|
||||||
|
langKey := "value_" + language
|
||||||
if dataset == "" {
|
if dataset == "" {
|
||||||
return c.JSON(http.StatusBadRequest, map[string]string{"error": "dataset is required"})
|
return c.JSON(http.StatusBadRequest, map[string]string{"error": "dataset is required"})
|
||||||
}
|
}
|
||||||
@ -474,9 +476,10 @@ func main() {
|
|||||||
chartData = filterDynamicChartData(chartData, keyToFilter, valueToExclude)
|
chartData = filterDynamicChartData(chartData, keyToFilter, valueToExclude)
|
||||||
}
|
}
|
||||||
|
|
||||||
langKey := "value_en"
|
|
||||||
cRes := utils.ProcessChartData(chartData, languageSourceConverted, langKey)
|
cRes := utils.ProcessChartData(chartData, languageSourceConverted, langKey)
|
||||||
|
|
||||||
|
chartHeadingKey := "chart_heading_" + language
|
||||||
|
tabHeadingKey := "tab_heading_" + language
|
||||||
// Prepare the structure with URL and its response
|
// Prepare the structure with URL and its response
|
||||||
recordResult := map[string]interface{}{
|
recordResult := map[string]interface{}{
|
||||||
"url": apiURL,
|
"url": apiURL,
|
||||||
@ -488,7 +491,8 @@ func main() {
|
|||||||
"chart_type": record.GetString("chart_type"),
|
"chart_type": record.GetString("chart_type"),
|
||||||
"response": cRes,
|
"response": cRes,
|
||||||
"group_by": record.GetString("group_by"),
|
"group_by": record.GetString("group_by"),
|
||||||
"chart_heading": record.GetString("chart_heading"),
|
"chart_heading": record.GetString(chartHeadingKey),
|
||||||
|
"tab_heading": record.GetString(tabHeadingKey),
|
||||||
"unset_value": record.Get("unset_value"),
|
"unset_value": record.Get("unset_value"),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -496,6 +500,7 @@ func main() {
|
|||||||
aggregatedResponse = append(aggregatedResponse, recordResult)
|
aggregatedResponse = append(aggregatedResponse, recordResult)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
//--------------------
|
||||||
|
|
||||||
// get all filter based on kpi
|
// get all filter based on kpi
|
||||||
var dataSetKpis []struct {
|
var dataSetKpis []struct {
|
||||||
@ -513,7 +518,7 @@ func main() {
|
|||||||
filterData, err := fetchfilterJSON(kpi)
|
filterData, err := fetchfilterJSON(kpi)
|
||||||
|
|
||||||
// Translate filter data using the desired dataset and language key
|
// Translate filter data using the desired dataset and language key
|
||||||
fRes, err := TranslateFilters(app, dataset, filterData, "value_en")
|
fRes, err := TranslateFilters(app, dataset, filterData, langKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Error translating filters: %v", err)
|
log.Fatalf("Error translating filters: %v", err)
|
||||||
}
|
}
|
||||||
@ -521,12 +526,10 @@ func main() {
|
|||||||
aggregatedFilterResponse[kpi] = fRes
|
aggregatedFilterResponse[kpi] = fRes
|
||||||
|
|
||||||
}
|
}
|
||||||
|
//--------------------
|
||||||
temp, err := fetchfilterJSON(dataset)
|
|
||||||
|
|
||||||
// Create the response structure
|
// Create the response structure
|
||||||
response := map[string]interface{}{
|
response := map[string]interface{}{
|
||||||
"filter_data": temp,
|
|
||||||
"new_filter_data": aggregatedFilterResponse,
|
"new_filter_data": aggregatedFilterResponse,
|
||||||
"data": aggregatedResponse,
|
"data": aggregatedResponse,
|
||||||
}
|
}
|
||||||
@ -540,18 +543,21 @@ func main() {
|
|||||||
|
|
||||||
e.Router.GET("/api/getHomePageData", func(c echo.Context) error {
|
e.Router.GET("/api/getHomePageData", func(c echo.Context) error {
|
||||||
|
|
||||||
|
language := c.QueryParam("language")
|
||||||
|
|
||||||
// Define the struct for holding the query results
|
// Define the struct for holding the query results
|
||||||
mainTopics := []struct {
|
mainTopics := []struct {
|
||||||
MainTopic string `db:"main_topic" json:"main_topic"`
|
MainTopicEn string `db:"main_topic_en" json:"main_topic_en"`
|
||||||
|
MainTopicAr string `db:"main_topic_ar" json:"main_topic_ar"`
|
||||||
MainTopicListOrder string `db:"main_topic_list_order" json:"main_topic_list_order"`
|
MainTopicListOrder string `db:"main_topic_list_order" json:"main_topic_list_order"`
|
||||||
ColorPattern string `db:"color_pattern" json:"color_pattern"`
|
ColorPattern string `db:"color_pattern" json:"color_pattern"`
|
||||||
}{}
|
}{}
|
||||||
|
|
||||||
// Execute the query
|
// Execute the query
|
||||||
err := app.DB().
|
err := app.DB().
|
||||||
Select("main_topic", "main_topic_list_order", "color_pattern").
|
Select("main_topic_en", "main_topic_ar", "main_topic_list_order", "color_pattern").
|
||||||
From("home_screen").
|
From("home_screen").
|
||||||
GroupBy("main_topic", "color_pattern").
|
GroupBy("main_topic_en", "main_topic_ar", "color_pattern").
|
||||||
OrderBy("main_topic_list_order ASC").
|
OrderBy("main_topic_list_order ASC").
|
||||||
All(&mainTopics)
|
All(&mainTopics)
|
||||||
|
|
||||||
@ -579,10 +585,12 @@ func main() {
|
|||||||
DataSetListOrder string `db:"data_set_list_order" json:"data_set_list_order"`
|
DataSetListOrder string `db:"data_set_list_order" json:"data_set_list_order"`
|
||||||
}{}
|
}{}
|
||||||
|
|
||||||
|
languageSpecificColumn := "data_set_tile_heading_" + language
|
||||||
|
query := ` SELECT data_set,` + languageSpecificColumn + ` AS data_set_tile_heading,value_source,value, data_set_list_order FROM home_screen WHERE main_topic_en = {:topic}`
|
||||||
err := app.DB().
|
err := app.DB().
|
||||||
NewQuery("SELECT data_set, data_set_tile_heading, value_source, value, data_set_list_order FROM home_screen WHERE main_topic={:topic} ").
|
NewQuery(query).
|
||||||
Bind(dbx.Params{
|
Bind(dbx.Params{
|
||||||
"topic": mainTopic.MainTopic,
|
"topic": mainTopic.MainTopicEn,
|
||||||
}).
|
}).
|
||||||
All(&dataSets)
|
All(&dataSets)
|
||||||
|
|
||||||
@ -591,9 +599,16 @@ func main() {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var MainTopic string
|
||||||
|
if language == "en" {
|
||||||
|
MainTopic = mainTopic.MainTopicEn
|
||||||
|
} else {
|
||||||
|
MainTopic = mainTopic.MainTopicAr
|
||||||
|
}
|
||||||
|
|
||||||
// Add the main topic and its sub-topics to the result
|
// Add the main topic and its sub-topics to the result
|
||||||
result = append(result, map[string]interface{}{
|
result = append(result, map[string]interface{}{
|
||||||
"main_topic": mainTopic.MainTopic,
|
"main_topic": MainTopic,
|
||||||
"main_topic_list_order": mainTopic.MainTopicListOrder,
|
"main_topic_list_order": mainTopic.MainTopicListOrder,
|
||||||
"color_pattern": mainTopic.ColorPattern,
|
"color_pattern": mainTopic.ColorPattern,
|
||||||
"tile_data": dataSets,
|
"tile_data": dataSets,
|
||||||
@ -607,18 +622,21 @@ func main() {
|
|||||||
|
|
||||||
e.Router.GET("/api/getUAENumbersData", func(c echo.Context) error {
|
e.Router.GET("/api/getUAENumbersData", func(c echo.Context) error {
|
||||||
|
|
||||||
|
language := c.QueryParam("language")
|
||||||
|
|
||||||
// Define the struct for holding the query results
|
// Define the struct for holding the query results
|
||||||
mainTopics := []struct {
|
mainTopics := []struct {
|
||||||
MainTopic string `db:"main_topic" json:"main_topic"`
|
MainTopicEn string `db:"main_topic_en" json:"main_topic_en"`
|
||||||
|
MainTopicAr string `db:"main_topic_ar" json:"main_topic_ar"`
|
||||||
MainTopicListOrder string `db:"main_topic_list_order" json:"main_topic_list_order"`
|
MainTopicListOrder string `db:"main_topic_list_order" json:"main_topic_list_order"`
|
||||||
ColorPattern string `db:"color_pattern" json:"color_pattern"`
|
ColorPattern string `db:"color_pattern" json:"color_pattern"`
|
||||||
}{}
|
}{}
|
||||||
|
|
||||||
// Execute the query
|
// Execute the query
|
||||||
err := app.DB().
|
err := app.DB().
|
||||||
Select("main_topic", "main_topic_list_order", "color_pattern").
|
Select("main_topic_en", "main_topic_ar", "main_topic_list_order", "color_pattern").
|
||||||
From("uae_numbers_screen").
|
From("uae_numbers_screen").
|
||||||
GroupBy("main_topic", "color_pattern").
|
GroupBy("main_topic_en", "main_topic_ar", "color_pattern").
|
||||||
OrderBy("main_topic_list_order ASC").
|
OrderBy("main_topic_list_order ASC").
|
||||||
All(&mainTopics)
|
All(&mainTopics)
|
||||||
|
|
||||||
@ -637,22 +655,24 @@ func main() {
|
|||||||
|
|
||||||
// Loop through main topics and fetch sub-topic data for each
|
// Loop through main topics and fetch sub-topic data for each
|
||||||
for _, mainTopic := range mainTopics {
|
for _, mainTopic := range mainTopics {
|
||||||
|
|
||||||
subTopics := []struct {
|
subTopics := []struct {
|
||||||
SubTopic string `db:"sub_topic" json:"sub_topic"`
|
SubTopicEn string `db:"sub_topic_en" json:"sub_topic_en"`
|
||||||
|
SubTopicAr string `db:"sub_topic_ar" json:"sub_topic_ar"`
|
||||||
SubTopicListOrder string `db:"sub_topic_list_order" json:"sub_topic_list_order"`
|
SubTopicListOrder string `db:"sub_topic_list_order" json:"sub_topic_list_order"`
|
||||||
}{}
|
}{}
|
||||||
|
|
||||||
// Query to get sub-topics for the current main topic
|
// Query to get sub-topics for the current main topic
|
||||||
err := app.DB().
|
err := app.DB().
|
||||||
Select("sub_topic", "sub_topic_list_order").
|
Select("sub_topic_en", "sub_topic_ar", "sub_topic_list_order").
|
||||||
From("uae_numbers_screen").
|
From("uae_numbers_screen").
|
||||||
Where(dbx.HashExp{"main_topic": mainTopic.MainTopic}).
|
Where(dbx.HashExp{"main_topic_en": mainTopic.MainTopicEn}).
|
||||||
GroupBy("sub_topic").
|
GroupBy("sub_topic_en", "sub_topic_ar").
|
||||||
OrderBy("sub_topic_list_order ASC").
|
OrderBy("sub_topic_list_order ASC").
|
||||||
All(&subTopics)
|
All(&subTopics)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Failed to fetch sub-topics for main topic %s: %v", mainTopic.MainTopic, err)
|
log.Printf("Failed to fetch sub-topics for main topic %s: %v", mainTopic.MainTopicEn, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -668,29 +688,53 @@ func main() {
|
|||||||
DataSetListOrder string `db:"data_set_list_order" json:"data_set_list_order"`
|
DataSetListOrder string `db:"data_set_list_order" json:"data_set_list_order"`
|
||||||
}{}
|
}{}
|
||||||
|
|
||||||
// Query to get data-set for the current sub topic
|
languageSpecificColumn := "data_set_tile_heading_" + language
|
||||||
|
query := ` SELECT data_set,` + languageSpecificColumn + ` AS data_set_tile_heading,value_source,value, data_set_list_order FROM uae_numbers_screen WHERE sub_topic_en = {:topic}`
|
||||||
err := app.DB().
|
err := app.DB().
|
||||||
Select("data_set", "data_set_tile_heading", "value_source", "value", "data_set_list_order").
|
NewQuery(query).
|
||||||
From("uae_numbers_screen").
|
Bind(dbx.Params{
|
||||||
Where(dbx.HashExp{"sub_topic": subTopic.SubTopic}).
|
"topic": subTopic.SubTopicEn,
|
||||||
OrderBy("data_set_list_order ASC").
|
}).
|
||||||
All(&dataSets)
|
All(&dataSets)
|
||||||
|
|
||||||
|
// languageSpecificColumn := "data_set_tile_heading_" + language
|
||||||
|
// // Query to get data-set for the current sub topic
|
||||||
|
// err := app.DB().
|
||||||
|
// Select("data_set", languageSpecificColumn, "value_source", "value", "data_set_list_order").
|
||||||
|
// From("uae_numbers_screen").
|
||||||
|
// Where(dbx.HashExp{"sub_topic_en": subTopic.SubTopicEn}).
|
||||||
|
// OrderBy("data_set_list_order ASC").
|
||||||
|
// All(&dataSets)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Failed to fetch data-set for sub topic %s: %v", subTopic.SubTopic, err)
|
log.Printf("Failed to fetch data-set for sub topic %s: %v", subTopic.SubTopicEn, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var SubTopic string
|
||||||
|
if language == "en" {
|
||||||
|
SubTopic = subTopic.SubTopicEn
|
||||||
|
} else {
|
||||||
|
SubTopic = subTopic.SubTopicAr
|
||||||
|
}
|
||||||
|
|
||||||
result2 = append(result2, map[string]interface{}{
|
result2 = append(result2, map[string]interface{}{
|
||||||
"sub_topic": subTopic.SubTopic,
|
"sub_topic": SubTopic,
|
||||||
"sub_topic_list_order": subTopic.SubTopicListOrder,
|
"sub_topic_list_order": subTopic.SubTopicListOrder,
|
||||||
"tile_data": dataSets,
|
"tile_data": dataSets,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var MainTopic string
|
||||||
|
if language == "en" {
|
||||||
|
MainTopic = mainTopic.MainTopicEn
|
||||||
|
} else {
|
||||||
|
MainTopic = mainTopic.MainTopicAr
|
||||||
|
}
|
||||||
|
|
||||||
// Add the main topic and its sub-topics to the result
|
// Add the main topic and its sub-topics to the result
|
||||||
result = append(result, map[string]interface{}{
|
result = append(result, map[string]interface{}{
|
||||||
"main_topic": mainTopic.MainTopic,
|
"main_topic": MainTopic,
|
||||||
"main_topic_list_order": mainTopic.MainTopicListOrder,
|
"main_topic_list_order": mainTopic.MainTopicListOrder,
|
||||||
"color_pattern": mainTopic.ColorPattern,
|
"color_pattern": mainTopic.ColorPattern,
|
||||||
"sub_topics": result2,
|
"sub_topics": result2,
|
||||||
|
|||||||
BIN
pb_data/data.db
BIN
pb_data/data.db
Binary file not shown.
BIN
pb_data/logs.db
BIN
pb_data/logs.db
Binary file not shown.
Loading…
Reference in New Issue
Block a user