forked from nathalie/pedi2
		
	Cambia el endpoint de region. Agrego el endpoint para Grupos de compra. Seeder que crea los grupos de compra en la bd a partir de un csv
This commit is contained in:
		
							parent
							
								
									b889dbf1e1
								
							
						
					
					
						commit
						9ee2e66438
					
				
					 8 changed files with 179 additions and 10 deletions
				
			
		|  | @ -9,11 +9,6 @@ class GrupoDeCompra extends Model | ||||||
|   public $timestamps = false; |   public $timestamps = false; | ||||||
|   protected $fillable = [ "nombre","region","telefono","correo","referente_finanzas","cantidad_de_nucleos"]; |   protected $fillable = [ "nombre","region","telefono","correo","referente_finanzas","cantidad_de_nucleos"]; | ||||||
|   protected $table = 'grupos_de_compra'; |   protected $table = 'grupos_de_compra'; | ||||||
|   public static $regiones = [ |   protected $hidden = ['contraseña']; | ||||||
|   	'NORTE', |  | ||||||
|   	'SUR', |  | ||||||
|   	'ESTE', |  | ||||||
|   	'OESTE' |  | ||||||
|   ]; |  | ||||||
|    |    | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -13,7 +13,8 @@ | ||||||
|         "fruitcake/laravel-cors": "^2.0", |         "fruitcake/laravel-cors": "^2.0", | ||||||
|         "guzzlehttp/guzzle": "^6.3.1|^7.0.1", |         "guzzlehttp/guzzle": "^6.3.1|^7.0.1", | ||||||
|         "laravel/framework": "^7.29", |         "laravel/framework": "^7.29", | ||||||
|         "laravel/tinker": "^2.5" |         "laravel/tinker": "^2.5", | ||||||
|  |         "league/csv": "^9.8" | ||||||
|     }, |     }, | ||||||
|     "require-dev": { |     "require-dev": { | ||||||
|         "facade/ignition": "^2.0", |         "facade/ignition": "^2.0", | ||||||
|  |  | ||||||
							
								
								
									
										86
									
								
								composer.lock
									
										
									
										generated
									
									
									
								
							
							
						
						
									
										86
									
								
								composer.lock
									
										
									
										generated
									
									
									
								
							|  | @ -4,7 +4,7 @@ | ||||||
|         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", |         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", | ||||||
|         "This file is @generated automatically" |         "This file is @generated automatically" | ||||||
|     ], |     ], | ||||||
|     "content-hash": "f5f1a3bdf47db0afc9822772493c4b3d", |     "content-hash": "29ba109acea0ebdbcafb4cf531e83199", | ||||||
|     "packages": [ |     "packages": [ | ||||||
|         { |         { | ||||||
|             "name": "asm89/stack-cors", |             "name": "asm89/stack-cors", | ||||||
|  | @ -1214,6 +1214,90 @@ | ||||||
|             ], |             ], | ||||||
|             "time": "2021-07-17T17:13:23+00:00" |             "time": "2021-07-17T17:13:23+00:00" | ||||||
|         }, |         }, | ||||||
|  |         { | ||||||
|  |             "name": "league/csv", | ||||||
|  |             "version": "9.8.0", | ||||||
|  |             "source": { | ||||||
|  |                 "type": "git", | ||||||
|  |                 "url": "https://github.com/thephpleague/csv.git", | ||||||
|  |                 "reference": "9d2e0265c5d90f5dd601bc65ff717e05cec19b47" | ||||||
|  |             }, | ||||||
|  |             "dist": { | ||||||
|  |                 "type": "zip", | ||||||
|  |                 "url": "https://api.github.com/repos/thephpleague/csv/zipball/9d2e0265c5d90f5dd601bc65ff717e05cec19b47", | ||||||
|  |                 "reference": "9d2e0265c5d90f5dd601bc65ff717e05cec19b47", | ||||||
|  |                 "shasum": "" | ||||||
|  |             }, | ||||||
|  |             "require": { | ||||||
|  |                 "ext-json": "*", | ||||||
|  |                 "ext-mbstring": "*", | ||||||
|  |                 "php": "^7.4 || ^8.0" | ||||||
|  |             }, | ||||||
|  |             "require-dev": { | ||||||
|  |                 "ext-curl": "*", | ||||||
|  |                 "ext-dom": "*", | ||||||
|  |                 "friendsofphp/php-cs-fixer": "^v3.4.0", | ||||||
|  |                 "phpstan/phpstan": "^1.3.0", | ||||||
|  |                 "phpstan/phpstan-phpunit": "^1.0.0", | ||||||
|  |                 "phpstan/phpstan-strict-rules": "^1.1.0", | ||||||
|  |                 "phpunit/phpunit": "^9.5.11" | ||||||
|  |             }, | ||||||
|  |             "suggest": { | ||||||
|  |                 "ext-dom": "Required to use the XMLConverter and or the HTMLConverter classes", | ||||||
|  |                 "ext-iconv": "Needed to ease transcoding CSV using iconv stream filters" | ||||||
|  |             }, | ||||||
|  |             "type": "library", | ||||||
|  |             "extra": { | ||||||
|  |                 "branch-alias": { | ||||||
|  |                     "dev-master": "9.x-dev" | ||||||
|  |                 } | ||||||
|  |             }, | ||||||
|  |             "autoload": { | ||||||
|  |                 "psr-4": { | ||||||
|  |                     "League\\Csv\\": "src" | ||||||
|  |                 }, | ||||||
|  |                 "files": [ | ||||||
|  |                     "src/functions_include.php" | ||||||
|  |                 ] | ||||||
|  |             }, | ||||||
|  |             "notification-url": "https://packagist.org/downloads/", | ||||||
|  |             "license": [ | ||||||
|  |                 "MIT" | ||||||
|  |             ], | ||||||
|  |             "authors": [ | ||||||
|  |                 { | ||||||
|  |                     "name": "Ignace Nyamagana Butera", | ||||||
|  |                     "email": "nyamsprod@gmail.com", | ||||||
|  |                     "homepage": "https://github.com/nyamsprod/", | ||||||
|  |                     "role": "Developer" | ||||||
|  |                 } | ||||||
|  |             ], | ||||||
|  |             "description": "CSV data manipulation made easy in PHP", | ||||||
|  |             "homepage": "https://csv.thephpleague.com", | ||||||
|  |             "keywords": [ | ||||||
|  |                 "convert", | ||||||
|  |                 "csv", | ||||||
|  |                 "export", | ||||||
|  |                 "filter", | ||||||
|  |                 "import", | ||||||
|  |                 "read", | ||||||
|  |                 "transform", | ||||||
|  |                 "write" | ||||||
|  |             ], | ||||||
|  |             "support": { | ||||||
|  |                 "docs": "https://csv.thephpleague.com", | ||||||
|  |                 "issues": "https://github.com/thephpleague/csv/issues", | ||||||
|  |                 "rss": "https://github.com/thephpleague/csv/releases.atom", | ||||||
|  |                 "source": "https://github.com/thephpleague/csv" | ||||||
|  |             }, | ||||||
|  |             "funding": [ | ||||||
|  |                 { | ||||||
|  |                     "url": "https://github.com/sponsors/nyamsprod", | ||||||
|  |                     "type": "github" | ||||||
|  |                 } | ||||||
|  |             ], | ||||||
|  |             "time": "2022-01-04T00:13:07+00:00" | ||||||
|  |         }, | ||||||
|         { |         { | ||||||
|             "name": "league/flysystem", |             "name": "league/flysystem", | ||||||
|             "version": "1.1.9", |             "version": "1.1.9", | ||||||
|  |  | ||||||
|  | @ -21,7 +21,7 @@ class CreateGruposDeCompraTable extends Migration | ||||||
|             $table->string('telefono')->nullable(); |             $table->string('telefono')->nullable(); | ||||||
|             $table->string('correo')->nullable(); |             $table->string('correo')->nullable(); | ||||||
|             $table->string('referente_finanzas')->nullable(); |             $table->string('referente_finanzas')->nullable(); | ||||||
|             $table->string('contraseña'); |             $table->string('contraseña')->nullable(); | ||||||
|             $table->timestamps(); |             $table->timestamps(); | ||||||
|         }); |         }); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  | @ -4,6 +4,7 @@ use Illuminate\Database\Seeder; | ||||||
| 
 | 
 | ||||||
| class DatabaseSeeder extends Seeder | class DatabaseSeeder extends Seeder | ||||||
| { | { | ||||||
|  | 	const CHUNK_SIZE            = 100; | ||||||
|     /** |     /** | ||||||
|      * Seed the application's database. |      * Seed the application's database. | ||||||
|      * |      * | ||||||
|  | @ -12,5 +13,6 @@ class DatabaseSeeder extends Seeder | ||||||
|     public function run() |     public function run() | ||||||
|     { |     { | ||||||
|         $this->call(UserSeeder::class); |         $this->call(UserSeeder::class); | ||||||
|  |         $this->call(GrupoDeCompraSeeder::class); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
							
								
								
									
										37
									
								
								database/seeds/GrupoDeCompraSeeder.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								database/seeds/GrupoDeCompraSeeder.php
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,37 @@ | ||||||
|  | <?php | ||||||
|  | 
 | ||||||
|  | use Illuminate\Database\Seeder; | ||||||
|  | use League\Csv\Reader; | ||||||
|  | 
 | ||||||
|  | class GrupoDeCompraSeeder extends Seeder | ||||||
|  | { | ||||||
|  |     /** | ||||||
|  |      * Run the database seeds. | ||||||
|  |      * | ||||||
|  |      * @return void | ||||||
|  |      */ | ||||||
|  |     public function run() | ||||||
|  |     { | ||||||
|  |         $csv = Reader::createFromPath(resource_path('csv/barrios.csv'), 'r'); | ||||||
|  |         $csv->setDelimiter("|"); | ||||||
|  |         $csv->setEnclosure("'"); | ||||||
|  |         $csv->setHeaderOffset(0); | ||||||
|  |         $registros = $csv->getRecords(); | ||||||
|  |         $toInsert = []; | ||||||
|  | 
 | ||||||
|  |         foreach($registros as $registro){ | ||||||
|  |             $toInsert[] = [ | ||||||
|  |                 'nombre'        => $registro['barrio'], | ||||||
|  |                 'region'        => $registro['region'], | ||||||
|  |                 'telefono'      => $registro['telefono'], | ||||||
|  |                 'correo'        => $registro['correo'], | ||||||
|  |                 'referente_finanzas'   => $registro['referente'] | ||||||
|  |             ]; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         foreach (array_chunk($toInsert,DatabaseSeeder::CHUNK_SIZE) as $chunk)   | ||||||
|  |         { | ||||||
|  |             DB::table('grupos_de_compra')->insert($chunk);  | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										43
									
								
								resources/csv/barrios.csv
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								resources/csv/barrios.csv
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,43 @@ | ||||||
|  | barrio|region|referente|telefono|correo | ||||||
|  | BUCEO|ESTE||| | ||||||
|  | MALVIN NORTE|ESTE||| | ||||||
|  | PINAR|ESTE||| | ||||||
|  | UNION|ESTE||| | ||||||
|  | SANTO DOMINGO|NORTE||| | ||||||
|  | 21 DE FEBRERO|NORTE||| | ||||||
|  | PIEDRAS BLANCAS|NORTE||| | ||||||
|  | BELLA ITALIA|NORTE||| | ||||||
|  | JARDINES|NORTE||| | ||||||
|  | LA SOCIALISTA|NORTE||| | ||||||
|  | VILLA GARCIA|NORTE||| | ||||||
|  | LAS ACACIAS|NORTE||| | ||||||
|  | MANGA|NORTE||| | ||||||
|  | CERRITO|OESTE||| | ||||||
|  | LEZICA|OESTE||| | ||||||
|  | PEÑAROL|OESTE||| | ||||||
|  | LAS PIEDRAS|OESTE||| | ||||||
|  | A.C.T.E.O|OESTE||| | ||||||
|  | NUEVO PARIS|OESTE||| | ||||||
|  | BELVEDERE|OESTE||| | ||||||
|  | BATLLE BERRES|OESTE||| | ||||||
|  | CERRO PTI|OESTE||| | ||||||
|  | COLECTIVO UTU LAVALLEJA|OESTE||| | ||||||
|  | FOGONES|OESTE||| | ||||||
|  | LAVALLEJA|OESTE||| | ||||||
|  | REJUNTE|OESTE||| | ||||||
|  | CAPURRO|OESTE||| | ||||||
|  | PARQUE RODO|SUR||| | ||||||
|  | REDUCTO|SUR||| | ||||||
|  | AGUADA|SUR||| | ||||||
|  | CASA DEL VECINO|SUR||| | ||||||
|  | CIUDAD VIEJA|SUR||| | ||||||
|  | COOP EJIDO|SUR||| | ||||||
|  | COVIREUS|SUR||| | ||||||
|  | LA BLANQUEADA|SUR||| | ||||||
|  | LA CURVA|SUR||| | ||||||
|  | PANADERIA VIDAL|SUR||| | ||||||
|  | SUA|SUR||| | ||||||
|  | TRES CRUCES|SUR||| | ||||||
|  | VILLA ESPAÑOLA|SUR||| | ||||||
|  | AUDA|OTRA||| | ||||||
|  | SINTEP|OTRA||| | ||||||
| 
 | 
|  | @ -17,6 +17,13 @@ use App\GrupoDeCompra; | ||||||
| 
 | 
 | ||||||
| Route::middleware('auth:api')->group(function () { | Route::middleware('auth:api')->group(function () { | ||||||
|     Route::get('/regiones', function() { |     Route::get('/regiones', function() { | ||||||
|     	return GrupoDeCompra::$regiones; |     	return GrupoDeCompra::all()->pluck('region')->unique()->flatten(); | ||||||
|  |     }); | ||||||
|  | 
 | ||||||
|  |     Route::prefix('grupos-de-compra')->group( function(){ | ||||||
|  |     	Route::get('/', function() { | ||||||
|  | 	    	$atributos_a_ocultar = ['id', 'telefono', 'cantidad_de_nucleos', 'correo', 'referente_finanzas', 'created_at', 'updated_at'];  | ||||||
|  |     		return GrupoDeCompra::all()->makeHidden($atributos_a_ocultar)->sortBy('nombre')->groupBy('region'); | ||||||
|  |     	}); | ||||||
|     }); |     }); | ||||||
| }); | }); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 nat
						nat