Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test version early test event #30

Merged
merged 25 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions internal/cli/event.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package cli

import (
"log"

"github.com/rarimo/geo-points-svc/internal/config"
"github.com/rarimo/geo-points-svc/internal/service/event"
)

func eventStart(cfg config.Config, data int) {
err := event.Run(cfg, data)
if err != nil {
log.Fatalf("Error starting event: %v", err)
kish1n marked this conversation as resolved.
Show resolved Hide resolved
}
}
6 changes: 6 additions & 0 deletions internal/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ func Run(args []string) bool {
migrateCmd = app.Command("migrate", "migrate command")
migrateUpCmd = migrateCmd.Command("up", "migrate db up")
migrateDownCmd = migrateCmd.Command("down", "migrate db down")

event = app.Command("event", "claim event command")
eventCmd = event.Command("start", "claim event command")
data = eventCmd.Arg("data", "data after ...").Required().Int()
kish1n marked this conversation as resolved.
Show resolved Hide resolved
)

cmd, err := app.Parse(args[1:])
Expand All @@ -48,6 +52,8 @@ func Run(args []string) bool {
err = MigrateUp(cfg)
case migrateDownCmd.FullCommand():
err = MigrateDown(cfg)
case eventCmd.FullCommand():
eventStart(cfg, *data)
default:
log.Errorf("unknown command %s", cmd)
return false
Expand Down
2 changes: 2 additions & 0 deletions internal/data/balances.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ type BalancesQ interface {
FilterByInternalAID(aid string) BalancesQ
FilterByExternalAID(aid string) BalancesQ
FilterBySharedHash(hash string) BalancesQ
FilterByCreatedBefore(time int) BalancesQ
kish1n marked this conversation as resolved.
Show resolved Hide resolved
FilterVerified() BalancesQ
}

type WithoutPassportEventBalance struct {
Expand Down
1 change: 1 addition & 0 deletions internal/data/evtypes/models/extra.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const (
TypeInternalPassportScan = "internal_passport_scan"
TypeExternalPassportScan = "external_passport_scan"
TypePollParticipation = "poll_participation"
TypeEarlyTest = "early_test"
)

const (
Expand Down
8 changes: 8 additions & 0 deletions internal/data/pg/balances.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,18 @@ func (q *balances) FilterBySharedHash(hash string) data.BalancesQ {
return q.applyCondition(squirrel.Eq{"shared_hash": hash})
}

func (q *balances) FilterByCreatedBefore(data int) data.BalancesQ {
return q.applyCondition(squirrel.Lt{"created_at": data})
}

func (q *balances) applyCondition(cond squirrel.Sqlizer) data.BalancesQ {
q.selector = q.selector.Where(cond)
q.updater = q.updater.Where(cond)
q.rank = q.rank.Where(cond)
q.counter = q.counter.Where(cond)
return q
}

func (q *balances) FilterVerified() data.BalancesQ {
return q.applyCondition(squirrel.Gt{"verified": true})
kish1n marked this conversation as resolved.
Show resolved Hide resolved
}
55 changes: 55 additions & 0 deletions internal/service/event/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package event

import (
"fmt"

"github.com/rarimo/geo-points-svc/internal/config"
"github.com/rarimo/geo-points-svc/internal/data"
"github.com/rarimo/geo-points-svc/internal/data/evtypes/models"
"github.com/rarimo/geo-points-svc/internal/data/pg"
)

func Run(cfg config.Config, date int) error {
log := cfg.Log()
db := cfg.DB()

balances := pg.NewBalances(db)
events := pg.NewEvents(db)

users, err := balances.FilterByCreatedBefore(date).FilterVerified().Select()
kish1n marked this conversation as resolved.
Show resolved Hide resolved
filtEvents := events.FilterByType(models.TypeEarlyTest)

if err != nil {
log.WithError(err).Error("failed to filter by updated before")
return err
}

if users == nil {
log.Infof("no users found")
return nil
}
kish1n marked this conversation as resolved.
Show resolved Hide resolved

for _, user := range users {
userNull := user.Nullifier
eve, err := filtEvents.FilterByNullifier(userNull).Get()
kish1n marked this conversation as resolved.
Show resolved Hide resolved

if err != nil {
log.WithError(err).Error("failed to filter by nullifier")
return err
}
if eve != nil {
break
}

err = events.Insert(data.Event{
Nullifier: user.Nullifier,
Type: models.TypeEarlyTest,
Status: data.EventFulfilled,
})
if err != nil {
return fmt.Errorf("failed to insert `early_test` event: %w", err)
}
}

return nil
}
1 change: 0 additions & 1 deletion internal/service/workers/leveljustice/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,4 @@ func Run(cfg config.Config, sig chan struct{}) {
}

sig <- struct{}{}

}
Loading