Allow to group bookmarks in folders
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
parent
f0468697cd
commit
d415686bb9
21 changed files with 829 additions and 21 deletions
|
|
@ -0,0 +1,125 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2024 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ApiSpec.PleromaBookmarkFolderOperation do
|
||||
alias OpenApiSpex.Operation
|
||||
alias OpenApiSpex.Schema
|
||||
alias Pleroma.Web.ApiSpec.Schemas.ApiError
|
||||
alias Pleroma.Web.ApiSpec.Schemas.BookmarkFolder
|
||||
alias Pleroma.Web.ApiSpec.Schemas.FlakeID
|
||||
|
||||
import Pleroma.Web.ApiSpec.Helpers
|
||||
|
||||
@spec open_api_operation(any()) :: any()
|
||||
def open_api_operation(action) do
|
||||
operation = String.to_existing_atom("#{action}_operation")
|
||||
apply(__MODULE__, operation, [])
|
||||
end
|
||||
|
||||
def index_operation do
|
||||
%Operation{
|
||||
tags: ["Bookmark folders"],
|
||||
summary: "All bookmark folders",
|
||||
security: [%{"oAuth" => ["read:bookmarks"]}],
|
||||
operationId: "PleromaAPI.BookmarkFolderController.index",
|
||||
responses: %{
|
||||
200 =>
|
||||
Operation.response("Array of Bookmark Folders", "application/json", %Schema{
|
||||
type: :array,
|
||||
items: BookmarkFolder
|
||||
})
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def create_operation do
|
||||
%Operation{
|
||||
tags: ["Bookmark folders"],
|
||||
summary: "Create a bookmark folder",
|
||||
security: [%{"oAuth" => ["write:bookmarks"]}],
|
||||
operationId: "PleromaAPI.BookmarkFolderController.create",
|
||||
requestBody: request_body("Parameters", create_request(), required: true),
|
||||
responses: %{
|
||||
200 => Operation.response("Bookmark Folder", "application/json", BookmarkFolder),
|
||||
422 => Operation.response("Error", "application/json", ApiError)
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def update_operation do
|
||||
%Operation{
|
||||
tags: ["Bookmark folders"],
|
||||
summary: "Update a bookmark folder",
|
||||
security: [%{"oAuth" => ["write:bookmarks"]}],
|
||||
operationId: "PleromaAPI.BookmarkFolderController.update",
|
||||
parameters: [id_param()],
|
||||
requestBody: request_body("Parameters", update_request(), required: true),
|
||||
responses: %{
|
||||
200 => Operation.response("Bookmark Folder", "application/json", BookmarkFolder),
|
||||
403 => Operation.response("Forbidden", "application/json", ApiError),
|
||||
404 => Operation.response("Not Found", "application/json", ApiError),
|
||||
422 => Operation.response("Error", "application/json", ApiError)
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def delete_operation do
|
||||
%Operation{
|
||||
tags: ["Bookmark folders"],
|
||||
summary: "Delete a bookmark folder",
|
||||
security: [%{"oAuth" => ["write:bookmarks"]}],
|
||||
operationId: "PleromaAPI.BookmarkFolderController.delete",
|
||||
parameters: [id_param()],
|
||||
responses: %{
|
||||
200 => Operation.response("Bookmark Folder", "application/json", BookmarkFolder),
|
||||
403 => Operation.response("Forbidden", "application/json", ApiError),
|
||||
404 => Operation.response("Not Found", "application/json", ApiError)
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
defp create_request do
|
||||
%Schema{
|
||||
title: "BookmarkFolderCreateRequest",
|
||||
type: :object,
|
||||
properties: %{
|
||||
name: %Schema{
|
||||
type: :string,
|
||||
description: "Folder name"
|
||||
},
|
||||
emoji: %Schema{
|
||||
type: :string,
|
||||
nullable: true,
|
||||
description: "Folder emoji"
|
||||
}
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
defp update_request do
|
||||
%Schema{
|
||||
title: "BookmarkFolderUpdateRequest",
|
||||
type: :object,
|
||||
properties: %{
|
||||
name: %Schema{
|
||||
type: :string,
|
||||
nullable: true,
|
||||
description: "Folder name"
|
||||
},
|
||||
emoji: %Schema{
|
||||
type: :string,
|
||||
nullable: true,
|
||||
description: "Folder emoji"
|
||||
}
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def id_param do
|
||||
Operation.parameter(:id, :path, FlakeID.schema(), "Bookmark Folder ID",
|
||||
example: "9umDrYheeY451cQnEe",
|
||||
required: true
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
@ -256,6 +256,18 @@ defmodule Pleroma.Web.ApiSpec.StatusOperation do
|
|||
description: "Privately bookmark a status",
|
||||
operationId: "StatusController.bookmark",
|
||||
parameters: [id_param()],
|
||||
requestBody:
|
||||
request_body("Parameters", %Schema{
|
||||
title: "StatusUpdateRequest",
|
||||
type: :object,
|
||||
properties: %{
|
||||
folder_id: %Schema{
|
||||
nullable: true,
|
||||
allOf: [FlakeID],
|
||||
description: "ID of bookmarks folder, if any"
|
||||
}
|
||||
}
|
||||
}),
|
||||
responses: %{
|
||||
200 => status_response()
|
||||
}
|
||||
|
|
@ -430,7 +442,15 @@ defmodule Pleroma.Web.ApiSpec.StatusOperation do
|
|||
summary: "Bookmarked statuses",
|
||||
description: "Statuses the user has bookmarked",
|
||||
operationId: "StatusController.bookmarks",
|
||||
parameters: pagination_params(),
|
||||
parameters: [
|
||||
Operation.parameter(
|
||||
:folder_id,
|
||||
:query,
|
||||
FlakeID.schema(),
|
||||
"If provided, only display bookmarks from given folder"
|
||||
)
|
||||
| pagination_params()
|
||||
],
|
||||
security: [%{"oAuth" => ["read:bookmarks"]}],
|
||||
responses: %{
|
||||
200 => Operation.response("Array of Statuses", "application/json", array_of_statuses())
|
||||
|
|
|
|||
26
lib/pleroma/web/api_spec/schemas/bookmark_folder.ex
Normal file
26
lib/pleroma/web/api_spec/schemas/bookmark_folder.ex
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2024 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ApiSpec.Schemas.BookmarkFolder do
|
||||
alias OpenApiSpex.Schema
|
||||
alias Pleroma.Web.ApiSpec.Schemas.FlakeID
|
||||
|
||||
require OpenApiSpex
|
||||
|
||||
OpenApiSpex.schema(%{
|
||||
title: "BookmarkFolder",
|
||||
description: "Response schema for a bookmark folder",
|
||||
type: :object,
|
||||
properties: %{
|
||||
id: FlakeID,
|
||||
name: %Schema{type: :string, description: "Folder name"},
|
||||
emoji: %Schema{type: :string, description: "Folder emoji", nullable: true}
|
||||
},
|
||||
example: %{
|
||||
"id" => "9toJCu5YZW7O7gfvH6",
|
||||
"name" => "Read later",
|
||||
"emoji" => nil
|
||||
}
|
||||
})
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue