Skip to content

Commit

Permalink
Merge pull request #14 from andela-sachungo/fix/UI
Browse files Browse the repository at this point in the history
Fix/ui
  • Loading branch information
sachungo committed Jan 28, 2016
2 parents 4e70502 + 93af209 commit 742e1eb
Show file tree
Hide file tree
Showing 39 changed files with 702 additions and 369 deletions.
2 changes: 1 addition & 1 deletion app/Http/Controllers/Auth/SocialAuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private function findOrCreateUser($socialUser)
return User::create([
'name' => $socialUser->getName(),
'email' => $socialUser->getEmail(),
'provider_id' => $socialUser->getAvatar(),
'provider_id' => $socialUser->getId(),
'avatar' => $socialUser->getAvatar(),
]);
}
Expand Down
22 changes: 11 additions & 11 deletions app/Http/Controllers/CategoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ public function __construct()
}

/**
* Store a newly created resource in storage.
* Store a newly created category in database.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
* @param Soma\Http\Requests\CategoriesRequest $request
* @return \Illuminate\Routing\Redirector
*/
public function store(CategoriesRequest $request)
{
Expand All @@ -35,10 +35,10 @@ public function store(CategoriesRequest $request)
}

/**
* Show the form for editing the specified resource.
* Show the form for editing the category.
*
* @param int $id
* @return \Illuminate\Http\Response
* @return view
*/
public function edit($id)
{
Expand All @@ -48,11 +48,11 @@ public function edit($id)
}

/**
* Update the specified resource in storage.
* Update the category.
*
* @param \Illuminate\Http\Request $request
* @param Soma\Http\Requests\CategoriesRequest $request
* @param int $id
* @return \Illuminate\Http\Response
* @return \Illuminate\Routing\Redirector
*/
public function update(CategoriesRequest $request, $id)
{
Expand All @@ -67,10 +67,10 @@ public function update(CategoriesRequest $request, $id)
}

/**
* Remove the specified resource from storage.
* Delete the category.
*
* @param int $id
* @return \Illuminate\Http\Response
* @return \Illuminate\Routing\Redirector
*/
public function destroy($id)
{
Expand All @@ -91,7 +91,7 @@ public function destroy($id)
/**
* Get the categories of a particular user.
*
* @return \Illuminate\Http\Response
* @return view
*/
public function getCategories()
{
Expand Down
12 changes: 6 additions & 6 deletions app/Http/Controllers/ProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ public function __construct()
}

/**
* Show the form for editing the specified resource.
* Show the form for editing user profile.
*
* @param int $id
* @return \Illuminate\Http\Response
* @return view
*/
public function edit($id)
{
Expand All @@ -30,11 +30,11 @@ public function edit($id)
}

/**
* Update the specified resource in storage.
* Update user details in database.
*
* @param \Illuminate\Http\Request $request
* @param Soma\Http\Requests\ProfileRequest $request
* @param int $id
* @return \Illuminate\Http\Response
* @return \Illuminate\Routing\Redirector
*/
public function update(ProfileRequest $request, $id)
{
Expand All @@ -54,7 +54,7 @@ public function update(ProfileRequest $request, $id)
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
* @return void
*/
public function changeAvatar(Request $request, $id)
{
Expand Down
98 changes: 70 additions & 28 deletions app/Http/Controllers/VideoController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use Soma\Videos;
use Soma\Categories;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Soma\Http\Requests\VideoRequest;

class VideoController extends Controller
Expand All @@ -21,15 +23,16 @@ public function __construct()
'index',
'show',
'getVideosByCategory',
'viewCount',
],
]);
$this->getCategories = Categories::all();
}

/**
* Display a listing of the resource.
* Paginate all the videos in the database.
*
* @return \Illuminate\Http\Response
* @return view
*/
public function index()
{
Expand All @@ -40,9 +43,9 @@ public function index()
}

/**
* Show the form for creating a new resource.
* Show the form for uploading a new video.
*
* @return \Illuminate\Http\Response
* @return view
*/
public function create()
{
Expand All @@ -52,48 +55,50 @@ public function create()
}

/**
* Store a newly created resource in storage.
* Save the video in the database.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
* @param Soma\Http\Requests\VideoRequest $request
* @return \Illuminate\Routing\Redirector
*/
public function store(VideoRequest $request)
{
$category = Categories::find($request->category_id);
$category = Categories::find($request->category);

$link = $this->youtubeEmbedLink($request->youtube_link);
$videoId = $this->getYoutubeId($request->youtube_link);

$category->videos()->create([
'user_id' => auth()->user()->id,
'youtube_link' => $link,
'youtube_id' => $videoId,
'title' => $request->title,
'description' => $request->description,
]);

flash()->success('Success!', 'You have uploaded a video');
flash()->success('Success!', 'Video uploaded');

return redirect()->route('own.videos');
return redirect()->back();
}

/**
* Display the specified resource.
* Get a single video details.
*
* @param int $id
* @return \Illuminate\Http\Response
* @return view
*/
public function show($id)
{
$video = Videos::find($id);
$category = Categories::find($video->category_id);
$video = Videos::with('category', 'userDirect')->where('id', $id)->first();
$categories = $this->getCategories;

return view('videos.show', compact('video', 'category'));
return view('videos.show', compact('video', 'categories'));
}

/**
* Show the form for editing the specified resource.
* Get the for for editing a video.
*
* @param int $id
* @return \Illuminate\Http\Response
* @return view
*/
public function edit($id)
{
Expand All @@ -104,18 +109,23 @@ public function edit($id)
}

/**
* Update the specified resource in storage.
* Update the svideo details in the database.
*
* @param \Illuminate\Http\Request $request
* @param Soma\Http\Requests\VideoRequest $request
* @param int $id
* @return \Illuminate\Http\Response
* @return \Illuminate\Routing\Redirector
*/
public function update(VideoRequest $request, $id)
{
$video = Videos::find($id);

$link = $this->youtubeEmbedLink($request->youtube_link);
$videoId = $this->getYoutubeId($request->youtube_link);

$video->update([
'category_id' => $request->category_id,
'youtube_link' => $request->youtube_link,
'category_id' => $request->category,
'youtube_link' => $link,
'youtube_id' => $videoId,
'title' => $request->title,
'description' => $request->description,
]);
Expand All @@ -126,10 +136,10 @@ public function update(VideoRequest $request, $id)
}

/**
* Remove the specified resource from storage.
* Delete the video from database.
*
* @param int $id
* @return \Illuminate\Http\Response
* @return \Illuminate\Routing\Redirector
*/
public function destroy($id)
{
Expand All @@ -147,9 +157,9 @@ public function destroy($id)
}

/**
* Get the videos of a particular user.
* Get all the videos of a particular user.
*
* @return \Illuminate\Http\Response
* @return view
*/
public function getVideos()
{
Expand All @@ -162,7 +172,7 @@ public function getVideos()
/**
* Get all the videos of a particular category.
*
* @return \Illuminate\Http\Response
* @return view
*/
public function getVideosByCategory($id)
{
Expand All @@ -172,11 +182,29 @@ public function getVideosByCategory($id)
return view('categories.video', compact('videos', 'categories'));
}

/**
* Save the number of times a video is viewed.
*
* @param \Illuminate\Http\Request
* @return \Illuminate\Http\Response
*/
public function viewCount(Request $request)
{
if (isset($request->id)) {
$video = Videos::find($request->id);

$video->play = is_null($video->play) ? 1 : $video->play + 1;
$video->save();

return new Response($video->play, 200);
}
}

/**
* Write the URL to allow the video to be embedded on page.
*
* @param string $youtubeLink
* @return \Illuminate\Http\Response
* @return string
*/
private function youtubeEmbedLink($youtubeLink)
{
Expand All @@ -186,4 +214,18 @@ private function youtubeEmbedLink($youtubeLink)

return $url;
}

/**
* Get the youtube id from the submitted url.
*
* @param string $youtubeLink
* @return string
*/
private function getYoutubeId($youtubeLink)
{
$pattern = "/^(?:https?:\/\/)?(?:www\.youtube\.com\/)(?:embed\/|watch\?v=)([\w-]{9,12})(?:.*)$/";
preg_match($pattern, $youtubeLink, $matches);

return $matches[1];
}
}
2 changes: 1 addition & 1 deletion app/Http/Flash.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ class Flash
/**
* Create a flash message.
*
* Flash is HTTP specific hence no need to inject the Session::store()
* @param string $title
* @param string $message
* @param string $key
* @return void
*/
public function createFlash($title, $message, $type, $key = 'flash_message')
{
// Flash is HTTP specific hence no need to inject the Session::store()
session()->flash($key, [
'title' => $title,
'message' => $message,
Expand Down
3 changes: 2 additions & 1 deletion app/Http/Requests/VideoRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ public function rules()
{
return [
'youtube_link' => 'required|url',
'title' => 'required',
'title' => 'required|max:30',
'description' => 'required',
'category' => 'required',
];
}
}
Loading

0 comments on commit 742e1eb

Please sign in to comment.