feat: live module and jenkins pipeline to harbor deploy
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package platformsetting
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
biz "kra/internal/biz/platformsetting"
|
||||
"kra/internal/data/ledger"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
const key = "diamond_rate_cents"
|
||||
|
||||
type Provider interface{ DB() *gorm.DB }
|
||||
type repo struct{ data Provider }
|
||||
|
||||
func NewRepo(data Provider) biz.Repo { return &repo{data: data} }
|
||||
func (r *repo) Get(ctx context.Context) (*biz.Setting, error) {
|
||||
var row ledger.SettingPO
|
||||
err := r.data.DB().WithContext(ctx).Where(&ledger.SettingPO{Key: key}).First(&row).Error
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return &biz.Setting{DiamondRateCents: 10}, nil
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
v, e := strconv.ParseInt(row.Value, 10, 64)
|
||||
if e != nil {
|
||||
v = 10
|
||||
}
|
||||
return &biz.Setting{DiamondRateCents: v}, nil
|
||||
}
|
||||
func (r *repo) Save(ctx context.Context, v *biz.Setting) error {
|
||||
row := ledger.SettingPO{Key: key, Value: strconv.FormatInt(v.DiamondRateCents, 10), UpdatedAt: time.Now()}
|
||||
return r.data.DB().WithContext(ctx).Clauses(clause.OnConflict{Columns: []clause.Column{{Name: "key"}}, DoUpdates: clause.AssignmentColumns([]string{"value", "updated_at"})}).Create(&row).Error
|
||||
}
|
||||
Reference in New Issue
Block a user