Skip to content

Commit

Permalink
Avanza hasta el commentController
Browse files Browse the repository at this point in the history
  • Loading branch information
orgimeno committed Jan 24, 2019
1 parent 689c499 commit 4316e33
Show file tree
Hide file tree
Showing 9 changed files with 323 additions and 2 deletions.
1 change: 1 addition & 0 deletions app/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public function registerBundles()
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new Knp\Bundle\PaginatorBundle\KnpPaginatorBundle(),
new AppBundle\AppBundle(),
new BackendBundle\BackendBundle(),
];
Expand Down
15 changes: 15 additions & 0 deletions app/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,18 @@ swiftmailer:
username: "%mailer_user%"
password: "%mailer_password%"
spool: { type: memory }

# KnpPaginatorBundle Config
knp_paginator:
page_range: 5
default_options:
page_name: page # page query parameter name
sort_field_name: sort # sort field query parameter name
sort_direction_name: direction # sort direction query parameter name
distinct: true # ensure distinct results, useful when ORM queries are using GROUP BY statements
filter_field_name: filterField # filter field query parameter name
filter_value_name: filterValue # filter value query parameter name
template:
pagination: '@KnpPaginator/Pagination/sliding.html.twig' # sliding pagination controls template
sortable: '@KnpPaginator/Pagination/sortable_link.html.twig' # sort link template
filtration: '@KnpPaginator/Pagination/filtration.html.twig'
90 changes: 90 additions & 0 deletions src/AppBundle/Controller/CommentController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?php

namespace AppBundle\Controller;

use BackendBundle\Entity\User;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;

class CommentController extends Controller
{

/**
* Create Video
*
* @throws \Exception
*/
public function newAction(Request $request){
$helpers = $this->get('app.helpers');
$hash = $request->get('authorization', null);
$authCheck = $helpers->authCheck($hash);

if($authCheck){
$em = $this->getDoctrine()->getManager();
$identity = $helpers->authCheck($hash, true);

$json = $request->get("json", null);
if($json != null){

$params = json_decode($json);

$created_at = new \DateTime('now');
$update_at = new \DateTime('now');
$imagen = null;
$videos_path = null;

$user_id =($identity->sub != null) ? $identity->sub : null;
$title = (isset($params->title)) ? $params->title : null;
$description = (isset($params->description )) ? $params->description : null;
$status = (isset($params->status )) ? $params->status : null;

if($user_id != null && $title != null){
/** @var User $user */
$user = $em->getRepository(User::class)->find($identity->sub);


$video = new Video();

$video->setCreatedAt($created_at);
$video->setUpdatedAt($update_at);
$video->setUser($user);
$video->setDescription($description);
$video->setStatus($status);
$video->setTitle($title);

$em->persist($video);
$em->flush();

$data = [
'status' => "success",
'code' => 200,
'data' => $video
];
}else{
$data = [
'status' => "error",
'code' => 460,
'msg' => "Video not created"
];
}

}else{
$data = [
'status' => "error",
'code' => 470,
'msg' => "Params failed, video not created"
];
}

}else{
$data = [
'status' => "error",
'code' => 400,
'msg' => "Authorazation not valid"
];
}

return $helpers->json($data);
}
}
51 changes: 51 additions & 0 deletions src/AppBundle/Controller/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,4 +281,55 @@ public function uploadImageAction(Request $request){

return $helpers->json($data);
}


/**
* @param Request $request
*/
public function channelAction(Request $request, $id = null){

$helpers = $this->get("app.helpers");

$em = $this->getDoctrine()->getManager();

if(!is_null($id)){

$user = $em->getRepository(User::class)->find($id);

$dql = "SELECT v from BackendBundle:Video v ORDER BY v.id DESC";

$query = $em->createQuery($dql);

$page = $request->query->getInt("page", 1);

$paginator = $this->get("knp_paginator");

$items_per_page = 6;

$pagination = $paginator->paginate($query, $page, $items_per_page);
$total_items_count = $pagination->getTotalItemCount();

$data = [
"status" => "success",
"total_items_count" => $total_items_count,
"page_actual" => $page,
"items_per_page" => $items_per_page,
"total_pages" => ceil($total_items_count / $items_per_page),
"data" => [
'user' => $user,
'videos' => $pagination
]
];

}else{

$data = [
"status" => "Error",
'code' => 400,
'msg' => "User not found"
];
}

return $helpers->json($data);
}
}
131 changes: 131 additions & 0 deletions src/AppBundle/Controller/VideoController.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,4 +276,135 @@ public function uploadAction(Request $request, $id = null){

return $helpers->json($data);
}


/**
* @param Request $request
*/
public function videosAction(Request $request){

$helpers = $this->get("app.helpers");

$em = $this->getDoctrine()->getManager();

$dql = "SELECT v from BackendBundle:Video v ORDER BY v.id DESC";

$query = $em->createQuery($dql);

$page = $request->query->getInt("page", 1);

$paginator = $this->get("knp_paginator");

$items_per_page = 6;

$pagination = $paginator->paginate($query, $page, $items_per_page);
$total_items_count = $pagination->getTotalItemCount();

$data = [
"status" => "success",
"total_items_count" => $total_items_count,
"page_actual" => $page,
"items_per_page" => $items_per_page,
"total_pages" => ceil($total_items_count / $items_per_page),
"data" => $pagination
];

return $helpers->json($data);
}

/**
* @param Request $request
*/
public function lastsVideosAction(Request $request){

$helpers = $this->get("app.helpers");

$em = $this->getDoctrine()->getManager();

$dql = "SELECT v from BackendBundle:Video v ORDER BY v.createdAt DESC";

$query = $em->createQuery($dql)->setMaxResults(5);
$video = $query->getResult();

$data = [
'status' => "success",
'data' => $video
];

return $helpers->json($data);
}

/**
* @param Request $request
*/
public function videoAction(Request $request, $id = null){

$helpers = $this->get("app.helpers");

$em = $this->getDoctrine()->getManager();

if(!is_null($id)){

$video = $em->getRepository(Video::class)->find($id);

$data = [
'status' => "success",
'data' => $video
];

}else{

$data = [
'status' => "error",
'code' => 400,
'msg' => "Video id not selected"
];
}

return $helpers->json($data);
}

/**
* @param Request $request
*/
public function searchAction(Request $request, $search = null){

$helpers = $this->get("app.helpers");

$em = $this->getDoctrine()->getManager();

if(!is_null($search)) {


$dql = "SELECT v from BackendBundle:Video v WHERE v.title like :search OR v.description LIKE :search ORDER BY v.createdAt DESC";

$query = $em->createQuery($dql)->setParameter('search', '%' . $search . '%');

}else{

$dql = "SELECT v from BackendBundle:Video v ORDER BY v.createdAt DESC";

$query = $em->createQuery($dql);
}

$page = $request->query->getInt("page", 1);

$paginator = $this->get("knp_paginator");

$items_per_page = 6;

$pagination = $paginator->paginate($query, $page, $items_per_page);
$total_items_count = $pagination->getTotalItemCount();

$data = [
"status" => "success",
"total_items_count" => $total_items_count,
"page_actual" => $page,
"items_per_page" => $items_per_page,
"total_pages" => ceil($total_items_count / $items_per_page),
"data" => $pagination
];

return $helpers->json($data);
}
}
6 changes: 5 additions & 1 deletion src/AppBundle/Resources/config/routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ app_user:

app_video:
resource: "@AppBundle/Resources/config/routing/video.yml"
prefix: /video
prefix: /video

app_comment:
resource: "@AppBundle/Resources/config/routing/comment.yml"
prefix: /comment
4 changes: 4 additions & 0 deletions src/AppBundle/Resources/config/routing/comment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
comment:
path: /new
defaults: {_controller: "AppBundle:Comment:new"}
methods: POST
5 changes: 5 additions & 0 deletions src/AppBundle/Resources/config/routing/user.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@ user_upload_image:
path: /upload-image-user
defaults: {_controller: "AppBundle:User:uploadImage"}
methods: POST

user_channel:
path: /channel/{id}
defaults: {_controller: "AppBundle:User:channel"}
methods: GET
22 changes: 21 additions & 1 deletion src/AppBundle/Resources/config/routing/video.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,24 @@ video_upload_image:
video_upload_video:
path: /upload-video/{id}
defaults: {_controller: "AppBundle:Video:upload", id:null }
methods: POST
methods: POST

video_list:
path: /list
defaults: {_controller: "AppBundle:Video:videos" }
methods: GET

video_lasts_videos:
path: /last-videos
defaults: {_controller: "AppBundle:Video:lastsVideos" }
methods: GET

video_view:
path: /detail/{id}
defaults: {_controller: "AppBundle:Video:video", id:null }
methods: GET

video_search:
path: /search/{search}
defaults: {_controller: "AppBundle:Video:search", search:null }
methods: GET

0 comments on commit 4316e33

Please sign in to comment.