diff --git a/main.go b/main.go index 69f4359..d8acbbc 100644 --- a/main.go +++ b/main.go @@ -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() diff --git a/pb_data/data.db b/pb_data/data.db index 330e891..94b957e 100644 Binary files a/pb_data/data.db and b/pb_data/data.db differ diff --git a/pb_data/data.db-shm b/pb_data/data.db-shm deleted file mode 100644 index 66e0323..0000000 Binary files a/pb_data/data.db-shm and /dev/null differ diff --git a/pb_data/data.db-wal b/pb_data/data.db-wal deleted file mode 100644 index 4daf1fb..0000000 Binary files a/pb_data/data.db-wal and /dev/null differ diff --git a/pb_data/logs.db b/pb_data/logs.db index 038272a..a2df16a 100644 Binary files a/pb_data/logs.db and b/pb_data/logs.db differ diff --git a/pb_data/logs.db-shm b/pb_data/logs.db-shm deleted file mode 100644 index 4fb1e72..0000000 Binary files a/pb_data/logs.db-shm and /dev/null differ diff --git a/pb_data/logs.db-wal b/pb_data/logs.db-wal deleted file mode 100644 index 6121834..0000000 Binary files a/pb_data/logs.db-wal and /dev/null differ