forked from nathalie/pedi2
		
	Endpoint devuelve subpedidos. Campo 'contraseña' cambia por 'password' en grupo de compra
This commit is contained in:
		
							parent
							
								
									425c2a3a65
								
							
						
					
					
						commit
						c8ecc2ad9e
					
				
					 11 changed files with 89 additions and 11 deletions
				
			
		|  | @ -1,6 +1,6 @@ | |||
| <?php | ||||
| 
 | ||||
| namespace App; | ||||
| namespace App\Filtros; | ||||
| 
 | ||||
| use Illuminate\Database\Eloquent\Model; | ||||
| use Illuminate\Http\Request; | ||||
|  | @ -31,8 +31,15 @@ class Filtro extends Model | |||
| 
 | ||||
|         //Aplicar filtros que aparecen en los parámetros, si los hay
 | ||||
|         $filtros = $this->request->all(); | ||||
|         foreach($filtros as $filtro => $valor) { | ||||
| 
 | ||||
|         //el filtro nombre debe tomar precedencia sobre otros como (alfabetico)
 | ||||
|         if ($filtros["nombre"]) { | ||||
|             $nombre = $filtros["nombre"]; | ||||
|             unset($filtros["nombre"]); | ||||
|             $filtros = array_merge(["nombre" => $nombre],$filtros); | ||||
|         } | ||||
| 
 | ||||
|         foreach($filtros as $filtro => $valor) { | ||||
|             //Obtener nombre del método  (snake_case a camelCase)
 | ||||
|             $metodo = str_replace('_', '', lcfirst(ucwords($filtro, '_'))); | ||||
| 
 | ||||
|  | @ -53,8 +60,15 @@ class Filtro extends Model | |||
|         return $this->builder; | ||||
|     } | ||||
| 
 | ||||
|     public function categoria(String $valor) | ||||
|     //Buscar un término en el nombre
 | ||||
|     public function nombre(String $valor) | ||||
|     { | ||||
|         $this->builder->where('categoria', $valor); | ||||
|         $this->builder->where('nombre', "LIKE", "%" . $valor . "%")->orderByRaw("IF(nombre = '{$valor}',2,IF(nombre LIKE '{$valor}%',1,0)) DESC"); | ||||
|     } | ||||
| 
 | ||||
|     public function alfabetico(String $order = 'asc') | ||||
|     { | ||||
|         if(!in_array($order,['asc','desc'])) { throw new TypeError(); } | ||||
|         $this->builder->orderBy('nombre', $order); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										13
									
								
								app/Filtros/FiltroDeProducto.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								app/Filtros/FiltroDeProducto.php
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,13 @@ | |||
| <?php | ||||
| 
 | ||||
| namespace App\Filtros; | ||||
| use Illuminate\Database\Eloquent\Builder; | ||||
| 
 | ||||
| class FiltroDeProducto extends Filtro { | ||||
| 
 | ||||
| 	public function categoria(String $valor) | ||||
|     { | ||||
|         $this->builder->where('categoria', $valor); | ||||
|     } | ||||
| 
 | ||||
| } | ||||
							
								
								
									
										14
									
								
								app/Filtros/FiltroDeSubpedido.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								app/Filtros/FiltroDeSubpedido.php
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,14 @@ | |||
| <?php | ||||
| 
 | ||||
| namespace App\Filtros; | ||||
| 
 | ||||
| use Illuminate\Database\Eloquent\Model; | ||||
| 
 | ||||
| class FiltroDeSubpedido extends Filtro | ||||
| { | ||||
|     public function grupoDeCompra(String $valor) | ||||
|     { | ||||
|         if (!is_numeric($valor)) { throw new TypeError();} | ||||
|         $this->builder->where('grupo_de_compra_id', intval($valor)); | ||||
|     } | ||||
| } | ||||
|  | @ -9,6 +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'; | ||||
|   protected $hidden = ['contraseña']; | ||||
|   protected $hidden = ['password']; | ||||
|    | ||||
| } | ||||
|  |  | |||
|  | @ -4,7 +4,7 @@ namespace App\Http\Controllers\Api; | |||
| 
 | ||||
| use App\Http\Controllers\Controller; | ||||
| use Illuminate\Http\Request; | ||||
| use App\Filtro; | ||||
| use App\Filtros\FiltroDeProducto; | ||||
| use App\Producto; | ||||
| 
 | ||||
| class ProductoController extends Controller | ||||
|  | @ -12,11 +12,11 @@ class ProductoController extends Controller | |||
|     /** | ||||
|      * Mostrar una lista de productos. | ||||
|      * | ||||
|      * @param App\Filtro $filtros | ||||
|      * @param App\Filtros\FiltroDeProducto $filtros | ||||
|      * @param \Illuminate\Http\Request  $request | ||||
|      * @return \Illuminate\Http\Response | ||||
|      */ | ||||
|     public function index(Filtro $filtros, Request $request) | ||||
|     public function index(FiltroDeProducto $filtros, Request $request) | ||||
|     { | ||||
|         return Producto::filtrar($filtros)->paginate(Producto::getPaginar($request)); | ||||
|     } | ||||
|  |  | |||
							
								
								
									
										23
									
								
								app/Http/Controllers/Api/SubpedidoController.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								app/Http/Controllers/Api/SubpedidoController.php
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,23 @@ | |||
| <?php | ||||
| 
 | ||||
| namespace App\Http\Controllers\Api; | ||||
| 
 | ||||
| use App\Http\Controllers\Controller; | ||||
| use Illuminate\Http\Request; | ||||
| use App\Filtros\FiltroDeSubpedido; | ||||
| use App\Subpedido; | ||||
| 
 | ||||
| class SubpedidoController extends Controller | ||||
| { | ||||
|     /** | ||||
|      * Mostrar una lista de productos. | ||||
|      * | ||||
|      * @param App\Filtros\FiltroDeSubpedido $filtros | ||||
|      * @param \Illuminate\Http\Request  $request | ||||
|      * @return \Illuminate\Http\Response | ||||
|      */ | ||||
|     public function index(FiltroDeSubpedido $filtros, Request $request) | ||||
|     { | ||||
|         return Subpedido::filtrar($filtros)->get(); | ||||
|     } | ||||
| } | ||||
|  | @ -4,6 +4,7 @@ namespace App; | |||
| 
 | ||||
| use Illuminate\Database\Eloquent\Model; | ||||
| use Illuminate\Http\Request; | ||||
| use App\Filtros\FiltroDeProducto; | ||||
| 
 | ||||
| class Producto extends Model | ||||
| { | ||||
|  | @ -21,7 +22,8 @@ class Producto extends Model | |||
|     return $this->belongsTo('App\Proveedor'); | ||||
|   } | ||||
| 
 | ||||
|   public function scopeFiltrar($query, Filtro $filtros) | ||||
|   //Este método permite que se apliquen los filtros al hacer una request (por ejemplo, de búsqueda)
 | ||||
|   public function scopeFiltrar($query, FiltroDeProducto $filtros) | ||||
|   { | ||||
|       return $filtros->aplicar($query); | ||||
|   } | ||||
|  |  | |||
|  | @ -6,6 +6,7 @@ use League\Csv\Reader; | |||
| use Illuminate\Database\Eloquent\Model; | ||||
| use Illuminate\Support\Facades\DB; | ||||
| use Log; | ||||
| use App\Filtros\FiltroDeSubpedido; | ||||
| 
 | ||||
| class Subpedido extends Model | ||||
| { | ||||
|  | @ -22,4 +23,10 @@ class Subpedido extends Model | |||
|     return $this->belongsTo('App\GrupoDeCompra'); | ||||
|   } | ||||
| 
 | ||||
|   //Este método permite que se apliquen los filtros al hacer una request (por ejemplo, de búsqueda)
 | ||||
|   public function scopeFiltrar($query, FiltroDeSubpedido $filtros) | ||||
|   { | ||||
|       return $filtros->aplicar($query); | ||||
|   } | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -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')->nullable(); | ||||
|             $table->string('password')->nullable(); | ||||
|             $table->timestamps(); | ||||
|         }); | ||||
|     } | ||||
|  |  | |||
							
								
								
									
										2
									
								
								public/js/main.js
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								public/js/main.js
									
										
									
									
										vendored
									
									
								
							|  | @ -33,7 +33,7 @@ Vue.component('region-option', { | |||
| Vue.component('barrio-select', { | ||||
| 	template: ` | ||||
| 		<div v-show="visible" class="block"> | ||||
| 			<label class="label">Seleccioná tu grupo de compra</label> | ||||
| 			<label class="label">Seleccioná tu barrio o grupo de compra</label> | ||||
| 			<div class="select"> | ||||
| 	        	<select> | ||||
| 			    	<option>Seleccionar</option> | ||||
|  |  | |||
|  | @ -37,4 +37,9 @@ Route::middleware('api')->group(function () { | |||
| 	Route::prefix('productos')->group(function () { | ||||
| 		Route::get('/','Api\ProductoController@index'); | ||||
| 	}); | ||||
| 
 | ||||
|     //@TO DO -> esta ruta debe estar en middleware de autenticacion
 | ||||
|     Route::prefix('subpedidos')->group(function () { | ||||
|         Route::get('/','Api\SubpedidoController@index'); | ||||
|     }); | ||||
| }); | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 nat
						nat