Skip to content

Commit

Permalink
Refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
ziishaned committed Apr 12, 2017
1 parent a184f9b commit 1e59d2e
Show file tree
Hide file tree
Showing 15 changed files with 522 additions and 101 deletions.
82 changes: 74 additions & 8 deletions app/Http/Controllers/CommentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,67 @@

use Auth;
use Emoji;
use Notifynder;
use App\Models\User;
use App\Models\Team;
use App\Models\Wiki;
use App\Models\Page;
use App\Models\Space;
use App\Models\Comment;
use Illuminate\Http\Request;

/**
* Class CommentController
*
* @package App\Http\Controllers
* @author Zeeshan Ahmed <[email protected]>
*/
class CommentController extends Controller
{
/**
* @var \Illuminate\Http\Request
*/
protected $request;

protected $comment;

/**
* @var \App\Models\Page
*/
protected $page;

public function __construct(Request $request, Page $page, Comment $comment)
/**
* @var \App\Models\Comment
*/
protected $comment;

/**
* @var \App\Models\User
*/
protected $user;

/**
* CommentController constructor.
*
* @param \Illuminate\Http\Request $request
* @param \App\Models\Page $page
* @param \App\Models\Comment $comment
* @param \App\Models\User $user
*/
public function __construct(Request $request, Page $page, Comment $comment, User $user)
{
$this->page = $page;
$this->user = $user;
$this->request = $request;
$this->comment = $comment;
$this->page = $page;
}

/**
* Create a new wiki comment.
*
* @param \App\Models\Team $team
* @param \App\Models\Space $space
* @param \App\Models\Wiki $wiki
* @return \Illuminate\Http\RedirectResponse
*/
public function storeWikiComment(Team $team, Space $space, Wiki $wiki)
{
$this->validate($this->request, Comment::COMMENT_RULES);
Expand All @@ -45,24 +84,32 @@ public function storeWikiComment(Team $team, Space $space, Wiki $wiki)
]);
}

/**
* Notify all users that are mentioned in comment.
*
* @param $mentions
* @param $wiki
* @param null $page
* @return bool
*/
public function notifyMentionedUsers($mentions, $wiki, $page = null)
{
foreach ($mentions as $mention) {
$mention = str_replace('@', '', $mention);

$user = \App\Models\User::where('slug', $mention)->first();
$user = $this->user->getUser($mention);;

if(is_null($page)) {
$url = route('wikis.show', [Auth::user()->getTeam()->slug, $wiki->space->slug, $wiki->slug]);
\Notifynder::category('wiki.user.mentioned')
Notifynder::category('wiki.user.mentioned')
->from(Auth::user()->id)
->to($user->id)
->url($url)
->extra(['wiki_name' => $wiki->name, 'username' => Auth::user()->name])
->send();
} else {
$url = route('pages.show', [Auth::user()->getTeam()->slug, $wiki->space->slug, $wiki->slug, $page->slug]);
\Notifynder::category('page.user.mentioned')
Notifynder::category('page.user.mentioned')
->from(Auth::user()->id)
->to($user->id)
->url($url)
Expand All @@ -75,6 +122,15 @@ public function notifyMentionedUsers($mentions, $wiki, $page = null)
return true;
}

/**
* Create a new page comment.
*
* @param \App\Models\Team $team
* @param \App\Models\Space $space
* @param \App\Models\Wiki $wiki
* @param \App\Models\Page $page
* @return \Illuminate\Http\RedirectResponse
*/
public function storePageComment(Team $team, Space $space, Wiki $wiki, Page $page)
{

Expand All @@ -95,15 +151,25 @@ public function storePageComment(Team $team, Space $space, Wiki $wiki, Page $pag
]);
}

/**
* Delete comment.
*
* @return \Illuminate\Http\JsonResponse
*/
public function destroy()
{
$this->comment->where('id', $this->request->get('commentId'))->where('user_id', Auth::user()->id)->delete();
$this->comment->deleteComment($this->request->get('commentId'));

return response()->json([
'deleted' => true,
], 200);
}

/**
* Update comment.
*
* @return \Illuminate\Http\JsonResponse
*/
public function update()
{
$this->validate($this->request, Comment::COMMENT_RULES);
Expand Down
5 changes: 5 additions & 0 deletions app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
*/
class HomeController extends Controller
{
/**
* Show home view to guest.
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function home()
{
return view('home');
Expand Down
31 changes: 28 additions & 3 deletions app/Http/Controllers/IntegrationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,54 @@

use DB;
use Carbon\Carbon;
use App\Models\Team;
use App\Models\Integration;
use Illuminate\Http\Request;
use App\Models\{
Team, Integration
};

/**
* Class IntegrationController
*
* @package App\Http\Controllers
* @author Zeeshan Ahmed <[email protected]>
*/
class IntegrationController extends Controller
{
/**
* @var \Illuminate\Http\Request
*/
protected $request;

/**
* @var \App\Models\Integration
*/
protected $integration;

/**
* IntegrationController constructor.
*
* @param \Illuminate\Http\Request $request
* @param \App\Models\Integration $integration
*/
public function __construct(Request $request, Integration $integration)
{
$this->request = $request;
$this->integration = $integration;
}

/**
* Store a new slack integration.
*
* @param \App\Models\Team $team
* @return \Illuminate\Http\RedirectResponse
*
*/
public function storeSlackIntegration(Team $team)
{
$this->validate($this->request, Integration::INTEGRATION_RULES);

$teamIntegration = $this->integration->storeSlackIntegration($this->request->all(), $team->id);

// Update all the integration actions on which user want to be notified on slack.
foreach ($this->request->integrations as $integration) {
DB::table('team_integration_actions')->insert([
'integration_id' => $teamIntegration->id,
Expand Down
42 changes: 40 additions & 2 deletions app/Http/Controllers/InviteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,46 @@
namespace App\Http\Controllers;

use Mail;
use Illuminate\Http\Request;
use App\Models\Team;
use App\Models\Invite;
use Illuminate\Http\Request;

/**
* Class InviteController
*
* @package App\Http\Controllers
* @author Zeeshan Ahmed <[email protected]>
*/
class InviteController extends Controller
{
/**
* @var \Illuminate\Http\Request
*/
protected $request;

/**
* @var \App\Models\Invite
*/
protected $invite;

/**
* InviteController constructor.
*
* @param \Illuminate\Http\Request $request
* @param \App\Models\Invite $invite
*/
public function __construct(Request $request, Invite $invite)
{
$this->request = $request;
$this->invite = $invite;
}

/**
* Invite user to team.
*
* @param \App\Models\Team $team
* @return \Illuminate\Http\RedirectResponse
*/
public function store(Team $team)
{
$this->validate($this->request, Invite::INVITE_RULES, [
Expand All @@ -36,6 +60,13 @@ public function store(Team $team)
]);
}

/**
* Send invitation mail to the invited user.
*
* @param $invitation
* @param $team
* @return bool
*/
public function sendInvitationEmail($invitation, $team)
{
Mail::send('mails.invitation', ['invitation' => $invitation, 'team' => $team], function ($message) use ($invitation, $team) {
Expand All @@ -47,9 +78,16 @@ public function sendInvitationEmail($invitation, $team)
return true;
}

/**
* Delete pending invitation.
*
* @param \App\Models\Team $team
* @param $invitationCode
* @return \Illuminate\Http\RedirectResponse
*/
public function destroy(Team $team, $invitationCode)
{
$this->invite->where('code', $invitationCode)->where('team_id', $team->id)->delete();
$this->invite->deleteInvitation($invitationCode, $team->id);

return redirect()->back()->with([
'alert' => 'Invitation successfully removed.',
Expand Down
Loading

0 comments on commit 1e59d2e

Please sign in to comment.