Skip to content

Commit 7f51e5d

Browse files
committed
API tweaks to return more relevant information on server listing
1 parent 32c21ba commit 7f51e5d

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

app/Http/Controllers/API/ServerController.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,10 @@ public function view(Request $request, $id)
117117
}
118118

119119
// Requested Daemon Stats
120-
$server = $query->first();
120+
$server = $query->with(
121+
'allocations',
122+
'pack'
123+
)->first();
121124
if ($request->input('daemon') === 'true') {
122125
$node = Models\Node::findOrFail($server->node);
123126
$client = Models\Node::guzzleRequest($node->id);

app/Models/Server.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,4 +208,54 @@ public static function getGuzzleHeaders($uuid)
208208

209209
return [];
210210
}
211+
212+
/**
213+
* Gets all allocations associated with this server.
214+
*
215+
* @return \Illuminate\Database\Eloquent\Relations\HasMany
216+
*/
217+
public function allocations()
218+
{
219+
return $this->hasMany(Allocation::class, 'assigned_to');
220+
}
221+
222+
/**
223+
* Gets information for the pack associated with this server.
224+
*
225+
* @return \Illuminate\Database\Eloquent\Relations\HasOne
226+
*/
227+
public function pack()
228+
{
229+
return $this->hasOne(ServicePack::class, 'id', 'pack');
230+
}
231+
232+
/**
233+
* Gets information for the service associated with this server.
234+
*
235+
* @return \Illuminate\Database\Eloquent\Relations\HasOne
236+
*/
237+
public function service()
238+
{
239+
return $this->hasOne(Service::class, 'id', 'service');
240+
}
241+
242+
/**
243+
* Gets information for the service option associated with this server.
244+
*
245+
* @return \Illuminate\Database\Eloquent\Relations\HasOne
246+
*/
247+
public function option()
248+
{
249+
return $this->hasOne(ServiceOptions::class, 'id', 'option');
250+
}
251+
252+
/**
253+
* Gets information for the service variables associated with this server.
254+
*
255+
* @return \Illuminate\Database\Eloquent\Relations\HasMany
256+
*/
257+
public function variables()
258+
{
259+
return $this->hasMany(ServerVariables::class);
260+
}
211261
}

0 commit comments

Comments
 (0)