Skip to content
This repository has been archived by the owner on Apr 12, 2020. It is now read-only.

Entrega Proyecto 1 #19

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"plugins": ["@babel/plugin-proposal-class-properties"]
}
12 changes: 12 additions & 0 deletions app/Colour.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Colour extends Model
{
protected $fillable = [
'colour',
];
}
2 changes: 2 additions & 0 deletions app/Http/Controllers/Auth/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Controllers\Auth;

use App\User;
use Str;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
Expand Down Expand Up @@ -67,6 +68,7 @@ protected function create(array $data)
'name' => $data['name'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
'api_token' => Str::random(60),
]);
}
}
55 changes: 55 additions & 0 deletions app/Http/Controllers/ElementosController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Stampa;
use App\Colour;
use App\Size;

class ElementosController extends Controller{

public function __construct()
{
$this->middleware('auth:api');
}

public function getColores(){
$colores = Colour::get('colour');
$arreglo = [];
foreach($colores as $color){
$arreglo[] = ['colour' => $color->colour];
}
if ($arreglo != null)
return response()->json($arreglo, 200);
else
return abort(404);
}


public function getStampas(){
$stampas = Stampa::get('stampa');
$arreglo = [];
foreach($stampas as $stampa){
$arreglo[] = ['stampa' => $stampa->stampa];
}
if ($arreglo != null)
return response()->json($arreglo, 200);
else
return abort(404);
}

public function getTalles(){
$talles = Size::get('size');
$arreglo = [];
foreach($talles as $talle){
$arreglo[] = ['size' => $talle->size];
}

if($arreglo!=null)
return response()->json($arreglo,200);
else
return abort(404);
}

}
28 changes: 28 additions & 0 deletions app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class HomeController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth');
}

/**
* Show the application dashboard.
*
* @return \Illuminate\Contracts\Support\Renderable
*/
public function index()
{
return view('home');
}
}
58 changes: 58 additions & 0 deletions app/Http/Controllers/remeraController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Shirt;

class RemeraController extends Controller
{

public function __construct()
{
$this->middleware('auth:api');
}

public function getRemeras()
{
//aca tengo que devolver todas las remeras del usuario logeado.
$user = auth('api')->user();

$remeras = Shirt::where('user_id', $user->id)->get();

return response()->json($remeras, 200);
}

public function guardar(Request $request)
{

$data = $request->all();

$request->validate([
'colour' => ['required', 'string', 'exists:colours', 'max:255'],
'stampa' => ['nullable', 'string', 'exists:stampas', 'max:255'],
'size' => ['nullable', 'string', 'exists:sizes', 'max:255'],
]);

$nueva = new Shirt;
$nueva->stampa = $data['stampa'];
$nueva->colour = $data['colour'];
$nueva->size = $data['size'];
$nueva->user_id = auth('api')->user()->id;

$nueva->save();

return response()->json([$request->all()]);
}

public function eliminar($id)
{

$remera = Shirt::findOrFail($id);
if (auth('api')->user()->id == $remera->user_id) {
$remera->delete();
return response()->json(['result' => 'success']);
}
return response()->json(['result' => 'fail']);
}
}
12 changes: 12 additions & 0 deletions app/Shirt.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Shirt extends Model
{
protected $fillable = [
'stampa_id', 'colour','size','user_id'
];
}
12 changes: 12 additions & 0 deletions app/Stampa.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Stampa extends Model
{
protected $fillable = [
'stampa'
];
}
6 changes: 5 additions & 1 deletion app/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class User extends Authenticatable
* @var array
*/
protected $fillable = [
'name', 'email', 'password',
'name', 'email', 'password','api_token',
];

/**
Expand All @@ -36,4 +36,8 @@ class User extends Authenticatable
protected $casts = [
'email_verified_at' => 'datetime',
];

public function misRemeras(){
return hasMany('App\Shirt');
}
}
12 changes: 12 additions & 0 deletions app/size.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Size extends Model
{
protected $fillable = [
'size'
];
}
6 changes: 6 additions & 0 deletions database/migrations/2014_10_12_000000_create_users_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ public function up()
$table->string('password');
$table->rememberToken();
$table->timestamps();

//para el token
$table->string('api_token', 80)
->unique()
->nullable()
->default(null);
});
}

Expand Down
31 changes: 31 additions & 0 deletions database/migrations/2019_05_30_195035_create_stampas_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateStampasTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('stampas', function (Blueprint $table) {
$table->string('stampa');
$table->primary('stampa');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('stampas');
}
}
31 changes: 31 additions & 0 deletions database/migrations/2019_06_04_191450_create_colours_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateColoursTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('colours', function (Blueprint $table) {
$table->string('colour');
$table->primary('colour');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('colours');
}
}
31 changes: 31 additions & 0 deletions database/migrations/2019_06_08_151417_create_sizes_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateSizesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('sizes', function (Blueprint $table) {
$table->string('size');
$table->primary('size');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('sizes');
}
}
42 changes: 42 additions & 0 deletions database/migrations/2019_06_08_151748_create_shirts_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateShirtsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('shirts', function (Blueprint $table) {

$table->bigIncrements('id');
$table->timestamps();
$table->string('stampa')->nullable();
$table->string('colour')->nullable();
$table->string('size')->nullable();
$table->unsignedBigInteger('user_id');

$table->foreign('user_id')->references('id')->on('users');
$table->foreign('stampa')->references('stampa')->on('stampas');
$table->foreign('colour')->references('colour')->on('colours');
$table->foreign('size')->references('size')->on('sizes');

});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('shirts');
}
}
Loading