Login count : GWM

This commit is contained in:
Gowtham M 2025-02-04 17:25:23 +05:30
parent 8339ef1ca2
commit 65850e763d
7 changed files with 40 additions and 3 deletions

43
main.go
View File

@ -282,9 +282,6 @@ func fetchfilterJSON(kpi string) ([]FilterGroup, error) {
return nil, err
}
// Debug Log Exclusion Filters
log.Printf("Raw Exclusion Filters JSON: %s", dataSetFilter.ExclusionFiltersJSON)
// Parse exclusion filters JSON if it's not empty
var exclusionFilters []utils.FilterGroup
if dataSetFilter.ExclusionFiltersJSON != "" {
@ -448,6 +445,46 @@ func main() {
app.OnBeforeServe().Add(func(e *core.ServeEvent) error {
e.Router.GET("/api/login_success", func(c echo.Context) error {
userID := c.QueryParam("id")
if userID == "" {
return c.JSON(http.StatusBadRequest, map[string]string{"error": "User ID is required"})
}
// Find user by ID
record, err := app.Dao().FindRecordById("users", userID)
if err != nil {
log.Printf("User not found: %v", err)
return c.JSON(http.StatusNotFound, map[string]string{"error": "User not found"})
}
// Get current login count and convert it properly
var loginCount int
if count, ok := record.Get("login_count").(float64); ok {
loginCount = int(count) // Convert float64 to int
} else {
loginCount = 0 // Default if not set
}
// Increment login count
loginCount++
record.Set("login_count", loginCount)
// Save the updated record
if err := app.Dao().SaveRecord(record); err != nil {
log.Printf("Failed to update login count: %v", err)
return c.JSON(http.StatusInternalServerError, map[string]string{"error": "Failed to update login count"})
}
log.Printf("User %s login count updated to %d", userID, loginCount)
return c.JSON(http.StatusOK, map[string]interface{}{
"message": "Success",
"login_count": loginCount,
})
})
e.Router.GET("/api/custom/apicalltest", func(c echo.Context) error {
// Get the database instance
db := app.Dao().DB()

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.