Add backend to list an user's pictures
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -525,6 +525,28 @@ defmodule Mobilizon.GraphQL.Resolvers.User do
|
||||
end
|
||||
end
|
||||
|
||||
def user_medias(%User{id: user_id}, %{page: page, limit: limit}, %{
|
||||
context: %{current_user: %User{id: logged_in_user_id}}
|
||||
})
|
||||
when user_id == logged_in_user_id do
|
||||
%{elements: elements, total: total} = Mobilizon.Media.pictures_for_user(user_id, page, limit)
|
||||
|
||||
{:ok,
|
||||
%{
|
||||
elements:
|
||||
Enum.map(elements, fn element ->
|
||||
%{
|
||||
name: element.file.name,
|
||||
url: element.file.url,
|
||||
id: element.id,
|
||||
content_type: element.file.content_type,
|
||||
size: element.file.size
|
||||
}
|
||||
end),
|
||||
total: total
|
||||
}}
|
||||
end
|
||||
|
||||
@spec update_user_login_information(User.t(), map()) ::
|
||||
{:ok, User.t()} | {:error, Ecto.Changeset.t()}
|
||||
defp update_user_login_information(
|
||||
|
||||
@@ -16,6 +16,14 @@ defmodule Mobilizon.GraphQL.Schema.PictureType do
|
||||
field(:size, :integer, description: "The picture's size")
|
||||
end
|
||||
|
||||
@desc """
|
||||
A paginated list of pictures
|
||||
"""
|
||||
object :paginated_picture_list do
|
||||
field(:elements, list_of(:picture), description: "The list of pictures")
|
||||
field(:total, :integer, description: "The total number of pictures in the list")
|
||||
end
|
||||
|
||||
@desc "An attached picture or a link to a picture"
|
||||
input_object :picture_input do
|
||||
# Either a full picture object
|
||||
|
||||
@@ -26,7 +26,7 @@ defmodule Mobilizon.GraphQL.Schema.PostType do
|
||||
)
|
||||
|
||||
field(:picture, :picture,
|
||||
description: "The event's picture",
|
||||
description: "The posts's picture",
|
||||
resolve: &Picture.picture/3
|
||||
)
|
||||
end
|
||||
|
||||
@@ -110,6 +110,16 @@ defmodule Mobilizon.GraphQL.Schema.UserType do
|
||||
field(:current_sign_in_ip, :string,
|
||||
description: "The IP adress the user's currently signed-in with"
|
||||
)
|
||||
|
||||
field(:media, :paginated_picture_list, description: "The user's media objects") do
|
||||
arg(:page, :integer,
|
||||
default_value: 1,
|
||||
description: "The page in the paginated user media list"
|
||||
)
|
||||
|
||||
arg(:limit, :integer, default_value: 10, description: "The limit of user media per page")
|
||||
resolve(&User.user_medias/3)
|
||||
end
|
||||
end
|
||||
|
||||
@desc "The list of roles an user can have"
|
||||
|
||||
Reference in New Issue
Block a user