mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-14 12:30:49 +08:00
dbstructure add duration
This commit is contained in:
@@ -44,7 +44,7 @@ class ExamController extends Controller
|
||||
'name' => 'required|string',
|
||||
'indexes' => 'required|array|min:1',
|
||||
'status' => 'required|in:0,1',
|
||||
'duration' => 'numeric'
|
||||
'duration' => 'nullable|numeric'
|
||||
];
|
||||
$request->validate($rules);
|
||||
$result = $this->repository->store($request->all());
|
||||
@@ -78,6 +78,7 @@ class ExamController extends Controller
|
||||
'name' => 'required|string',
|
||||
'indexes' => 'required|array|min:1',
|
||||
'status' => 'required|in:0,1',
|
||||
'duration' => 'nullable|numeric'
|
||||
];
|
||||
$request->validate($rules);
|
||||
$result = $this->repository->update($request->all(), $id);
|
||||
|
||||
@@ -27,6 +27,7 @@ class ExamRepository extends BaseRepository
|
||||
public function store(array $params)
|
||||
{
|
||||
$this->checkIndexes($params);
|
||||
$this->checkBeginEnd($params);
|
||||
$valid = $this->listValid(null, Exam::DISCOVERED_YES);
|
||||
if ($valid->isNotEmpty() && $params['status'] == Exam::STATUS_ENABLED) {
|
||||
throw new NexusException("Enabled and discovered exam already exists.");
|
||||
@@ -38,6 +39,7 @@ class ExamRepository extends BaseRepository
|
||||
public function update(array $params, $id)
|
||||
{
|
||||
$this->checkIndexes($params);
|
||||
$this->checkBeginEnd($params);
|
||||
$valid = $this->listValid($id, Exam::DISCOVERED_YES);
|
||||
if ($valid->isNotEmpty() && $params['status'] == Exam::STATUS_ENABLED) {
|
||||
throw new NexusException("Enabled and discovered exam already exists.");
|
||||
@@ -70,6 +72,18 @@ class ExamRepository extends BaseRepository
|
||||
return true;
|
||||
}
|
||||
|
||||
private function checkBeginEnd(array $params)
|
||||
{
|
||||
if (!empty($params['begin']) && !empty($params['end']) && empty($params['duration'])) {
|
||||
return true;
|
||||
}
|
||||
if (empty($params['begin']) && empty($params['end']) && ctype_digit((string)$params['duration']) && $params['duration'] > 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
throw new \InvalidArgumentException("Require begin and end or only duration.");
|
||||
}
|
||||
|
||||
public function getDetail($id)
|
||||
{
|
||||
$exam = Exam::query()->findOrFail($id);
|
||||
|
||||
Reference in New Issue
Block a user