Skip to content

Commit

Permalink
Get user mandatory for distribution fields functionality (#248)
Browse files Browse the repository at this point in the history
  • Loading branch information
ice-myles authored Dec 3, 2024
1 parent c96c88a commit bc026f7
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 12 deletions.
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ require (
github.com/google/uuid v1.6.0
github.com/hashicorp/go-multierror v1.1.1
github.com/ice-blockchain/go-tarantool-client v0.0.0-20230327200757-4fc71fa3f7bb
github.com/ice-blockchain/santa v1.186.0
github.com/ice-blockchain/santa v1.188.0
github.com/ice-blockchain/wintr v1.154.0
github.com/imroc/req/v3 v3.48.0
github.com/ip2location/ip2location-go/v9 v9.7.0
github.com/ip2location/ip2location-go/v9 v9.7.1
github.com/jackc/pgx/v5 v5.7.1
github.com/pkg/errors v0.9.1
github.com/prometheus/common v0.60.1
Expand All @@ -29,7 +29,7 @@ require (
)

require (
cel.dev/expr v0.18.0 // indirect
cel.dev/expr v0.19.0 // indirect
cloud.google.com/go v0.116.0 // indirect
cloud.google.com/go/auth v0.11.0 // indirect
cloud.google.com/go/auth/oauth2adapt v0.2.6 // indirect
Expand Down Expand Up @@ -98,7 +98,7 @@ require (
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/golang/snappy v0.0.5-0.20231225225746-43d5d4cd4e0e // indirect
github.com/google/pprof v0.0.0-20241128161848-dc51965c6481 // indirect
github.com/google/pprof v0.0.0-20241203143554-1e3fdc7de467 // indirect
github.com/google/s2a-go v0.1.8 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.4 // indirect
github.com/googleapis/gax-go/v2 v2.14.0 // indirect
Expand Down
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cel.dev/expr v0.18.0 h1:CJ6drgk+Hf96lkLikr4rFf19WrU0BOWEihyZnI2TAzo=
cel.dev/expr v0.18.0/go.mod h1:MrpN08Q+lEBs+bGYdLxxHkZoUSsCp0nSKTs0nTymJgw=
cel.dev/expr v0.19.0 h1:lXuo+nDhpyJSpWxpPVi5cPUwzKb+dsdOiw6IreM5yt0=
cel.dev/expr v0.19.0/go.mod h1:MrpN08Q+lEBs+bGYdLxxHkZoUSsCp0nSKTs0nTymJgw=
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
cloud.google.com/go v0.116.0 h1:B3fRrSDkLRt5qSHWe40ERJvhvnQwdZiHu0bJOpldweE=
cloud.google.com/go v0.116.0/go.mod h1:cEPSRWPzZEswwdr9BxE6ChEn01dWlTaF05LiC2Xs70U=
Expand Down Expand Up @@ -225,8 +225,8 @@ github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeN
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/martian/v3 v3.3.3 h1:DIhPTQrbPkgs2yJYdXU/eNACCG5DVQjySNRNlflZ9Fc=
github.com/google/martian/v3 v3.3.3/go.mod h1:iEPrYcgCF7jA9OtScMFQyAlZZ4YXTKEtJ1E6RWzmBA0=
github.com/google/pprof v0.0.0-20241128161848-dc51965c6481 h1:yudKIrXagAOl99WQzrP1gbz5HLB9UjhcOFnPzdd6Qec=
github.com/google/pprof v0.0.0-20241128161848-dc51965c6481/go.mod h1:vavhavw2zAxS5dIdcRluK6cSGGPlZynqzFM8NdvU144=
github.com/google/pprof v0.0.0-20241203143554-1e3fdc7de467 h1:keEZFtbLJugfE0qHn+Ge1JCE71spzkchQobDf3mzS/4=
github.com/google/pprof v0.0.0-20241203143554-1e3fdc7de467/go.mod h1:vavhavw2zAxS5dIdcRluK6cSGGPlZynqzFM8NdvU144=
github.com/google/s2a-go v0.1.8 h1:zZDs9gcbt9ZPLV0ndSyQk6Kacx2g/X+SKYovpnz3SMM=
github.com/google/s2a-go v0.1.8/go.mod h1:6iNWHTpQ+nfNRN5E00MSdfDwVesa8hhS32PhPO8deJA=
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
Expand All @@ -247,14 +247,14 @@ github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/ice-blockchain/go-tarantool-client v0.0.0-20230327200757-4fc71fa3f7bb h1:8TnFP3mc7O+tc44kv2e0/TpZKnEVUaKH+UstwfBwRkk=
github.com/ice-blockchain/go-tarantool-client v0.0.0-20230327200757-4fc71fa3f7bb/go.mod h1:ZsQU7i3mxhgBBu43Oev7WPFbIjP4TniN/b1UPNGbrq8=
github.com/ice-blockchain/santa v1.186.0 h1:fRHp1jGvHq/o3Kgq/Ki6BCU3dvSYDPx0GPRz25KuE1A=
github.com/ice-blockchain/santa v1.186.0/go.mod h1:2oL7RhcSxMazLADQPo/1WPii1qQiA+xpOYnRvCqglB0=
github.com/ice-blockchain/santa v1.188.0 h1:1pGFnmaBJmDUmGtjVAm59eYsKxoVAaIM+alsMFJw1lk=
github.com/ice-blockchain/santa v1.188.0/go.mod h1:wB3deWO3L11JLdIMsdhIvUcL6AW2WYZtJ0Hs+Ufp3YQ=
github.com/ice-blockchain/wintr v1.154.0 h1:yZSQtAEwGHTSmJ5pXjX0tpui1TNnG615QfpBkhY99a4=
github.com/ice-blockchain/wintr v1.154.0/go.mod h1:DoUn66XJGzPzfCZTsHyMjfgj2aVLGvjqDSuKj2pa3KE=
github.com/imroc/req/v3 v3.48.0 h1:IYuMGetuwLzOOTzDCquDqs912WNwpsPK0TBXWPIvoqg=
github.com/imroc/req/v3 v3.48.0/go.mod h1:weam9gmyb00QnOtu6HXSnk44dNFkIUQb5QdMx13FeUU=
github.com/ip2location/ip2location-go/v9 v9.7.0 h1:ipwl67HOWcrw+6GOChkEXcreRQR37NabqBd2ayYa4Q0=
github.com/ip2location/ip2location-go/v9 v9.7.0/go.mod h1:MPLnsKxwQlvd2lBNcQCsLoyzJLDBFizuO67wXXdzoyI=
github.com/ip2location/ip2location-go/v9 v9.7.1 h1:eXu/DqS13QE0h1Yrc9oji+6/anLD9KDf6Ulf5GdIQs8=
github.com/ip2location/ip2location-go/v9 v9.7.1/go.mod h1:MPLnsKxwQlvd2lBNcQCsLoyzJLDBFizuO67wXXdzoyI=
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
Expand Down
8 changes: 8 additions & 0 deletions users/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,13 @@ type (
devicemetadata.DeviceLocation
ReferralType ReferralType `json:"referralType,omitempty" example:"T1" enums:"CONTACTS,T0,T1,T2"`
}
MandatoryForDistributionFieldsProfile struct {
DistributionScenariosVerified *bool `json:"distributionScenariosVerified,omitempty" example:"true" swaggerignore:"true" db:"distribution_scenarios_verified"`
SensitiveUserInformation
ID UserID `json:"id,omitempty" example:"did:ethr:0x4B73C58370AEfcEf86A6021afCDe5673511376B2" db:"id"`
TelegramUserID string `json:"telegramUserId,omitempty" example:"1234" db:"telegram_user_id"`
TelegramBotID string `json:"telegramBotId,omitempty" example:"5678" db:"telegram_bot_id"`
}
UserProfile struct {
*User
T1ReferralCount *uint64 `json:"t1ReferralCount,omitempty" example:"100"`
Expand Down Expand Up @@ -197,6 +204,7 @@ type (
GetUserByUsername(ctx context.Context, username string) (*UserProfile, error)
GetUserByPhoneNumber(ctx context.Context, phoneNumber string) (*User, error)
GetUserByID(ctx context.Context, userID string) (*UserProfile, error)
GetMandatoryForDistributionUserFieldsByIDList(ctx context.Context, userIDList []string) (result map[string]*MandatoryForDistributionFieldsProfile, err error)

GetTopCountries(ctx context.Context, keyword string, limit, offset uint64) ([]*CountryStatistics, error)
GetUserGrowth(ctx context.Context, days uint64, tz *stdlibtime.Location) (*UserGrowthStatistics, error)
Expand Down
31 changes: 31 additions & 0 deletions users/users_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,3 +275,34 @@ func (r *repository) GetUsers(ctx context.Context, keyword string, limit, offset

return result, errors.Wrapf(err, "failed to select for users by %#v", params...)
}

func (r *repository) GetMandatoryForDistributionUserFieldsByIDList(ctx context.Context, userIDList []string) (
result map[string]*MandatoryForDistributionFieldsProfile, err error,
) {
if ctx.Err() != nil {
return nil, errors.Wrap(ctx.Err(), "get users by id list failed because context failed")
}
if len(userIDList) == 0 {
return map[string]*MandatoryForDistributionFieldsProfile{}, nil
}
sql := `SELECT
id,
phone_number,
email,
telegram_user_id,
telegram_bot_id,
distribution_scenarios_verified
FROM users
WHERE id = ANY($1)`
params := []any{userIDList}
res, err := storage.Select[MandatoryForDistributionFieldsProfile](ctx, r.db, sql, params...)
if err != nil {
return nil, errors.Wrapf(err, "failed to select mandatody for distribution fields list for users by %#v", params...)
}
result = make(map[string]*MandatoryForDistributionFieldsProfile, len(res))
for _, profile := range res {
result[profile.ID] = profile
}

return result, nil
}

0 comments on commit bc026f7

Please sign in to comment.