Skip to content

Commit

Permalink
feat: add api series season
Browse files Browse the repository at this point in the history
  • Loading branch information
trueChazza committed Dec 1, 2023
1 parent ef05864 commit f5c8f3f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/media_server_web/controllers/series_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,26 @@ defmodule MediaServerWeb.SeriesController do
)
end

def show(conn, %{"id" => id, "season" => season}) do
series = MediaServer.SeriesIndex.all() |> MediaServer.SeriesIndex.find(id)

episodes = MediaServerWeb.Repositories.Episodes.get_all(series["id"], season)

conn
|> put_resp_header("content-type", "application/json")
|> send_resp(
200,
Jason.encode!(
Enum.map(episodes, fn episode ->
%{
"title" => episode["title"],
"overview" => episode["overview"],
"screenshot" => ~p"/api/images?episode=#{episode["id"]}&type=screenshot",
}
end))
)
end

def show(conn, %{"id" => id}) do
series = MediaServer.SeriesIndex.all() |> MediaServer.SeriesIndex.find(id)

Expand Down
8 changes: 8 additions & 0 deletions test/media_server_web/controllers/series_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,12 @@ defmodule MediaServerWeb.SeriesControllerTest do

assert conn.resp_body === "{\"background\":\"/api/images?series=1&type=background\",\"id\":1,\"overview\":\"An object in the sky spreads radiation over North America. Fearing terrorism, U.S. Homeland Security agents are dispatched to investigate and contain the damage. What they discover will have implications for the entire world.\",\"poster\":\"/api/images?series=1&type=poster\",\"seasonCount\":1,\"stream\":\"/api/stream?series=1\",\"title\":\"Pioneer One\",\"year\":2010}"
end

test "it should have season", %{conn: conn, user: user} do
conn = get(conn, ~p"/api/series/1?season=1&token=#{user.api_token.token}")

assert conn.status === 200

assert conn.resp_body === "[{\"overview\":\"An object from space spreads radiation over North America. Fearing terrorism, U.S. Homeland Security agents are dispatched to investigate and contain the damage. What they discover is a forgotten relic of the old Soviet space program, whose return to Earth will have implications for the entire world.\",\"screenshot\":\"/api/images?episode=1&type=screenshot\",\"title\":\"Earthfall\"},{\"overview\":\"Hired Mars expert Dr. Zachary Walzer (Jack Haley) fights to prove the validity of the Mars story. Can he convince the government to mount a manned mission to Mars? Agent in charge Tom Taylor (James Rich) faces pressure from both the Canadians and his own superiors, and has to make a call.\",\"screenshot\":\"/api/images?episode=2&type=screenshot\",\"title\":\"The Man From Mars\"},{\"overview\":\"Now quarantined to the Calgary base for two weeks, Taylor and his team have bought time to get answers from the supposed Martian cosmonaut. But who can get him to talk?\",\"screenshot\":\"/api/images?episode=3&type=screenshot\",\"title\":\"Alone in the Night\"},{\"overview\":\"As the media begins to question the story about the crashed satellite, Secretary McClellan (Einar Gunn) starts to play hardball with the Russians in pursuit of his own truth. But everything hinges on what Yuri (Aleksandr Evtushenko), the frightened boy at the center of it all, might have to say...\",\"screenshot\":\"/api/images?episode=4&type=screenshot\",\"title\":\"Triangular Diplomacy\"},{\"overview\":\"When an unannounced visitor breaks in to the Calgary base with just days left in the Quarantine, tensions are higher than ever. The fate of Yuri and everyone on Tom Taylor’s team is about to be decided in this, the penultimate episode of the first season.\",\"screenshot\":\"/api/images?episode=5&type=screenshot\",\"title\":\"Sea Change\"},{\"overview\":\"Taylor prepares to go to the public with Yuri's story, and everyone discovers the consequences of their actions in the conclusion to Pioneer One's first season.\",\"screenshot\":\"/api/images?episode=6&type=screenshot\",\"title\":\"War of the World\"}]"
end
end

0 comments on commit f5c8f3f

Please sign in to comment.