1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
package repos
import "apjournal/internal/models"
type UserScoreRepo interface {
DBUserScoreCreate(req *models.UserScore) error
DBUserScoreGet(username string) (*models.UserScore, error)
DBUserScoreUpdate(req *models.UserScore) error
}
func (p *Provider) DBUserScoreCreate(req *models.UserScore) error {
_, err := p.db.NamedExec(`
INSERT INTO user_score(username, burn_time, score, password)
VALUES (:username, :burn_time, :score, :password);`, req)
return err
}
func (p *Provider) DBUserScoreGet(username string) (*models.UserScore, error) {
resp := models.UserScore{}
query := "SELECT * FROM user_score WHERE username=$1;"
if err := p.db.Get(&resp, query, username); err != nil {
return nil, err
}
return &resp, nil
}
func (p *Provider) DBUserScoreUpdate(req *models.UserScore) error {
stmt := `UPDATE user_score SET burn_time=$1, score=$2
WHERE username=$3;`
_, err := p.db.Exec(stmt, req.BurnTime, req.Score, req.Username)
return err
}
|