Skip to content

Commit f475a0b

Browse files
committed
Merge pull request #1 from StydeNet/master
actualizar
2 parents 2513c8b + ca6261f commit f475a0b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1108
-3241
lines changed

app/Entities/Ticket.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
class Ticket extends Entity
66
{
77

8+
protected $fillable = ['title', 'status'];
9+
810
public function author()
911
{
10-
return $this->belongsTo(User::getClass());
12+
return $this->belongsTo(User::getClass(), 'user_id');
1113
}
1214

1315
public function comments()
@@ -17,7 +19,7 @@ public function comments()
1719

1820
public function voters()
1921
{
20-
return $this->belongsToMany(User::getClass(), 'ticket_votes');
22+
return $this->belongsToMany(User::getClass(), 'ticket_votes')->withTimestamps();
2123
}
2224

2325
public function getOpenAttribute()

app/Entities/TicketComment.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
class TicketComment extends Entity
66
{
77

8+
protected $fillable = ['comment', 'link'];
9+
810
public function ticket()
911
{
1012
return $this->belongsTo(Ticket::getClass());

app/Entities/User.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,12 @@ public function tickets()
3939

4040
public function voted()
4141
{
42-
return $this->belongsToMany(Ticket::getClass(), 'ticket_votes');
42+
return $this->belongsToMany(Ticket::getClass(), 'ticket_votes')->withTimestamps();
43+
}
44+
45+
public function hasVoted(Ticket $ticket)
46+
{
47+
return $this->voted()->where('ticket_id', $ticket->id)->count();
4348
}
4449

4550
}

app/Http/Controllers/Auth/AuthController.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,15 @@ public function __construct(Guard $auth, Registrar $registrar)
3535

3636
$this->middleware('guest', ['except' => 'getLogout']);
3737
}
38+
39+
/**
40+
* Get the post register / login redirect path.
41+
*
42+
* @return string
43+
*/
44+
public function redirectPath()
45+
{
46+
return '/';
47+
}
48+
3849
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace TeachMe\Http\Controllers;
4+
5+
use Illuminate\Auth\Guard;
6+
use Illuminate\Http\Request;
7+
use TeachMe\Entities\Ticket;
8+
use TeachMe\Entities\TicketComment;
9+
use TeachMe\Repositories\CommentRepository;
10+
use TeachMe\Repositories\TicketRepository;
11+
12+
class CommentsController extends Controller {
13+
14+
protected $commentRepository;
15+
protected $ticketRepository;
16+
17+
public function __construct(
18+
TicketRepository $ticketRepository,
19+
CommentRepository $commentRepository
20+
)
21+
{
22+
$this->commentRepository = $commentRepository;
23+
$this->ticketRepository = $ticketRepository;
24+
}
25+
26+
public function submit($id, Request $request, Guard $auth)
27+
{
28+
$this->validate($request, [
29+
'comment' => 'required|max:250',
30+
'link' => 'url'
31+
]);
32+
33+
$ticket = $this->ticketRepository->findOrFail($id);
34+
35+
$this->commentRepository->create(
36+
$ticket,
37+
currentUser(),
38+
$request->get('comment'),
39+
$request->get('link')
40+
);
41+
42+
session()->flash('success', 'Tu comentario fue guardado exitosamente');
43+
return redirect()->back();
44+
}
45+
46+
}
Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
11
<?php namespace TeachMe\Http\Controllers;
22

3-
use TeachMe\Entities\Ticket;
4-
use TeachMe\Http\Requests;
5-
use TeachMe\Http\Controllers\Controller;
6-
3+
use Illuminate\Auth\Guard;
4+
use Illuminate\Support\Facades\Redirect;
75
use Illuminate\Http\Request;
86

7+
use TeachMe\Repositories\TicketRepository;
8+
99
class TicketsController extends Controller {
1010

11+
private $ticketRepository;
12+
13+
public function __construct(TicketRepository $ticketRepository)
14+
{
15+
$this->ticketRepository = $ticketRepository;
16+
}
17+
1118
public function latest()
1219
{
13-
$tickets = Ticket::orderBy('created_at', 'DESC')->paginate(20);
20+
$tickets = $this->ticketRepository->paginateLatest();
21+
1422
return view('tickets/list', compact('tickets'));
1523
}
1624

@@ -21,20 +29,39 @@ public function popular()
2129

2230
public function open()
2331
{
24-
$tickets = Ticket::where('status', 'open')->orderBy('created_at', 'DESC')->paginate(20);
32+
$tickets = $this->ticketRepository->paginateOpen();
2533
return view('tickets/list', compact('tickets'));
2634
}
2735

2836
public function closed()
2937
{
30-
$tickets = Ticket::where('status', 'closed')->orderBy('created_at', 'DESC')->paginate(20);
38+
$tickets = $this->ticketRepository->paginateClosed();
3139
return view('tickets/list', compact('tickets'));
3240
}
3341

3442
public function details($id)
3543
{
36-
$ticket = Ticket::findOrFail($id);
44+
$ticket = $this->ticketRepository->findOrFail($id);
3745
return view('tickets/details', compact('ticket'));
3846
}
3947

48+
public function create()
49+
{
50+
return view('tickets.create');
51+
}
52+
53+
public function store(Request $request)
54+
{
55+
$this->validate($request, [
56+
'title' => 'required|max:120'
57+
]);
58+
59+
$ticket = $this->ticketRepository->openNew(
60+
currentUser(),
61+
$request->get('title')
62+
);
63+
64+
return Redirect::route('tickets.details', $ticket->id);
65+
}
66+
4067
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php namespace TeachMe\Http\Controllers;
2+
3+
use Illuminate\Http\Request;
4+
use TeachMe\Repositories\TicketRepository;
5+
use TeachMe\Repositories\VoteRepository;
6+
7+
class VotesController extends Controller {
8+
9+
private $ticketRepository;
10+
private $voteRepository;
11+
12+
public function __construct(
13+
TicketRepository $ticketRepository,
14+
VoteRepository $voteRepository
15+
)
16+
{
17+
$this->ticketRepository = $ticketRepository;
18+
$this->voteRepository = $voteRepository;
19+
}
20+
21+
public function submit($id, Request $request)
22+
{
23+
$ticket = $this->ticketRepository->findOrFail($id);
24+
$success = $this->voteRepository->vote(currentUser(), $ticket);
25+
26+
if ($request->ajax()) {
27+
return response()->json(compact('success'));
28+
}
29+
30+
return redirect()->back();
31+
}
32+
33+
public function destroy($id, Request $request)
34+
{
35+
$ticket = $this->ticketRepository->findOrFail($id);
36+
$success = $this->voteRepository->unvote(currentUser(), $ticket);
37+
38+
if ($request->ajax()) {
39+
return response()->json(compact('success'));
40+
}
41+
42+
return redirect()->back();
43+
}
44+
45+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace TeachMe\Http\ViewComposers;
4+
5+
use Illuminate\Support\Facades\Lang;
6+
use Illuminate\Support\Facades\Route;
7+
8+
class TicketsListComposer {
9+
10+
public function compose($view)
11+
{
12+
$view->title = trans(Route::currentRouteName() . '_title');
13+
$view->text_total = Lang::choice(
14+
'tickets.total',
15+
$view->tickets->total(),
16+
['title' => strtolower($view->title)]
17+
);
18+
}
19+
20+
}

app/Http/routes.php

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,33 @@
3232
Route::controllers([
3333
'auth' => 'Auth\AuthController',
3434
'password' => 'Auth\PasswordController',
35-
]);
35+
]);
36+
37+
Route::group(['middleware' => 'auth'], function () {
38+
39+
// Crear solicitudes
40+
Route::get('/solicitar', [
41+
'as' => 'tickets.create',
42+
'uses' => 'TicketsController@create'
43+
]);
44+
Route::post('/solicitar', [
45+
'as' => 'tickets.store',
46+
'uses' => 'TicketsController@store'
47+
]);
48+
49+
// Votar
50+
Route::post('votar/{id}', [
51+
'as' => 'votes.submit',
52+
'uses' => 'VotesController@submit'
53+
]);
54+
Route::delete('votar/{id}', [
55+
'as' => 'votes.destroy',
56+
'uses' => 'VotesController@destroy'
57+
]);
58+
59+
Route::post('comentar/{id}', [
60+
'as' => 'comments.submit',
61+
'uses' => 'CommentsController@submit',
62+
]);
63+
64+
});
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php namespace TeachMe\Providers;
2+
3+
use Illuminate\Support\ServiceProvider;
4+
5+
class ViewServiceProvider extends ServiceProvider {
6+
7+
/**
8+
* Bootstrap the application services.
9+
*
10+
* @return void
11+
*/
12+
public function boot()
13+
{
14+
view()->composer(
15+
'tickets/list',
16+
'TeachMe\Http\ViewComposers\TicketsListComposer'
17+
);
18+
}
19+
20+
/**
21+
* Register the application services.
22+
*
23+
* @return void
24+
*/
25+
public function register()
26+
{
27+
//
28+
}
29+
30+
}

0 commit comments

Comments
 (0)