draft
This commit is contained in:
30
backend/internal/repository/admin_user.go
Normal file
30
backend/internal/repository/admin_user.go
Normal file
@@ -0,0 +1,30 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user