Added laravel/passport, assign ftn addresses to nodes

This commit is contained in:
Deon George
2021-06-20 23:03:20 +10:00
parent 84df9ce811
commit 7cab4e288b
24 changed files with 1163 additions and 176 deletions

View File

@@ -2,12 +2,21 @@
namespace App\Http\Controllers;
use Illuminate\Support\Collection;
use Illuminate\Http\Request;
use App\Models\Domain;
use App\Models\{Address,Domain,Zone};
class DomainController extends Controller
{
public const NODE_ZC = 1<<1; // Zone
public const NODE_RC = 1<<2; // Region
public const NODE_NC = 1<<3; // Host
public const NODE_HC = 1<<4; // Hub
// http://ftsc.org/docs/frl-1002.001
public const NUMBER_MAX = 0x7fff;
public function __construct()
{
$this->middleware('auth');
@@ -40,6 +49,69 @@ class DomainController extends Controller
->with('o',$o);
}
/**
* Get all the hosts for a zone of a particular region (or not)
*
* @param Zone $o
* @param int $region
* @return Collection
*/
public function api_hosts(Zone $o,int $region): Collection
{
$oo = Address::where('role',self::NODE_NC)
->where('zone_id',$o->id)
->when($region,function($query,$region) { return $query->where('region_id',$region)->where('node_id','<>',0); })
->when((! $region),function($query) use ($region) { return $query->whereNull('region_id'); })
->where('point_id',0)
->with(['system'])
->get();
return $oo->map(function($item) {
return ['id'=>$item->host_id,'value'=>sprintf('%s %s',$item->ftn,$item->system->name)];
});
}
/**
* Find all the hubs for a host
*
* @param Zone $o
* @param int $host
* @return Collection
*/
public function api_hubs(Zone $o,int $host): Collection
{
$oo = Address::where('role',self::NODE_HC)
->where('zone_id',$o->id)
->when($host,function($query,$host) { return $query->where('host_id',$host)->where('node_id','<>',0); })
->with(['system'])
->get();
return $oo->map(function($item) {
return ['id'=>$item->host_id,'value'=>sprintf('%s %s',$item->ftn,$item->system->name)];
});
}
/**
* Get all the regions for a zone
*
* @param Zone $o
* @return Collection
*/
public function api_regions(Zone $o): Collection
{
$oo = Address::where('role',self::NODE_RC)
->where('zone_id',$o->id)
->where('node_id',0)
->where('point_id',0)
->orderBy('region_id')
->with(['system'])
->get();
return $oo->map(function($item) {
return ['id'=>$item->region_id,'value'=>sprintf('%s %s',$item->ftn,$item->system->location)];
});
}
public function home()
{
return view('domain.home');