Skip to content

Commit abee8da

Browse files
authored
feat(GAT-8586): admin update cohort discovery state in datasets (#1562)
1 parent 3c610e6 commit abee8da

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

app/Http/Controllers/Api/V2/DatasetController.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -916,4 +916,32 @@ public function getLinkages($datasetVersionId)
916916

917917
return $datasetLinkages;
918918
}
919+
920+
// no Swagger
921+
public function updateIsCohortDiscovery(GetDataset $request, int $id)
922+
{
923+
try {
924+
$input = $request->all();
925+
$isCohortDiscovery = isset($input['is_cohort_discovery']) ? $input['is_cohort_discovery'] : null;
926+
927+
if (is_null($isCohortDiscovery)) {
928+
throw new Exception('Payload is missing is_cohort_discovery');
929+
}
930+
931+
$dataset = Dataset::where('id', $id)->first();
932+
933+
if ($dataset->status !== Dataset::STATUS_ACTIVE) {
934+
throw new Exception('Dataset status is ' . strtoupper($dataset->status));
935+
}
936+
937+
$dataset->is_cohort_discovery = $isCohortDiscovery;
938+
$dataset->save();
939+
940+
return response()->json([
941+
'message' => Config::get('statuscodes.STATUS_OK.message'),
942+
], Config::get('statuscodes.STATUS_OK.code'));
943+
} catch (Exception $e) {
944+
throw new Exception($e->getMessage());
945+
}
946+
}
919947
}

config/routes_v2.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,20 @@
431431
'id', '[0-9]+'
432432
],
433433
],
434+
[
435+
'name' => 'datasets',
436+
'method' => 'put',
437+
'path' => '/datasets/{id}/cohort-discovery',
438+
'methodController' => 'DatasetController@updateIsCohortDiscovery',
439+
'namespaceController' => 'App\Http\Controllers\Api\V2',
440+
'middleware' => [
441+
'jwt.verify',
442+
'check.access:roles,hdruk.superadmin',
443+
],
444+
'constraint' => [
445+
'id', '[0-9]+'
446+
],
447+
],
434448

435449
// v2 teams/datasets
436450
[

0 commit comments

Comments
 (0)