Commit a1cceec3 authored by Maik Messerschmidt's avatar Maik Messerschmidt
Browse files

Replace concept of listed inputs with named groups.

parent 816c4aeb
......@@ -14,8 +14,8 @@ class InputController extends Controller {
*
* @return \Illuminate\Http\Response
*/
public function next() {
$input = Input::where('listed', true)
public function byGroup(String $group) {
$input = Input::where('group', $group)
->where('uses', '<', DB::raw('max_uses')) // Eloquent escapes the 3rd value.
->orWhere('max_uses', null)
->orderBy('uses')
......@@ -32,7 +32,7 @@ class InputController extends Controller {
* @param int $id
* @return \Illuminate\Http\Response
*/
public function get(Input $input) {
public function byId(Input $input) {
if ($input->max_uses !== null && $input->uses >= $input->max_uses)
return response('', 410);
else
......
......@@ -21,7 +21,7 @@ class Input extends Model {
'increments',
'uses',
'max_uses',
'listed',
'group',
'data',
];
......
......@@ -36,9 +36,10 @@ class CreateInputsTable extends Migration
->unsigned()
->comment("How often this input can be used. Use NULL for inifinite often.");
$table
->boolean('listed')
->default(true)
->comment("Whether this input should be available by /next or only by uuid.");
->string('group')
->unique()
->nullable()
->comment("The group this input belongs to.");
$table
->text("data")
->comment("The actual input data.");
......
......@@ -41,17 +41,14 @@
</div>
<div class="form-group">
{{ Form::label('listed', 'Should this entry be listed?', ['class' => 'control-label' ]) }}
{{ Form::select('listed', [true => 'listed', false => 'unlisted'], old('listed'), ['min' => 0, 'class' => 'form-control']) }}
<small id="max_uses-help" class="form-text text-muted">
Decide, whether this entry should be listed.
<ul>
<li>A 'listed' entry can be requested by the client without knowledge of the unique id by simply asking the server for "some input".</li>
<li>An 'unlisted' entry can only be requested by knowing the unique id.</li>
</ul>
Note: This doesn't change, whether this entry is visible in the admin interface.
{{ Form::label('group', 'Optional group name', ['class' => 'control-label' ]) }}
{{ Form::text('group', old('group'), ['class' => 'form-control']) }}
<small id="group-help" class="form-text text-muted">
This makes this input available by the given group name.
Useful, if you want to make multiple different inputs available via
the same URL.
</small>
@error('listed')
@error('group')
<div class="text-danger">{{ $message }}</div>
@enderror
</div>
......
......@@ -6,7 +6,7 @@
<tr>
<th scope="col">uid</th>
<th scope="col">uploaded on</th>
<th scope="col">listed</th>
<th scope="col">group</th>
<th scope="col">uses</th>
<th scope="col">max uses</th>
<th scope="col">use count increments</th>
......@@ -18,7 +18,7 @@
<tr>
<td>{{ $input->id }}</td>
<td>{{ $input->created_at }}</td>
<td>{{ $input->listed ? "yes" : "no" }}</td>
<td>{{ $input->group ?? "" }}</td>
<td>{{ $input->uses }}</td>
<td>{{ $input->max_uses ?? '∞'}}</td>
<td>{{ $input->increments }}</td>
......
......@@ -18,6 +18,6 @@ Route::middleware(['check-token:' . config('experiment.admin-token')])->group(fu
});
// input api route
Route::get('/inputs/next', 'Api\InputController@next')->name('api.inputs.next');
Route::get('/inputs/get/{input}', 'Api\InputController@get')->name('api.inputs.get');
Route::get('/inputs/by-group/{group}', 'Api\InputController@byGroup')->name('api.inputs.by-group');
Route::get('/inputs/by-id/{input}', 'Api\InputController@byId')->name('api.inputs.by-id');
Route::post('/inputs/used/{input}', 'Api\InputController@used')->name('api.inputs.used');
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment