You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
993 B
Go

package model
import (
"context"
"git.noahlan.cn/northlan/ntools-go/gorm-zero/gormx"
"gorm.io/gorm"
)
var _ GiftModel = (*customGiftModel)(nil)
type (
// GiftModel is an interface to be customized, add more methods here,
// and implement the added methods in customGiftModel.
GiftModel interface {
giftModel
FindByPlatformGift(ctx context.Context, platform string, giftId string) (*Gift, error)
}
customGiftModel struct {
*defaultGiftModel
}
)
// NewGiftModel returns a model for the database table.
func NewGiftModel(conn *gorm.DB) GiftModel {
return &customGiftModel{
defaultGiftModel: newGiftModel(conn),
}
}
func (m *customGiftModel) FindByPlatformGift(ctx context.Context, platform string, giftId string) (*Gift, error) {
var resp Gift
db := m.DB.WithContext(ctx)
err := db.Model(&Gift{}).
Where("platform = ? AND gift_id = ?", platform, giftId).
Take(&resp).Error
err = gormx.WrapSelectErr(err)
if err != nil {
return nil, err
}
return &resp, nil
}