@@ -33,18 +33,19 @@ func (r repo) Lock(ctx context.Context, n uint64) ([]model.VerificationEvent, er
33
33
}
34
34
35
35
func (r repo ) convertToVerificationEventModel (n uint64 , eventsData []struct {
36
- EventId uint64
37
- EventType model.EventType
38
- EventStatus model.EventStatus
39
- VerificationId uint64
40
- VerificationName string
36
+ EventId uint64 `db:"event_id"`
37
+ EventType model.EventType `db:"type"`
38
+ EventStatus model.EventStatus `db:"status"`
39
+ VerificationId uint64 `db:"id"`
40
+ VerificationName string `db:"name"`
41
41
}) []model.VerificationEvent {
42
42
43
43
events := make ([]model.VerificationEvent , 0 , n )
44
44
45
45
for _ , event := range eventsData {
46
46
events = append (events , model.VerificationEvent {
47
47
ID : event .EventId ,
48
+ VerificationID : event .VerificationId ,
48
49
Type : event .EventType ,
49
50
Status : event .EventStatus ,
50
51
Entity : & model.Verification {
@@ -57,33 +58,34 @@ func (r repo) convertToVerificationEventModel(n uint64, eventsData []struct {
57
58
}
58
59
59
60
func (r repo ) getEventsDataFromDB (ctx context.Context , err error , eventIds []uint64 ) ([]struct {
60
- EventId uint64
61
- EventType model.EventType
62
- EventStatus model.EventStatus
63
- VerificationId uint64
64
- VerificationName string
61
+ EventId uint64 `db:"event_id"`
62
+ EventType model.EventType `db:"type"`
63
+ EventStatus model.EventStatus `db:"status"`
64
+ VerificationId uint64 `db:"id"`
65
+ VerificationName string `db:"name"`
65
66
}, error ) {
66
67
67
- query , args , err := squirrel .Select ("verification_events.id " ,
68
- "verification_events.event_type " ,
69
- "verification_events.event_status " ,
68
+ query , args , err := squirrel .Select ("verification_events.event_id " ,
69
+ "verification_events.type " ,
70
+ "verification_events.status " ,
70
71
"verification.id" ,
71
72
"verification.name" ).
73
+ PlaceholderFormat (squirrel .Dollar ).
72
74
Join ("verification on verification.id = verification_events.verification_id" ).
73
75
From ("verification_events" ).
74
- Where (squirrel.Eq {"verification_events.id " : eventIds }).
76
+ Where (squirrel.Eq {"verification_events.event_id " : eventIds }).
75
77
ToSql ()
76
78
77
79
if err != nil {
78
80
return nil , err
79
81
}
80
82
81
83
var eventsData []struct {
82
- EventId uint64
83
- EventType model.EventType
84
- EventStatus model.EventStatus
85
- VerificationId uint64
86
- VerificationName string
84
+ EventId uint64 `db:"event_id"`
85
+ EventType model.EventType `db:"type"`
86
+ EventStatus model.EventStatus `db:"status"`
87
+ VerificationId uint64 `db:"id"`
88
+ VerificationName string `db:"name"`
87
89
}
88
90
89
91
err = r .db .SelectContext (ctx , & eventsData , query , args ... )
@@ -96,22 +98,34 @@ func (r repo) getEventsDataFromDB(ctx context.Context, err error, eventIds []uin
96
98
}
97
99
98
100
func (r repo ) getEventIdsFromDB (ctx context.Context , n uint64 ) ([]uint64 , error ) {
99
- query , args , err := squirrel .Update ("verification_events" ).
100
- Set ("event_status" , model .Processed ).
101
+ eventIds := make ([]uint64 , 0 , n )
102
+ query , args , err := squirrel .Select ("event_id" ).
103
+ From ("verification_events" ).
101
104
PlaceholderFormat (squirrel .Dollar ).
102
- Where (squirrel.Eq {"event_status " : model . Deferred }).
105
+ Where (squirrel.Eq {"status " : "DEFERRED" }).
103
106
Limit (n ).
104
- Suffix ("RETURNING id" ).
105
107
ToSql ()
106
108
107
109
if err != nil {
108
110
logger .ErrorKV (ctx , "repo.getEventIdsFromDB() get select query" , "err" , err )
109
111
return nil , err
110
112
}
111
113
112
- eventIds := make ([]uint64 , 0 , n )
113
114
err = r .db .SelectContext (ctx , & eventIds , query , args ... )
114
115
116
+ query , args , err = squirrel .Update ("verification_events" ).
117
+ Set ("status" , model .Processed ).
118
+ PlaceholderFormat (squirrel .Dollar ).
119
+ Where (squirrel.Eq {"event_id " : eventIds }).
120
+ ToSql ()
121
+
122
+ if err != nil {
123
+ logger .ErrorKV (ctx , "repo.getEventIdsFromDB() get select query" , "err" , err )
124
+ return nil , err
125
+ }
126
+
127
+ _ , err = r .db .ExecContext (ctx , query , args ... )
128
+
115
129
if err != nil {
116
130
logger .ErrorKV (ctx , "repo.getEventIdsFromDB() get result query" , "err" , err )
117
131
return nil , err
0 commit comments