diff --git a/app/GrupoDeCompra.php b/app/GrupoDeCompra.php index 91de6c6..dec7ea0 100644 --- a/app/GrupoDeCompra.php +++ b/app/GrupoDeCompra.php @@ -9,11 +9,6 @@ class GrupoDeCompra extends Model public $timestamps = false; protected $fillable = [ "nombre","region","telefono","correo","referente_finanzas","cantidad_de_nucleos"]; protected $table = 'grupos_de_compra'; - public static $regiones = [ - 'NORTE', - 'SUR', - 'ESTE', - 'OESTE' - ]; + protected $hidden = ['contraseña']; } diff --git a/composer.json b/composer.json index 8926860..c580243 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,8 @@ "fruitcake/laravel-cors": "^2.0", "guzzlehttp/guzzle": "^6.3.1|^7.0.1", "laravel/framework": "^7.29", - "laravel/tinker": "^2.5" + "laravel/tinker": "^2.5", + "league/csv": "^9.8" }, "require-dev": { "facade/ignition": "^2.0", diff --git a/composer.lock b/composer.lock index c784fa4..7146bea 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "f5f1a3bdf47db0afc9822772493c4b3d", + "content-hash": "29ba109acea0ebdbcafb4cf531e83199", "packages": [ { "name": "asm89/stack-cors", @@ -1214,6 +1214,90 @@ ], "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", "version": "1.1.9", diff --git a/database/migrations/2020_09_23_165235_create_grupos_de_compra_table.php b/database/migrations/2020_09_23_165235_create_grupos_de_compra_table.php index c14c05d..9062089 100644 --- a/database/migrations/2020_09_23_165235_create_grupos_de_compra_table.php +++ b/database/migrations/2020_09_23_165235_create_grupos_de_compra_table.php @@ -21,7 +21,7 @@ class CreateGruposDeCompraTable extends Migration $table->string('telefono')->nullable(); $table->string('correo')->nullable(); $table->string('referente_finanzas')->nullable(); - $table->string('contraseña'); + $table->string('contraseña')->nullable(); $table->timestamps(); }); } diff --git a/database/seeds/DatabaseSeeder.php b/database/seeds/DatabaseSeeder.php index cceafbf..3497642 100644 --- a/database/seeds/DatabaseSeeder.php +++ b/database/seeds/DatabaseSeeder.php @@ -4,6 +4,7 @@ use Illuminate\Database\Seeder; class DatabaseSeeder extends Seeder { + const CHUNK_SIZE = 100; /** * Seed the application's database. * @@ -12,5 +13,6 @@ class DatabaseSeeder extends Seeder public function run() { $this->call(UserSeeder::class); + $this->call(GrupoDeCompraSeeder::class); } } diff --git a/database/seeds/GrupoDeCompraSeeder.php b/database/seeds/GrupoDeCompraSeeder.php new file mode 100644 index 0000000..eaf1052 --- /dev/null +++ b/database/seeds/GrupoDeCompraSeeder.php @@ -0,0 +1,37 @@ +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); + } + } +} diff --git a/resources/csv/barrios.csv b/resources/csv/barrios.csv new file mode 100644 index 0000000..33b9a3d --- /dev/null +++ b/resources/csv/barrios.csv @@ -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||| diff --git a/routes/api.php b/routes/api.php index 6f9464b..6750ce7 100644 --- a/routes/api.php +++ b/routes/api.php @@ -17,6 +17,13 @@ use App\GrupoDeCompra; Route::middleware('auth:api')->group(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'); + }); }); });