Skip to content

Commit

Permalink
first test version
Browse files Browse the repository at this point in the history
  • Loading branch information
kish1n committed Aug 6, 2024
1 parent 1d0b4c9 commit 4796ccb
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 1 deletion.
14 changes: 14 additions & 0 deletions internal/cli/event.go
Original file line number Diff line number Diff line change
@@ -1 +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)
}
}
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()
)

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
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})
}
54 changes: 54 additions & 0 deletions internal/service/event/main.go
Original file line number Diff line number Diff line change
@@ -1 +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()
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
}

for _, user := range users {
userNull := user.Nullifier
eve, err := filtEvents.FilterByNullifier(userNull).Get()

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{}{}

}

0 comments on commit 4796ccb

Please sign in to comment.