Skip to content

Commit

Permalink
chore: remove code comments as i dont read them and idk why i write them
Browse files Browse the repository at this point in the history
  • Loading branch information
Digital39999 committed Aug 13, 2024
1 parent d83790a commit 979fcbb
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions app/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type RequestData struct {
Name string `json:"name" binding:"required"`
UserId string `json:"userId" binding:"required"`
CreatedAt int64 `json:"createdAt" binding:"required"`
Type string `json:"type" binding:"required"` // New field for analytics type
Type string `json:"type" binding:"required"`
}

func analyticsHandler(c *gin.Context) {
Expand All @@ -32,13 +32,12 @@ func analyticsHandler(c *gin.Context) {
redisKey = "analyticsEngine"
}

analyticsType := c.Query("type") // Get analytics type from query parameters
analyticsType := c.Query("type")
if analyticsType == "" {
c.JSON(http.StatusBadRequest, gin.H{"status": http.StatusBadRequest, "error": "Analytics type is required."})
return
}

// Generate the Redis key for the specified type
redisKeyWithType := redisKey + "-" + analyticsType

now := time.Now()
Expand Down Expand Up @@ -81,19 +80,16 @@ func analyticsHandler(c *gin.Context) {
weekStart := createdAt.AddDate(0, 0, -int(createdAt.Weekday())).Format("2006-01-02")
monthKey := createdAt.Format("2006-01")

// Daily aggregation
if reqData.CreatedAt >= dailyCutoff {
usages[reqData.Name]["daily"][dateKey]++
global["daily"][dateKey]++
}

// Weekly aggregation: Group by week start date
if reqData.CreatedAt >= weeklyCutoff {
usages[reqData.Name]["weekly"][weekStart]++
global["weekly"][weekStart]++
}

// Monthly aggregation
if reqData.CreatedAt >= monthlyCutoff {
usages[reqData.Name]["monthly"][monthKey]++
global["monthly"][monthKey]++
Expand All @@ -120,7 +116,6 @@ func eventHandler(c *gin.Context) {
redisKey = "analyticsEngine"
}

// Generate the Redis key for the specified type
redisKeyWithType := redisKey + "-" + reqData.Type

value, err := json.Marshal(reqData)
Expand Down

0 comments on commit 979fcbb

Please sign in to comment.