package infrastructure import ( "context" "mengstack/internal/modules/auth/domain" "gorm.io/gorm" ) type userRepo struct { db *gorm.DB } func NewUserRepository(db *gorm.DB) domain.UserRepository { return &userRepo{db: db} } func (r *userRepo) Create(ctx context.Context, user *domain.User) error { return r.db.WithContext(ctx).Create(user).Error } func (r *userRepo) FindByID(ctx context.Context, tenantID string, id uint) (*domain.User, error) { var user domain.User err := r.db.WithContext(ctx).Where("id = ? AND tenant_id = ?", id, tenantID).First(&user).Error if err != nil { return nil, err } return &user, nil } func (r *userRepo) FindByEmail(ctx context.Context, tenantID string, email string) (*domain.User, error) { var user domain.User err := r.db.WithContext(ctx).Where("email = ? AND tenant_id = ?", email, tenantID).First(&user).Error if err != nil { return nil, err } return &user, nil } func (r *userRepo) FindByUsername(ctx context.Context, tenantID string, username string) (*domain.User, error) { var user domain.User err := r.db.WithContext(ctx).Where("username = ? AND tenant_id = ?", username, tenantID).First(&user).Error if err != nil { return nil, err } return &user, nil } func (r *userRepo) Update(ctx context.Context, user *domain.User) error { return r.db.WithContext(ctx).Save(user).Error }