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

Entrega Proyecto 1 #22

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
54b1af2
Conexión SQL, Creación DB + Tabla seed con usuario por defecto
jonifritz Apr 15, 2019
9d2569a
Creación autenticación Laravel
jonifritz Apr 15, 2019
115a9a6
Creación de la tabla para la entidad, vista para registrar la entidad…
jonifritz Apr 15, 2019
9a44f4a
Listar libros, index libros
jonifritz Apr 15, 2019
1eedec8
- add model Lista, view Lista, ListController.
jonifritz Apr 18, 2019
2898b12
Fix list.create
jonifritz Apr 23, 2019
9d59493
add bookRequest, update checkBookPrivacy, add book.update, edit book.…
jonifritz Apr 24, 2019
3651274
- Edit and update book (controller and views)
jonifritz Apr 27, 2019
3151fad
- ProfileController
jonifritz Apr 27, 2019
ecb47c2
- Update Book controller (book.index, add book.destroy).
jonifritz Apr 30, 2019
2544b07
Procfile for Heroku
jonifritz Apr 30, 2019
2625145
-Updates views
jonifritz Apr 30, 2019
2e1fa1b
- General fixes. BookController, ListController, Middleware.
jonifritz Apr 30, 2019
9e9b025
Update Procfile
jonifritz Apr 30, 2019
1a71b08
Update views for responsive
jonifritz Apr 30, 2019
d99d45c
- Home.
jonifritz Apr 30, 2019
c7c0902
- ListRequest added.
jonifritz Apr 30, 2019
798673e
- Update book and book views.
jonifritz Apr 30, 2019
43658a0
- General updates.
jonifritz May 1, 2019
58fa588
-update readme
jonifritz May 1, 2019
50406a9
minor updates
jonifritz May 1, 2019
9e51b0c
- home updated
jonifritz May 1, 2019
3f6de47
- update routes
jonifritz May 1, 2019
86a96e2
homeController updated
jonifritz May 1, 2019
86c0b91
fix middleware (auth)
jonifritz May 2, 2019
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
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: vendor/bin/heroku-php-apache2 public/
10 changes: 10 additions & 0 deletions app/Book.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Book extends Model
{
//
}
152 changes: 152 additions & 0 deletions app/Http/Controllers/BookController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
<?php

namespace App\Http\Controllers;

use App\Book;
use App\Lista;
use Illuminate\Http\Request;
use Auth;
use App\Http\Requests\BookRequest;

class BookController extends Controller
{

public function __construct()
{

$this->middleware('auth');
}

/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$books = Book::where('user_id', Auth::user()->id)->get();

$data['books'] = $books;

return view('book.index', $data);
}


/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{

$lists = Auth::user()->list()->get();

if($lists) {
$data['lists'] = $lists;
} else {
$data['lists'] = [];
}


return view('book.create', $data);
}

/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(BookRequest $request)
{
$book = New Book();

$book->name=$request->name;
$book->author=$request->author;
$book->isbn=$request->isbn;
$book->page_number=$request->page_number;
$book->language=$request->language;
$book->user_id = Auth::user()->id;
$book->list_id=$request->list_id;

if ($book->save()) {
return redirect()->route('book.create')->with('status', 'Éxito');
}
}

/**
* Display the specified resource.
*
* @param \App\Book $book
* @return \Illuminate\Http\Response
*/
public function show(Book $book)
{
//
}

/**
* Show the form for editing the specified resource.
*
* @param \App\Book $book
* @return \Illuminate\Http\Response
*/
public function edit($libro)
{

$book = Book::where([
['id', $libro],
['user_id', Auth::user()->id],
]);

if($book->count() == 0) {
return redirect()->route('book.index')->with('status', 'Este libro no pertenece');
}

$lists = Auth::user()->list()->get();

$data['lists'] = $lists;
$data['book'] = $book->first();

return view('book.edit', $data);
//return $lists;
}

/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Book $book
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $book)
{
$book_ = Book::find($book);

$book_->name=$request->name;
$book_->author=$request->author;
$book_->isbn=$request->isbn;
$book_->page_number=$request->page_number;
$book_->language=$request->language;
$book_->list_id=$request->list_id;

if ($book_->save()) {
// return redirect()->route('book.update')->with('status', 'Éxito');
return redirect()->route('book.edit', ['id' => $book_->id])->with('status', 'Éxito');
}
}

/**
* Remove the specified resource from storage.
*
* @param \App\Book $book
* @return \Illuminate\Http\Response
*/
public function destroy($book)
{
Book::where('id', $book)->delete();

return redirect()->route('book.index');
}
}
34 changes: 34 additions & 0 deletions app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Lista;

class HomeController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{

}

/**
* Show the application dashboard.
*
* @return \Illuminate\Contracts\Support\Renderable
*/
public function index()
{

$lists = Lista::where('public_list', 1)->get();

$data['lists'] = $lists;

return view('home', $data);
}
}
162 changes: 162 additions & 0 deletions app/Http/Controllers/ListaController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
<?php

namespace App\Http\Controllers;

use App\Lista;
use Illuminate\Http\Request;
use Auth;
use App\User;
use App\Book;
use App\Http\Requests\BookRequest;

class ListaController extends Controller
{
public function __construct()
{

$this->middleware('auth')->except('publicLists', 'show');

//$this->middleware('book.privacy')->only('show');
$this->middleware('book.privacy', ['only' => ['show','edit']]);
}

/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$lists = Auth::user()->list()->get();

$data['listas'] = $lists;

return view('lista.index', $data);
}


public function publicLists($userid)
{
try {

$lists = User::findOrFail($userid)->list()->where('public_list', 1)->get();

$data['lists'] = $lists;

return view('lista.publicLists', $data);

} catch(\Exception $e) {

return redirect('/home');

}


}

/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return view('lista.create');
}

/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$lista = New Lista();

$lista->name = $request->name;
$lista->user_id = Auth::user()->id;

if ($lista->save()) {
return redirect()->route('list.create')->with('status', 'Éxito');
}
}

/**
* Display the specified resource.
*
* @param \App\lista $lista
* @return \Illuminate\Http\Response
*/
public function show($lista)
{
$lista = Lista::find($lista);
$name = $lista->name;
$books = $lista->book;
$public_list = $lista->public_list;

$data['name'] = $name;
$data['books'] = $books;
$data['is_public'] = $public_list;

return view('lista.show', $data);
}

/**
* Show the form for editing the specified resource.
*
* @param \App\lista $lista
* @return \Illuminate\Http\Response
*/
public function edit($lista)
{

$list = Lista::find($lista);

$data['list'] = $list;

return view('lista.edit', $data);

}

/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\lista $lista
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $lista)
{
$list = Lista::find($lista);

$list->name = $request->name;
$list->public_list = $request->public_list;
$list->user_id = Auth::user()->id;

if ($list->save()) {
return redirect()->route('list.edit', ['id' => $list->id])->with('status', 'Éxito');
}

}

/**
* Remove the specified resource from storage.
*
* @param \App\lista $lista
* @return \Illuminate\Http\Response
*/
public function destroy($lista)
{

if (Lista::where('id', $lista)->delete()) {

$book = Book::where('list_id', $lista)->update(['list_id' => null]);

}

return redirect()->route('list.index');


}
}
Loading