feat: mid

This commit is contained in:
Rogee
2024-12-06 18:47:48 +08:00
parent 869625d70a
commit e15d8d9bb2
3 changed files with 29 additions and 10 deletions

View File

@@ -194,3 +194,17 @@ func (svc *Service) CreateTenantUser(ctx context.Context, userID, tenantID int64
}
return nil
}
// GetTenantIDBySlug
func (svc *Service) GetTenantIDBySlug(ctx context.Context, slug string) (int64, error) {
log := svc.log.WithField("method", "GetTenantIDBySlug")
stmt := table.Tenants.SELECT(table.Tenants.ID).WHERE(table.Tenants.Slug.EQ(String(slug)))
log.Debug(stmt.DebugSql())
var id int64
if err := stmt.QueryContext(ctx, db.FromContext(ctx, svc.db), &id); err != nil {
return 0, errors.Wrap(err, "failed to query tenant id by slug")
}
return id, nil
}