submissions: fix operations CountSince #99
pkg
@ -3,6 +3,8 @@ package datastore
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
"time"
|
||||||
|
|
||||||
"git.itzana.me/strafesnet/maps-service/pkg/model"
|
"git.itzana.me/strafesnet/maps-service/pkg/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -45,7 +47,7 @@ type Operations interface {
|
|||||||
Create(ctx context.Context, smap model.Operation) (model.Operation, error)
|
Create(ctx context.Context, smap model.Operation) (model.Operation, error)
|
||||||
Update(ctx context.Context, id int32, values OptionalMap) error
|
Update(ctx context.Context, id int32, values OptionalMap) error
|
||||||
Delete(ctx context.Context, id int32) error
|
Delete(ctx context.Context, id int32) error
|
||||||
CountSince(ctx context.Context, owner int64, since int64) (int64, error)
|
CountSince(ctx context.Context, owner int64, since time.Time) (int64, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Submissions interface {
|
type Submissions interface {
|
||||||
|
@ -3,6 +3,7 @@ package gormstore
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
"time"
|
||||||
|
|
||||||
"git.itzana.me/strafesnet/maps-service/pkg/datastore"
|
"git.itzana.me/strafesnet/maps-service/pkg/datastore"
|
||||||
"git.itzana.me/strafesnet/maps-service/pkg/model"
|
"git.itzana.me/strafesnet/maps-service/pkg/model"
|
||||||
@ -54,9 +55,9 @@ func (env *Operations) Delete(ctx context.Context, id int32) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (env *Operations) CountSince(ctx context.Context, owner int64, since int64) (int64, error) {
|
func (env *Operations) CountSince(ctx context.Context, owner int64, since time.Time) (int64, error) {
|
||||||
var count int64
|
var count int64
|
||||||
if err := env.db.Where("owner = ? AND created_at > ?",owner,since).Count(&count).Error; err != nil {
|
if err := env.db.Model(&model.Operation{}).Where("owner = ? AND created_at > ?",owner,since).Count(&count).Error; err != nil {
|
||||||
return count, err
|
return count, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,7 +84,7 @@ func (svc *Service) CreateMapfix(ctx context.Context, request *api.MapfixTrigger
|
|||||||
{
|
{
|
||||||
count, err := svc.DB.Operations().CountSince(ctx,
|
count, err := svc.DB.Operations().CountSince(ctx,
|
||||||
int64(userId),
|
int64(userId),
|
||||||
time.Now().Add(-CreateMapfixRecencyWindow).Unix(),
|
time.Now().Add(-CreateMapfixRecencyWindow),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -75,7 +75,7 @@ func (svc *Service) CreateSubmission(ctx context.Context, request *api.Submissio
|
|||||||
{
|
{
|
||||||
count, err := svc.DB.Operations().CountSince(ctx,
|
count, err := svc.DB.Operations().CountSince(ctx,
|
||||||
int64(userId),
|
int64(userId),
|
||||||
time.Now().Add(-CreateSubmissionRecencyWindow).Unix(),
|
time.Now().Add(-CreateSubmissionRecencyWindow),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
Loading…
x
Reference in New Issue
Block a user