Skip to content

Commit

Permalink
feat: Change video visibility (#484)
Browse files Browse the repository at this point in the history
  • Loading branch information
Betree authored Nov 6, 2024
1 parent 7b6e999 commit 0c907d9
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
23 changes: 23 additions & 0 deletions apps/cf_graphql/lib/resolvers/videos.ex
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,27 @@ defmodule CF.Graphql.Resolvers.Videos do
CF.LLMs.StatementsCreator.process_video!(video.id)
{:ok, video}
end

def edit(_root, %{id: id, unlisted: unlisted}, %{
context: %{user: user}
}) do
base_video = DB.Repo.get!(DB.Schema.Video, id)
changeset = Ecto.Changeset.change(base_video, %{unlisted: unlisted})

Ecto.Multi.new()
|> Ecto.Multi.update(:video, fn _repo ->
changeset
end)
|> Ecto.Multi.run(:action, fn _repo, %{video: video} ->
Repo.insert(CF.Actions.ActionCreator.action_update(user.id, changeset))
end)
|> Repo.transaction()
|> case do
{:ok, %{video: video}} ->
{:ok, video}

{:error, _} ->
{:error, "Failed to update video"}
end
end
end
11 changes: 11 additions & 0 deletions apps/cf_graphql/lib/schema/schema.ex
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,16 @@ defmodule CF.Graphql.Schema do

resolve(&Resolvers.Videos.start_automatic_statements_extraction/3)
end

field :edit_video, :video do
middleware(Middleware.RequireAuthentication)
# MIN_REPUTATION_UPDATE_VIDEO
middleware(Middleware.RequireReputation, 75)

arg(:id, non_null(:id))
arg(:unlisted, non_null(:boolean))

resolve(&Resolvers.Videos.edit/3)
end
end
end
2 changes: 2 additions & 0 deletions apps/cf_graphql/lib/schema/types/video.ex
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ defmodule CF.Graphql.Schema.Types.Video do
field(:inserted_at, :string)
@desc "Define if video has been added by a partner or a regular user"
field(:is_partner, :boolean)
@desc "Define if video is unlisted"
field(:unlisted, non_null(:boolean))
@desc "List all non-removed speakers for this video"
field :speakers, list_of(:speaker) do
resolve(assoc(:speakers))
Expand Down
3 changes: 2 additions & 1 deletion apps/cf_rest_api/lib/views/video_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ defmodule CF.RestApi.VideoView do
speakers: render_many(video.speakers, CF.RestApi.SpeakerView, "speaker.json"),
language: video.language,
is_partner: video.is_partner,
is_subscribed: is_subscribed
is_subscribed: is_subscribed,
unlisted: video.unlisted
}
end
end

0 comments on commit 0c907d9

Please sign in to comment.