add repo method for decrement quizManual
This commit is contained in:
parent
c75ba5ee69
commit
1a0489c429
5
pj_errors/pg_error.go
Normal file
5
pj_errors/pg_error.go
Normal file
@ -0,0 +1,5 @@
|
||||
package pj_errors
|
||||
|
||||
import "errors"
|
||||
|
||||
var ErrNotFound = errors.New("not found")
|
@ -7,23 +7,24 @@ import (
|
||||
"github.com/google/uuid"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/dal/sqlcgen"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/pj_errors"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type Deps struct {
|
||||
Queries *sqlcgen.Queries
|
||||
Pool *sql.DB
|
||||
Queries *sqlcgen.Queries
|
||||
Pool *sql.DB
|
||||
}
|
||||
|
||||
type AccountRepository struct {
|
||||
queries *sqlcgen.Queries
|
||||
pool *sql.DB
|
||||
queries *sqlcgen.Queries
|
||||
pool *sql.DB
|
||||
}
|
||||
|
||||
func NewAccountRepository(deps Deps) *AccountRepository {
|
||||
return &AccountRepository{
|
||||
queries: deps.Queries,
|
||||
pool: deps.Pool,
|
||||
queries: deps.Queries,
|
||||
pool: deps.Pool,
|
||||
}
|
||||
}
|
||||
|
||||
@ -315,3 +316,19 @@ func (r *AccountRepository) GetQidOwner(ctx context.Context, qId string) (string
|
||||
|
||||
return userID, nil
|
||||
}
|
||||
|
||||
func (r *AccountRepository) ManualDone(ctx context.Context, userID string) error {
|
||||
_, err := r.queries.DecrementManual(ctx, sqlcgen.DecrementManualParams{
|
||||
UserID: sql.NullString{String: userID, Valid: true},
|
||||
Privilegeid: sql.NullString{String: "quizManual", Valid: true},
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return pj_errors.ErrNotFound
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user