Skip to content
This repository has been archived by the owner on Sep 11, 2022. It is now read-only.

Commit

Permalink
ADding user to stats
Browse files Browse the repository at this point in the history
Signed-off-by: Dusan Malusev <[email protected]>
  • Loading branch information
Dusan Malusev committed Mar 13, 2022
1 parent 7a7f122 commit 0630fac
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
11 changes: 8 additions & 3 deletions backend/pkg/http/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,16 @@ func registerRoutes(c *container.Container, app *fiber.App) {

app.Get("/user-profile", authMiddleware, handlers.UserProfileMetrics(c.GetLedgerService()))
app.Post("/ledger", authMiddleware, handlers.InsertLedger(c.GetLedgerService(), c.GetBroadCaster()))
app.Post("/event/:eventId/participate", authMiddleware, events.InsertParticipent(c.GetParticipantService()))
app.Get("/ws/:eventId/collection", authMiddleware, middleware.WebSocket(), ws.LedgerHandler(c.GetBroadCaster(), c.GetDefaultLogger()))
app.Post("/event/:eventId/participate", authMiddleware, events.InsertParticipent(c.GetParticipantService()))

app.Get("/ws/:eventId/collection",
authMiddleware,
middleware.WebSocket(),
ws.LedgerHandler(c.GetBroadCaster(), c.GetDefaultLogger()),
)

app.Get("/events", authMiddleware, events.GetEventHandler(c.GetEventService(), c.GetDefaultLogger()))
app.Get("/event/:eventId/participate",authMiddleware, events.ParticipantHandler())
app.Get("/event/:eventId/participate", authMiddleware, events.ParticipantHandler())
app.Get("/event/:eventId/board", authMiddleware, handlers.EventBoard(c.GetLedgerService()))
app.Get("/exchange-rates", handlers.ExchangeRateHandler(c.GetExchangeRateService(), c.GetDefaultLogger()))
app.Get("/achievements", achievement.AchievementHandler(c.GetAchievementService(), c.GetDefaultLogger()))
Expand Down
22 changes: 12 additions & 10 deletions backend/pkg/services/ledger/ledger.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,20 @@ type (
}

UserMetrics struct {
User models.User `json:"user"`
TotalPoints uint64 `json:"total_points"`
TotalPointsByExchangeRate []TotalByExchange `json:"total_points_by_exchange_rate"`
Achievements []models.Achievement `json:"achievement"`
Events []models.Event `json:"events"`
}

EventBoard struct {
TotalPoints uint64 `json:"total_points"`
TotalPointsByExchangeRate []TotalByExchange `json:"total_points_by_exchange_rate"`
TotalPoints uint64 `json:"total_points"`
TotalPointsByExchangeRate []TotalByExchange `json:"total_points_by_exchange_rate"`
TotalPointsByExchangeRateAll []TotalByExchange `json:"total_points_by_exchange_rate_all"`
Event models.Event `json:"event"`
TopRankedUsers []models.User `json:"ranked_users"`
Damage uint64 `json:"damage"`
Event models.Event `json:"event"`
TopRankedUsers []models.User `json:"ranked_users"`
Damage uint64 `json:"damage"`
}
)

Expand All @@ -71,6 +72,7 @@ func (s *Service) CalculateUserMetrics(ctx context.Context, userId uint64) (*Use
Events: user.Events,
Achievements: user.Achievements,
TotalPointsByExchangeRate: make([]TotalByExchange, 0, 10),
User: user,
}

exchangeRates := make([]models.ExchangeRate, 0, 10)
Expand Down Expand Up @@ -201,12 +203,12 @@ func (s *Service) CalculateEventBoard(
).Scan(&countsDamage)

res := &EventBoard{
Event: event,
TopRankedUsers: topRankedUsers,
TotalPoints: goal.Points,
TotalPointsByExchangeRate: make([]TotalByExchange, 0, 10),
Event: event,
TopRankedUsers: topRankedUsers,
TotalPoints: goal.Points,
TotalPointsByExchangeRate: make([]TotalByExchange, 0, 10),
TotalPointsByExchangeRateAll: make([]TotalByExchange, 0, 10),
Damage: 0,
Damage: 0,
}

for _, count := range counts {
Expand Down

0 comments on commit 0630fac

Please sign in to comment.