49 lines
1.2 KiB
Go
49 lines
1.2 KiB
Go
package repository
|
|
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
type RecommendationRepository interface {
|
|
GetUserVirtualGameInteractions(ctx context.Context, userID string) ([]UserGameInteraction, error)
|
|
}
|
|
|
|
type recommendationRepo struct {
|
|
store *Store
|
|
}
|
|
|
|
func NewRecommendationRepository(store *Store) RecommendationRepository {
|
|
return &recommendationRepo{store: store}
|
|
}
|
|
|
|
func (r *recommendationRepo) GetUserVirtualGameInteractions(ctx context.Context, userID string) ([]UserGameInteraction, error) {
|
|
var interactions []UserGameInteraction
|
|
query := `SELECT game_id, interaction_type, timestamp FROM virtual_game_interactions WHERE user_id = $1 ORDER BY timestamp DESC LIMIT 100`
|
|
|
|
rows, err := r.store.conn.Query(ctx, query, userID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
|
|
for rows.Next() {
|
|
var u UserGameInteraction
|
|
if err := rows.Scan(&u.GameID, &u.InteractionType, &u.Timestamp); err != nil {
|
|
return nil, err
|
|
}
|
|
interactions = append(interactions, u)
|
|
}
|
|
|
|
if rows.Err() != nil {
|
|
return nil, rows.Err()
|
|
}
|
|
|
|
return interactions, nil
|
|
}
|
|
|
|
type UserGameInteraction struct {
|
|
GameID string
|
|
InteractionType string // e.g., "view", "bet", "like"
|
|
Timestamp string
|
|
}
|