Skip to content

Commit 0c907d9

Browse files
authored
feat: Change video visibility (#484)
1 parent 7b6e999 commit 0c907d9

File tree

4 files changed

+38
-1
lines changed

4 files changed

+38
-1
lines changed

apps/cf_graphql/lib/resolvers/videos.ex

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,27 @@ defmodule CF.Graphql.Resolvers.Videos do
114114
CF.LLMs.StatementsCreator.process_video!(video.id)
115115
{:ok, video}
116116
end
117+
118+
def edit(_root, %{id: id, unlisted: unlisted}, %{
119+
context: %{user: user}
120+
}) do
121+
base_video = DB.Repo.get!(DB.Schema.Video, id)
122+
changeset = Ecto.Changeset.change(base_video, %{unlisted: unlisted})
123+
124+
Ecto.Multi.new()
125+
|> Ecto.Multi.update(:video, fn _repo ->
126+
changeset
127+
end)
128+
|> Ecto.Multi.run(:action, fn _repo, %{video: video} ->
129+
Repo.insert(CF.Actions.ActionCreator.action_update(user.id, changeset))
130+
end)
131+
|> Repo.transaction()
132+
|> case do
133+
{:ok, %{video: video}} ->
134+
{:ok, video}
135+
136+
{:error, _} ->
137+
{:error, "Failed to update video"}
138+
end
139+
end
117140
end

apps/cf_graphql/lib/schema/schema.ex

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,5 +99,16 @@ defmodule CF.Graphql.Schema do
9999

100100
resolve(&Resolvers.Videos.start_automatic_statements_extraction/3)
101101
end
102+
103+
field :edit_video, :video do
104+
middleware(Middleware.RequireAuthentication)
105+
# MIN_REPUTATION_UPDATE_VIDEO
106+
middleware(Middleware.RequireReputation, 75)
107+
108+
arg(:id, non_null(:id))
109+
arg(:unlisted, non_null(:boolean))
110+
111+
resolve(&Resolvers.Videos.edit/3)
112+
end
102113
end
103114
end

apps/cf_graphql/lib/schema/types/video.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ defmodule CF.Graphql.Schema.Types.Video do
3838
field(:inserted_at, :string)
3939
@desc "Define if video has been added by a partner or a regular user"
4040
field(:is_partner, :boolean)
41+
@desc "Define if video is unlisted"
42+
field(:unlisted, non_null(:boolean))
4143
@desc "List all non-removed speakers for this video"
4244
field :speakers, list_of(:speaker) do
4345
resolve(assoc(:speakers))

apps/cf_rest_api/lib/views/video_view.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ defmodule CF.RestApi.VideoView do
4343
speakers: render_many(video.speakers, CF.RestApi.SpeakerView, "speaker.json"),
4444
language: video.language,
4545
is_partner: video.is_partner,
46-
is_subscribed: is_subscribed
46+
is_subscribed: is_subscribed,
47+
unlisted: video.unlisted
4748
}
4849
end
4950
end

0 commit comments

Comments
 (0)