31 lines
676 B
Go
31 lines
676 B
Go
package repository
|
|
|
|
import (
|
|
"context"
|
|
|
|
"gorm.io/gorm"
|
|
|
|
"pay-bridge/internal/model"
|
|
)
|
|
|
|
type AdminUserRepository struct {
|
|
db *gorm.DB
|
|
}
|
|
|
|
func NewAdminUserRepository(db *gorm.DB) *AdminUserRepository {
|
|
return &AdminUserRepository{db: db}
|
|
}
|
|
|
|
func (r *AdminUserRepository) GetByUsername(ctx context.Context, username string) (*model.AdminUser, error) {
|
|
var user model.AdminUser
|
|
err := r.db.WithContext(ctx).Where("username = ? AND status = 1", username).First(&user).Error
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &user, nil
|
|
}
|
|
|
|
func (r *AdminUserRepository) Create(ctx context.Context, user *model.AdminUser) error {
|
|
return r.db.WithContext(ctx).Create(user).Error
|
|
}
|