diff options
| author | Robert | 2017-07-28 18:21:48 +0200 | 
|---|---|---|
| committer | Robert | 2017-08-01 22:12:33 +0200 | 
| commit | 0b198fa8dece545f7cfd282d9a10d0638b0491b4 (patch) | |
| tree | 87852136769dfe1e2976e5eab126ba30137ea05e /app/controllers/api | |
| parent | 7680c88adf7d5161908d630a51a83cde603e5f6d (diff) | |
| download | chouette-core-0b198fa8dece545f7cfd282d9a10d0638b0491b4.tar.bz2 | |
Refs: #4176@2h; Request Spec for NetexImport adapted and implemented
- Specing that, in case of a correct request  Referential & NetexImport instances are created and a 201 is returned
- Specing that, in case of an incorrect request,  no instance is created and a 406 with a correct error message is returned
- Implemented
MISSING:
Refactor controller implmentation
Diffstat (limited to 'app/controllers/api')
| -rw-r--r-- | app/controllers/api/v1/netex_imports_controller.rb | 15 | 
1 files changed, 12 insertions, 3 deletions
diff --git a/app/controllers/api/v1/netex_imports_controller.rb b/app/controllers/api/v1/netex_imports_controller.rb index d67d121c0..e9b8242bd 100644 --- a/app/controllers/api/v1/netex_imports_controller.rb +++ b/app/controllers/api/v1/netex_imports_controller.rb @@ -5,9 +5,18 @@ module Api        def create          respond_to do | format |            format.json do  -            @import = NetexImport.create(netex_import_params) -            unless @import.valid? -              render json: {errors: @import.errors}, status: 406 +            workbench = Workbench.where(id: netex_import_params['workbench_id']).first +            if workbench +              @referential = Referential.new(name: netex_import_params['name'], organisation_id: workbench.organisation_id, workbench_id: workbench.id) +              @import = NetexImport.new(netex_import_params) +              if @import.valid? && @referential.valid? +                @import.save! +                @referential.save! +              else +                render json: {errors: @import.errors.to_h.merge( @referential.errors.to_h )}, status: 406 +              end +            else +              render json: {errors: {'workbench_id' => 'missing'}}, status: 406              end            end          end  | 
