From 296d0f904289180b1d4534758248f2a4f856ea7e Mon Sep 17 00:00:00 2001 From: gkourie Date: Fri, 20 Dec 2024 17:04:11 +0100 Subject: [PATCH] Implement annotation-store rules directly in StoreImageAnnotation --- app/Http/Requests/StoreImageAnnotation.php | 10 ++-- ...StoreImageAnnotationLabelFeatureVector.php | 51 ------------------- 2 files changed, 7 insertions(+), 54 deletions(-) delete mode 100644 app/Http/Requests/StoreImageAnnotationLabelFeatureVector.php diff --git a/app/Http/Requests/StoreImageAnnotation.php b/app/Http/Requests/StoreImageAnnotation.php index 666737ed4..d2434d330 100644 --- a/app/Http/Requests/StoreImageAnnotation.php +++ b/app/Http/Requests/StoreImageAnnotation.php @@ -4,8 +4,9 @@ use Biigle\Image; use Biigle\Shape; +use Illuminate\Foundation\Http\FormRequest; -class StoreImageAnnotation extends StoreImageAnnotationLabelFeatureVector +class StoreImageAnnotation extends FormRequest { /** * The image on which the annotation should be created. @@ -33,10 +34,13 @@ public function authorize() */ public function rules() { - return array_merge(parent::rules(), [ + return [ + 'label_id' => 'required_without:feature_vector|integer|exists:labels,id', + 'feature_vector' => 'required_without:label_id|array|size:384', + 'confidence' => 'required|numeric|between:0,1', 'shape_id' => 'required|integer|exists:shapes,id', 'points' => 'required|array', - ]); + ]; } /** diff --git a/app/Http/Requests/StoreImageAnnotationLabelFeatureVector.php b/app/Http/Requests/StoreImageAnnotationLabelFeatureVector.php deleted file mode 100644 index 9cef59ff5..000000000 --- a/app/Http/Requests/StoreImageAnnotationLabelFeatureVector.php +++ /dev/null @@ -1,51 +0,0 @@ -annotation = ImageAnnotation::findOrFail($this->route('id')); - $this->label = Label::findOrFail($this->input('label_id')); - - return $this->user()->can('attach-label', [$this->annotation, $this->label]); - } - - /** - * Get the validation rules that apply to the request. - * - * @return array - */ - public function rules() - { - return [ - 'label_id' => 'required_without:feature_vector|integer|exists:labels,id', - 'feature_vector' => 'required_without:label_id|array|size:384', - 'confidence' => 'required|numeric|between:0,1', - ]; - } -}