From 5863c5ec74d2033bb62a21f3adbdb8fae2418c1b Mon Sep 17 00:00:00 2001 From: Pavel Date: Thu, 25 Apr 2024 20:44:32 +0300 Subject: [PATCH] update protobuf --- docs/proto/promo.proto | 11 +++++++++-- internal/repository/promocode_stats.go | 10 ++-------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/docs/proto/promo.proto b/docs/proto/promo.proto index 052aca2..296fc65 100644 --- a/docs/proto/promo.proto +++ b/docs/proto/promo.proto @@ -4,18 +4,25 @@ package codeword; option go_package = "./codeword_rpc"; +import "google/protobuf/empty.proto"; + message Time { int64 from = 1; int64 to = 2; } service PromoCodeService { - rpc GetAllPromoActivations(Time) returns (PromoActivationResp); + rpc GetAllPromoActivations(google.protobuf.Empty) returns (PromoActivationResp); } message PromoActivationResp { + message UserTime { + string UserID = 1; + int64 Time = 2; + } + message Activations { - repeated string values = 1; + repeated UserTime values = 1; } map response = 1; } diff --git a/internal/repository/promocode_stats.go b/internal/repository/promocode_stats.go index ca0ae14..2d96c3d 100644 --- a/internal/repository/promocode_stats.go +++ b/internal/repository/promocode_stats.go @@ -93,19 +93,12 @@ func (r *StatsRepository) GetAllPromoActivations(ctx context.Context, req *codew { "$unwind": "$usageArray.v", }, - { - "$match": bson.M{ - "usageArray.v.time": bson.M{ - "$gte": req.From, - "$lte": req.To, - }, - }, - }, { "$group": bson.M{ "_id": "$_id", "users": bson.M{"$push": bson.M{ "UserID": "$usageArray.v.userID", + "Time": "$usageArray.v.time", }}, }, }, @@ -122,6 +115,7 @@ func (r *StatsRepository) GetAllPromoActivations(ctx context.Context, req *codew ID string `bson:"_id"` Users []struct { UserID string `bson:"UserID"` + Time int64 } `bson:"users"` } err := cursor.Decode(&data)