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"
|
"github.com/google/uuid"
|
||||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/dal/sqlcgen"
|
"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/model"
|
||||||
|
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/pj_errors"
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Deps struct {
|
type Deps struct {
|
||||||
Queries *sqlcgen.Queries
|
Queries *sqlcgen.Queries
|
||||||
Pool *sql.DB
|
Pool *sql.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
type AccountRepository struct {
|
type AccountRepository struct {
|
||||||
queries *sqlcgen.Queries
|
queries *sqlcgen.Queries
|
||||||
pool *sql.DB
|
pool *sql.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAccountRepository(deps Deps) *AccountRepository {
|
func NewAccountRepository(deps Deps) *AccountRepository {
|
||||||
return &AccountRepository{
|
return &AccountRepository{
|
||||||
queries: deps.Queries,
|
queries: deps.Queries,
|
||||||
pool: deps.Pool,
|
pool: deps.Pool,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -315,3 +316,19 @@ func (r *AccountRepository) GetQidOwner(ctx context.Context, qId string) (string
|
|||||||
|
|
||||||
return userID, nil
|
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