From 3e230550423e92f49a6925ed415485f5ffcaf92a Mon Sep 17 00:00:00 2001 From: zafer Date: Fri, 5 Apr 2024 22:24:34 +0300 Subject: [PATCH] add route /:channel_handle/latest --- .../controllers/video_popout_controller.ex | 17 +++++++++++++++++ lib/algora_web/router.ex | 1 + 2 files changed, 18 insertions(+) create mode 100644 lib/algora_web/controllers/video_popout_controller.ex diff --git a/lib/algora_web/controllers/video_popout_controller.ex b/lib/algora_web/controllers/video_popout_controller.ex new file mode 100644 index 0000000..e054b7a --- /dev/null +++ b/lib/algora_web/controllers/video_popout_controller.ex @@ -0,0 +1,17 @@ +defmodule AlgoraWeb.VideoPopoutController do + use AlgoraWeb, :controller + + alias Algora.{Accounts, Library} + + def get(conn, %{"channel_handle" => channel_handle}) do + user = Accounts.get_user_by!(handle: channel_handle) + + case Library.get_latest_video(user) do + nil -> + redirect(conn, to: ~p"/#{user.handle}") + + video -> + redirect(conn, to: ~p"/#{user.handle}/#{video.id}") + end + end +end diff --git a/lib/algora_web/router.ex b/lib/algora_web/router.ex index e6eaad7..636948f 100644 --- a/lib/algora_web/router.ex +++ b/lib/algora_web/router.ex @@ -48,6 +48,7 @@ defmodule AlgoraWeb.Router do scope "/", AlgoraWeb do pipe_through [:browser, :embed] + get "/:channel_handle/latest", VideoPopoutController, :get get "/:channel_handle/chat", ChatPopoutController, :get get "/:channel_handle/embed", EmbedPopoutController, :get