2020-07-09 08:01:29 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
require "swagger_helper"
|
2023-01-09 19:18:21 +08:00
|
|
|
|
2022-07-28 10:27:38 +08:00
|
|
|
RSpec.describe "topics" do
|
2020-07-09 08:01:29 +08:00
|
|
|
let(:"Api-Key") { Fabricate(:api_key).key }
|
|
|
|
let(:"Api-Username") { "system" }
|
2023-01-09 19:18:21 +08:00
|
|
|
|
2020-07-09 08:01:29 +08:00
|
|
|
path "/t/{id}/posts.json" do
|
|
|
|
get "Get specific posts from a topic" do
|
|
|
|
tags "Topics"
|
2021-09-03 21:39:29 +08:00
|
|
|
operationId "getSpecificPostsFromTopic"
|
2020-07-09 08:01:29 +08:00
|
|
|
consumes "application/json"
|
|
|
|
parameter name: "Api-Key", in: :header, type: :string, required: true
|
|
|
|
parameter name: "Api-Username", in: :header, type: :string, required: true
|
|
|
|
parameter name: :id, in: :path, schema: { type: :string }
|
|
|
|
|
|
|
|
parameter name: :post_body,
|
|
|
|
in: :body,
|
|
|
|
schema: {
|
|
|
|
type: :object,
|
|
|
|
properties: {
|
2021-08-13 02:25:17 +08:00
|
|
|
"post_ids[]": {
|
2020-07-09 08:01:29 +08:00
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
required: ["post_ids[]"],
|
2023-01-09 19:18:21 +08:00
|
|
|
}
|
|
|
|
|
2020-07-09 08:01:29 +08:00
|
|
|
produces "application/json"
|
|
|
|
response "200", "specific posts" do
|
|
|
|
schema type: :object,
|
|
|
|
properties: {
|
|
|
|
post_stream: {
|
|
|
|
type: :object,
|
|
|
|
properties: {
|
2023-01-09 19:18:21 +08:00
|
|
|
posts: {
|
2020-07-09 08:01:29 +08:00
|
|
|
type: :array,
|
|
|
|
items: {
|
|
|
|
type: :object,
|
|
|
|
properties: {
|
2023-01-09 19:18:21 +08:00
|
|
|
id: {
|
2020-07-09 08:01:29 +08:00
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
name: {
|
|
|
|
type: %i[string null],
|
|
|
|
},
|
|
|
|
username: {
|
2021-08-13 02:25:17 +08:00
|
|
|
type: :string,
|
2023-01-09 19:18:21 +08:00
|
|
|
},
|
2020-07-09 08:01:29 +08:00
|
|
|
avatar_template: {
|
2021-08-13 02:25:17 +08:00
|
|
|
type: :string,
|
2023-01-09 19:18:21 +08:00
|
|
|
},
|
2020-07-09 08:01:29 +08:00
|
|
|
created_at: {
|
2021-08-13 02:25:17 +08:00
|
|
|
type: :string,
|
2023-01-09 19:18:21 +08:00
|
|
|
},
|
2020-07-09 08:01:29 +08:00
|
|
|
cooked: {
|
2021-08-13 02:25:17 +08:00
|
|
|
type: :string,
|
2023-01-09 19:18:21 +08:00
|
|
|
},
|
2020-07-09 08:01:29 +08:00
|
|
|
post_number: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
post_type: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
updated_at: {
|
|
|
|
type: :string,
|
2023-01-09 19:18:21 +08:00
|
|
|
},
|
2020-07-09 08:01:29 +08:00
|
|
|
reply_count: {
|
|
|
|
type: :integer,
|
2021-08-13 02:25:17 +08:00
|
|
|
},
|
|
|
|
reply_to_post_number: {
|
|
|
|
type: %i[string null],
|
2023-01-09 19:18:21 +08:00
|
|
|
},
|
2021-08-13 02:25:17 +08:00
|
|
|
quote_count: {
|
2020-07-09 08:01:29 +08:00
|
|
|
type: :integer,
|
2023-01-09 19:18:21 +08:00
|
|
|
},
|
2020-07-09 08:01:29 +08:00
|
|
|
incoming_link_count: {
|
|
|
|
type: :integer,
|
2023-01-09 19:18:21 +08:00
|
|
|
},
|
|
|
|
reads: {
|
2020-07-09 08:01:29 +08:00
|
|
|
type: :integer,
|
2023-01-09 19:18:21 +08:00
|
|
|
},
|
2021-08-13 02:25:17 +08:00
|
|
|
readers_count: {
|
2020-07-09 08:01:29 +08:00
|
|
|
type: :integer,
|
2023-01-09 19:18:21 +08:00
|
|
|
},
|
|
|
|
score: {
|
2024-01-10 10:29:35 +08:00
|
|
|
type: :number,
|
2023-01-09 19:18:21 +08:00
|
|
|
},
|
|
|
|
yours: {
|
2021-08-13 02:25:17 +08:00
|
|
|
type: :boolean,
|
2023-01-09 19:18:21 +08:00
|
|
|
},
|
2020-07-09 08:01:29 +08:00
|
|
|
topic_id: {
|
|
|
|
type: :integer,
|
2023-01-09 19:18:21 +08:00
|
|
|
},
|
2020-07-09 08:01:29 +08:00
|
|
|
topic_slug: {
|
2021-08-13 02:25:17 +08:00
|
|
|
type: :string,
|
2020-07-09 08:01:29 +08:00
|
|
|
},
|
2021-08-13 02:25:17 +08:00
|
|
|
display_username: {
|
|
|
|
type: %i[string null],
|
2023-01-09 19:18:21 +08:00
|
|
|
},
|
2021-08-13 02:25:17 +08:00
|
|
|
primary_group_name: {
|
|
|
|
type: %i[string null],
|
2023-01-09 19:18:21 +08:00
|
|
|
},
|
2021-08-13 02:25:17 +08:00
|
|
|
flair_name: {
|
|
|
|
type: %i[string null],
|
2023-01-09 19:18:21 +08:00
|
|
|
},
|
2021-08-13 02:25:17 +08:00
|
|
|
flair_url: {
|
|
|
|
type: %i[string null],
|
2023-01-09 19:18:21 +08:00
|
|
|
},
|
2021-08-13 02:25:17 +08:00
|
|
|
flair_bg_color: {
|
|
|
|
type: %i[string null],
|
2023-01-09 19:18:21 +08:00
|
|
|
},
|
2021-08-13 02:25:17 +08:00
|
|
|
flair_color: {
|
|
|
|
type: %i[string null],
|
2023-01-09 19:18:21 +08:00
|
|
|
},
|
2020-07-09 08:01:29 +08:00
|
|
|
version: {
|
|
|
|
type: :integer,
|
2023-01-09 19:18:21 +08:00
|
|
|
},
|
2020-07-09 08:01:29 +08:00
|
|
|
can_edit: {
|
2020-07-11 02:06:25 +08:00
|
|
|
type: :boolean,
|
2023-01-09 19:18:21 +08:00
|
|
|
},
|
2020-07-09 08:01:29 +08:00
|
|
|
can_delete: {
|
2020-07-11 02:06:25 +08:00
|
|
|
type: :boolean,
|
2023-01-09 19:18:21 +08:00
|
|
|
},
|
2020-07-09 08:01:29 +08:00
|
|
|
can_recover: {
|
2020-07-11 02:06:25 +08:00
|
|
|
type: :boolean,
|
2023-01-09 19:18:21 +08:00
|
|
|
},
|
2020-07-09 08:01:29 +08:00
|
|
|
can_wiki: {
|
2020-07-11 02:06:25 +08:00
|
|
|
type: :boolean,
|
2023-01-09 19:18:21 +08:00
|
|
|
},
|
2020-07-09 08:01:29 +08:00
|
|
|
read: {
|
2020-07-11 02:06:25 +08:00
|
|
|
type: :boolean,
|
2023-01-09 19:18:21 +08:00
|
|
|
},
|
2020-07-09 08:01:29 +08:00
|
|
|
user_title: {
|
2021-08-13 02:25:17 +08:00
|
|
|
type: %i[string null],
|
2023-01-09 19:18:21 +08:00
|
|
|
},
|
2020-07-09 08:01:29 +08:00
|
|
|
actions_summary: {
|
|
|
|
type: :array,
|
2023-01-09 19:18:21 +08:00
|
|
|
items: {
|
2020-07-09 08:01:29 +08:00
|
|
|
type: :object,
|
|
|
|
properties: {
|
2023-01-09 19:18:21 +08:00
|
|
|
id: {
|
2020-07-09 08:27:19 +08:00
|
|
|
type: :integer,
|
2023-01-09 19:18:21 +08:00
|
|
|
},
|
2020-07-09 08:01:29 +08:00
|
|
|
can_act: {
|
2020-07-11 02:06:25 +08:00
|
|
|
type: :boolean,
|
2023-01-09 19:18:21 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
moderator: {
|
2020-07-11 02:06:25 +08:00
|
|
|
type: :boolean,
|
2023-01-09 19:18:21 +08:00
|
|
|
},
|
|
|
|
admin: {
|
2020-07-11 02:06:25 +08:00
|
|
|
type: :boolean,
|
2023-01-09 19:18:21 +08:00
|
|
|
},
|
|
|
|
staff: {
|
2020-07-09 08:01:29 +08:00
|
|
|
type: :boolean,
|
2021-08-13 02:25:17 +08:00
|
|
|
},
|
2020-07-09 08:01:29 +08:00
|
|
|
user_id: {
|
2021-08-13 02:25:17 +08:00
|
|
|
type: :integer,
|
2023-01-09 19:18:21 +08:00
|
|
|
},
|
2021-08-13 02:25:17 +08:00
|
|
|
hidden: {
|
|
|
|
type: :boolean,
|
2023-01-09 19:18:21 +08:00
|
|
|
},
|
2021-08-13 02:25:17 +08:00
|
|
|
trust_level: {
|
2020-07-09 08:27:19 +08:00
|
|
|
type: :integer,
|
2023-01-09 19:18:21 +08:00
|
|
|
},
|
2021-08-13 02:25:17 +08:00
|
|
|
deleted_at: {
|
|
|
|
type: %i[string null],
|
2020-07-09 08:01:29 +08:00
|
|
|
},
|
|
|
|
user_deleted: {
|
|
|
|
type: :boolean,
|
2023-01-09 19:18:21 +08:00
|
|
|
},
|
|
|
|
edit_reason: {
|
2021-08-13 02:25:17 +08:00
|
|
|
type: %i[string null],
|
2023-01-09 19:18:21 +08:00
|
|
|
},
|
2020-07-09 08:01:29 +08:00
|
|
|
can_view_edit_history: {
|
|
|
|
type: :boolean,
|
|
|
|
},
|
|
|
|
wiki: {
|
|
|
|
type: :boolean,
|
|
|
|
},
|
|
|
|
reviewable_id: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
reviewable_score_count: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
reviewable_score_pending_count: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
2023-01-09 19:18:21 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-07-09 08:01:29 +08:00
|
|
|
id: {
|
|
|
|
type: :integer,
|
2023-01-09 19:18:21 +08:00
|
|
|
},
|
2020-07-09 08:01:29 +08:00
|
|
|
}
|
2023-01-09 19:18:21 +08:00
|
|
|
|
2020-07-09 08:01:29 +08:00
|
|
|
let(:post_body) { { "post_ids[]": 1 } }
|
|
|
|
let(:id) { Fabricate(:topic).id }
|
|
|
|
|
|
|
|
run_test!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
path "/t/{id}.json" do
|
|
|
|
get "Get a single topic" do
|
|
|
|
tags "Topics"
|
2021-09-03 21:39:29 +08:00
|
|
|
operationId "getTopic"
|
2020-07-09 08:01:29 +08:00
|
|
|
consumes "application/json"
|
|
|
|
parameter name: "Api-Key", in: :header, type: :string, required: true
|
|
|
|
parameter name: "Api-Username", in: :header, type: :string, required: true
|
|
|
|
parameter name: :id, in: :path, schema: { type: :string }
|
2022-02-11 10:01:19 +08:00
|
|
|
expected_request_schema = nil
|
2020-07-09 08:01:29 +08:00
|
|
|
|
|
|
|
produces "application/json"
|
|
|
|
response "200", "specific posts" do
|
|
|
|
let(:id) { Fabricate(:topic).id }
|
|
|
|
|
2022-02-11 10:01:19 +08:00
|
|
|
expected_response_schema = load_spec_schema("topic_show_response")
|
|
|
|
schema expected_response_schema
|
|
|
|
|
|
|
|
it_behaves_like "a JSON endpoint", 200 do
|
|
|
|
let(:expected_response_schema) { expected_response_schema }
|
|
|
|
let(:expected_request_schema) { expected_request_schema }
|
|
|
|
end
|
2020-07-09 08:01:29 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
delete "Remove a topic" do
|
|
|
|
tags "Topics"
|
2021-09-03 21:39:29 +08:00
|
|
|
operationId "removeTopic"
|
2020-07-09 08:01:29 +08:00
|
|
|
consumes "application/json"
|
|
|
|
parameter name: "Api-Key", in: :header, type: :string, required: true
|
|
|
|
parameter name: "Api-Username", in: :header, type: :string, required: true
|
|
|
|
parameter name: :id, in: :path, schema: { type: :string }
|
|
|
|
response "200", "specific posts" do
|
|
|
|
let!(:post) { Fabricate(:post) }
|
|
|
|
let(:id) { post.topic.id }
|
|
|
|
|
|
|
|
run_test!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
path "/t/-/{id}.json" do
|
|
|
|
put "Update a topic" do
|
|
|
|
tags "Topics"
|
2021-09-03 21:39:29 +08:00
|
|
|
operationId "updateTopic"
|
2020-07-09 08:01:29 +08:00
|
|
|
consumes "application/json"
|
|
|
|
parameter name: "Api-Key", in: :header, type: :string, required: true
|
|
|
|
parameter name: "Api-Username", in: :header, type: :string, required: true
|
|
|
|
parameter name: :id, in: :path, schema: { type: :string }
|
|
|
|
|
|
|
|
parameter name: :post_body,
|
|
|
|
in: :body,
|
|
|
|
schema: {
|
|
|
|
type: :object,
|
|
|
|
properties: {
|
|
|
|
topic: {
|
|
|
|
type: :object,
|
|
|
|
properties: {
|
|
|
|
title: {
|
|
|
|
type: :string,
|
2020-07-09 08:27:19 +08:00
|
|
|
},
|
|
|
|
category_id: {
|
|
|
|
type: :integer,
|
2020-07-09 08:01:29 +08:00
|
|
|
},
|
|
|
|
},
|
2023-01-09 19:18:21 +08:00
|
|
|
},
|
2020-07-09 08:01:29 +08:00
|
|
|
},
|
|
|
|
}
|
2023-01-09 19:18:21 +08:00
|
|
|
|
2020-07-09 08:01:29 +08:00
|
|
|
produces "application/json"
|
|
|
|
response "200", "topic updated" do
|
|
|
|
schema type: :object,
|
|
|
|
properties: {
|
|
|
|
basic_topic: {
|
|
|
|
type: :object,
|
|
|
|
properties: {
|
|
|
|
id: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
title: {
|
|
|
|
type: :string,
|
|
|
|
},
|
|
|
|
fancy_title: {
|
|
|
|
type: :string,
|
|
|
|
},
|
|
|
|
slug: {
|
|
|
|
type: :string,
|
|
|
|
},
|
|
|
|
posts_count: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
2023-01-09 19:18:21 +08:00
|
|
|
},
|
|
|
|
},
|
2020-07-09 08:01:29 +08:00
|
|
|
}
|
2023-01-09 19:18:21 +08:00
|
|
|
|
2020-07-09 08:01:29 +08:00
|
|
|
let(:post_body) { { title: "New topic title" } }
|
|
|
|
let!(:post) { Fabricate(:post) }
|
|
|
|
let(:id) { post.topic.id }
|
|
|
|
|
|
|
|
run_test! do |response|
|
|
|
|
data = JSON.parse(response.body)
|
|
|
|
expect(data["basic_topic"]["title"]).to eq("New topic title")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
path "/t/{id}/invite.json" do
|
|
|
|
post "Invite to topic" do
|
|
|
|
tags "Topics", "Invites"
|
2021-09-03 21:39:29 +08:00
|
|
|
operationId "inviteToTopic"
|
2020-07-09 08:01:29 +08:00
|
|
|
consumes "application/json"
|
|
|
|
parameter name: "Api-Key", in: :header, type: :string, required: true
|
|
|
|
parameter name: "Api-Username", in: :header, type: :string, required: true
|
|
|
|
parameter name: :id, in: :path, schema: { type: :string }
|
|
|
|
|
|
|
|
parameter name: :request_body,
|
|
|
|
in: :body,
|
|
|
|
schema: {
|
|
|
|
type: :object,
|
|
|
|
properties: {
|
|
|
|
user: {
|
|
|
|
type: :string,
|
|
|
|
},
|
|
|
|
email: {
|
|
|
|
type: :string,
|
|
|
|
},
|
2023-01-09 19:18:21 +08:00
|
|
|
},
|
2020-07-09 08:01:29 +08:00
|
|
|
}
|
2023-01-09 19:18:21 +08:00
|
|
|
|
2020-07-09 08:01:29 +08:00
|
|
|
produces "application/json"
|
|
|
|
response "200", "topic updated" do
|
|
|
|
schema type: :object,
|
|
|
|
properties: {
|
|
|
|
user: {
|
|
|
|
type: :object,
|
|
|
|
properties: {
|
|
|
|
id: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
username: {
|
|
|
|
type: :string,
|
|
|
|
},
|
|
|
|
name: {
|
|
|
|
type: :string,
|
|
|
|
},
|
|
|
|
avatar_template: {
|
|
|
|
type: :string,
|
|
|
|
},
|
|
|
|
},
|
2023-01-09 19:18:21 +08:00
|
|
|
},
|
2020-07-09 08:01:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
let(:username) { Fabricate(:user).username }
|
|
|
|
let(:request_body) { { user: username } }
|
2022-10-11 00:21:51 +08:00
|
|
|
let(:id) { Fabricate(:private_message_topic).id }
|
2020-07-09 08:01:29 +08:00
|
|
|
|
|
|
|
run_test! do |response|
|
|
|
|
data = JSON.parse(response.body)
|
|
|
|
expect(data["user"]["username"]).to eq(username)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
path "/t/{id}/bookmark.json" do
|
|
|
|
put "Bookmark topic" do
|
|
|
|
tags "Topics"
|
2021-09-03 21:39:29 +08:00
|
|
|
operationId "bookmarkTopic"
|
2020-07-09 08:01:29 +08:00
|
|
|
consumes "application/json"
|
|
|
|
parameter name: "Api-Key", in: :header, type: :string, required: true
|
|
|
|
parameter name: "Api-Username", in: :header, type: :string, required: true
|
|
|
|
parameter name: :id, in: :path, schema: { type: :string }
|
|
|
|
|
|
|
|
produces "application/json"
|
|
|
|
response "200", "topic updated" do
|
|
|
|
let!(:post) { Fabricate(:post) }
|
|
|
|
let(:id) { post.topic.id }
|
|
|
|
|
|
|
|
run_test!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
path "/t/{id}/status.json" do
|
|
|
|
put "Update the status of a topic" do
|
|
|
|
tags "Topics"
|
2021-09-03 21:39:29 +08:00
|
|
|
operationId "updateTopicStatus"
|
2020-07-09 08:01:29 +08:00
|
|
|
consumes "application/json"
|
|
|
|
parameter name: "Api-Key", in: :header, type: :string, required: true
|
|
|
|
parameter name: "Api-Username", in: :header, type: :string, required: true
|
|
|
|
parameter name: :id, in: :path, schema: { type: :string }
|
|
|
|
|
|
|
|
parameter name: :request_body,
|
|
|
|
in: :body,
|
|
|
|
schema: {
|
|
|
|
type: :object,
|
|
|
|
properties: {
|
|
|
|
status: {
|
|
|
|
type: :string,
|
|
|
|
enum: %w[closed pinned pinned_globally archived visible],
|
|
|
|
},
|
|
|
|
enabled: {
|
|
|
|
type: :string,
|
|
|
|
enum: %w[true false],
|
|
|
|
},
|
|
|
|
until: {
|
|
|
|
type: :string,
|
|
|
|
description: "Only required for `pinned` and `pinned_globally`",
|
|
|
|
example: "2030-12-31",
|
|
|
|
},
|
2023-01-09 19:18:21 +08:00
|
|
|
},
|
2020-07-09 08:01:29 +08:00
|
|
|
required: %w[status enabled],
|
|
|
|
}
|
2023-01-09 19:18:21 +08:00
|
|
|
|
2020-07-09 08:01:29 +08:00
|
|
|
produces "application/json"
|
|
|
|
response "200", "topic updated" do
|
|
|
|
schema type: :object,
|
|
|
|
properties: {
|
2020-10-26 22:55:22 +08:00
|
|
|
success: {
|
|
|
|
type: :string,
|
|
|
|
example: "OK",
|
2021-08-13 02:25:17 +08:00
|
|
|
},
|
|
|
|
topic_status_update: {
|
|
|
|
type: %i[string null],
|
2023-01-09 19:18:21 +08:00
|
|
|
},
|
2020-07-09 08:01:29 +08:00
|
|
|
}
|
2023-01-09 19:18:21 +08:00
|
|
|
|
2020-07-09 08:01:29 +08:00
|
|
|
let(:request_body) { { status: "closed", enabled: "true" } }
|
|
|
|
let(:id) { Fabricate(:topic).id }
|
|
|
|
|
|
|
|
run_test!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
path "/latest.json" do
|
|
|
|
get "Get the latest topics" do
|
|
|
|
tags "Topics"
|
2021-09-03 21:39:29 +08:00
|
|
|
operationId "listLatestTopics"
|
2020-07-09 08:01:29 +08:00
|
|
|
consumes "application/json"
|
|
|
|
parameter name: "Api-Key", in: :header, type: :string, required: true
|
|
|
|
parameter name: "Api-Username", in: :header, type: :string, required: true
|
2020-07-09 08:27:19 +08:00
|
|
|
parameter(
|
|
|
|
name: :order,
|
2020-07-09 08:01:29 +08:00
|
|
|
in: :query,
|
|
|
|
type: :string,
|
2020-07-09 08:27:19 +08:00
|
|
|
description:
|
|
|
|
"Enum: `default`, `created`, `activity`, `views`, `posts`, `category`, `likes`, `op_likes`, `posters`",
|
|
|
|
)
|
|
|
|
parameter(
|
|
|
|
name: :ascending,
|
2020-07-09 08:01:29 +08:00
|
|
|
in: :query,
|
|
|
|
type: :string,
|
2020-07-09 08:27:19 +08:00
|
|
|
description: "Defaults to `desc`, add `ascending=true` to sort asc",
|
|
|
|
)
|
2023-01-09 19:18:21 +08:00
|
|
|
|
2020-07-09 08:01:29 +08:00
|
|
|
produces "application/json"
|
|
|
|
response "200", "topic updated" do
|
|
|
|
schema type: :object,
|
|
|
|
properties: {
|
|
|
|
users: {
|
|
|
|
type: :array,
|
|
|
|
items: {
|
|
|
|
type: :object,
|
|
|
|
properties: {
|
|
|
|
id: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
username: {
|
|
|
|
type: :string,
|
2021-08-13 02:25:17 +08:00
|
|
|
},
|
|
|
|
name: {
|
|
|
|
type: %i[string null],
|
2020-07-09 08:01:29 +08:00
|
|
|
},
|
|
|
|
avatar_template: {
|
|
|
|
type: :string,
|
|
|
|
},
|
2023-01-09 19:18:21 +08:00
|
|
|
},
|
2020-07-09 08:01:29 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
primary_groups: {
|
|
|
|
type: :array,
|
2022-10-26 09:05:15 +08:00
|
|
|
items: {
|
|
|
|
},
|
2020-07-09 08:01:29 +08:00
|
|
|
},
|
|
|
|
topic_list: {
|
|
|
|
type: :object,
|
|
|
|
properties: {
|
|
|
|
can_create_topic: {
|
|
|
|
type: :boolean,
|
2021-08-13 02:25:17 +08:00
|
|
|
},
|
|
|
|
draft: {
|
|
|
|
type: %i[string null],
|
2020-07-09 08:01:29 +08:00
|
|
|
},
|
|
|
|
draft_key: {
|
|
|
|
type: :string,
|
|
|
|
},
|
|
|
|
draft_sequence: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
per_page: {
|
|
|
|
type: :integer,
|
2023-01-09 19:18:21 +08:00
|
|
|
},
|
2020-07-09 08:01:29 +08:00
|
|
|
topics: {
|
|
|
|
type: :array,
|
|
|
|
items: {
|
|
|
|
type: :object,
|
|
|
|
properties: {
|
|
|
|
id: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
title: {
|
|
|
|
type: :string,
|
|
|
|
},
|
|
|
|
fancy_title: {
|
2020-07-10 07:39:05 +08:00
|
|
|
type: :string,
|
2020-07-09 08:01:29 +08:00
|
|
|
},
|
|
|
|
slug: {
|
|
|
|
type: :string,
|
|
|
|
},
|
|
|
|
posts_count: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
reply_count: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
highest_post_number: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
image_url: {
|
|
|
|
type: :string,
|
|
|
|
},
|
|
|
|
created_at: {
|
|
|
|
type: :string,
|
|
|
|
},
|
|
|
|
last_posted_at: {
|
2020-10-26 22:55:22 +08:00
|
|
|
type: :string,
|
2020-07-09 08:01:29 +08:00
|
|
|
},
|
|
|
|
bumped: {
|
|
|
|
type: :boolean,
|
|
|
|
},
|
|
|
|
bumped_at: {
|
|
|
|
type: :string,
|
|
|
|
},
|
|
|
|
archetype: {
|
2020-07-11 02:06:25 +08:00
|
|
|
type: :string,
|
2020-07-09 08:01:29 +08:00
|
|
|
},
|
|
|
|
unseen: {
|
|
|
|
type: :boolean,
|
|
|
|
},
|
|
|
|
last_read_post_number: {
|
2021-07-05 14:17:31 +08:00
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
unread_posts: {
|
2020-07-09 08:01:29 +08:00
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
pinned: {
|
|
|
|
type: :boolean,
|
2021-08-13 02:25:17 +08:00
|
|
|
},
|
|
|
|
unpinned: {
|
|
|
|
type: %i[string null],
|
2020-07-09 08:01:29 +08:00
|
|
|
},
|
|
|
|
visible: {
|
|
|
|
type: :boolean,
|
|
|
|
},
|
|
|
|
closed: {
|
|
|
|
type: :boolean,
|
|
|
|
},
|
|
|
|
archived: {
|
|
|
|
type: :boolean,
|
|
|
|
},
|
|
|
|
notification_level: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
bookmarked: {
|
|
|
|
type: :boolean,
|
|
|
|
},
|
|
|
|
liked: {
|
|
|
|
type: :boolean,
|
|
|
|
},
|
|
|
|
views: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
like_count: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
has_summary: {
|
|
|
|
type: :boolean,
|
|
|
|
},
|
|
|
|
last_poster_username: {
|
|
|
|
type: :string,
|
|
|
|
},
|
|
|
|
category_id: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
op_like_count: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
pinned_globally: {
|
2021-08-13 02:25:17 +08:00
|
|
|
type: :boolean,
|
|
|
|
},
|
|
|
|
featured_link: {
|
|
|
|
type: %i[string null],
|
2023-01-09 19:18:21 +08:00
|
|
|
},
|
2020-07-09 08:01:29 +08:00
|
|
|
posters: {
|
|
|
|
type: :array,
|
|
|
|
items: {
|
|
|
|
type: :object,
|
|
|
|
properties: {
|
|
|
|
extras: {
|
|
|
|
type: :string,
|
|
|
|
},
|
|
|
|
description: {
|
2021-08-13 02:25:17 +08:00
|
|
|
type: :string,
|
|
|
|
},
|
2020-07-09 08:01:29 +08:00
|
|
|
user_id: {
|
|
|
|
type: :integer,
|
2023-01-09 19:18:21 +08:00
|
|
|
},
|
2021-08-13 02:25:17 +08:00
|
|
|
primary_group_id: {
|
2024-06-27 10:44:39 +08:00
|
|
|
type: %i[integer null],
|
2020-07-09 08:01:29 +08:00
|
|
|
},
|
|
|
|
},
|
2023-01-09 19:18:21 +08:00
|
|
|
},
|
2020-07-09 08:01:29 +08:00
|
|
|
},
|
2023-01-09 19:18:21 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-07-09 08:01:29 +08:00
|
|
|
}
|
2023-01-09 19:18:21 +08:00
|
|
|
|
2020-07-09 08:01:29 +08:00
|
|
|
let(:order) { "default" }
|
|
|
|
let(:ascending) { "false" }
|
|
|
|
|
|
|
|
run_test!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-08-13 18:22:15 +08:00
|
|
|
path "/top.json" do
|
|
|
|
get "Get the top topics filtered by period" do
|
2020-07-09 08:01:29 +08:00
|
|
|
tags "Topics"
|
2021-09-03 21:39:29 +08:00
|
|
|
operationId "listTopTopics"
|
2020-07-09 08:01:29 +08:00
|
|
|
consumes "application/json"
|
|
|
|
parameter name: "Api-Key", in: :header, type: :string, required: true
|
|
|
|
parameter name: "Api-Username", in: :header, type: :string, required: true
|
2020-07-09 08:27:19 +08:00
|
|
|
parameter(
|
2021-08-13 18:22:15 +08:00
|
|
|
name: :period,
|
|
|
|
in: :query,
|
2020-07-09 08:01:29 +08:00
|
|
|
type: :string,
|
2020-07-09 08:27:19 +08:00
|
|
|
description: "Enum: `all`, `yearly`, `quarterly`, `monthly`, `weekly`, `daily`",
|
|
|
|
)
|
2023-01-09 19:18:21 +08:00
|
|
|
|
2020-07-09 08:01:29 +08:00
|
|
|
produces "application/json"
|
2020-09-05 06:24:43 +08:00
|
|
|
response "200", "response" do
|
2020-07-09 08:01:29 +08:00
|
|
|
schema type: :object,
|
|
|
|
properties: {
|
|
|
|
users: {
|
|
|
|
type: :array,
|
|
|
|
items: {
|
|
|
|
type: :object,
|
|
|
|
properties: {
|
|
|
|
id: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
username: {
|
|
|
|
type: :string,
|
|
|
|
},
|
|
|
|
name: {
|
|
|
|
type: :string,
|
|
|
|
},
|
|
|
|
avatar_template: {
|
|
|
|
type: :string,
|
|
|
|
},
|
2023-01-09 19:18:21 +08:00
|
|
|
},
|
2020-07-09 08:01:29 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
primary_groups: {
|
|
|
|
type: :array,
|
2022-10-26 09:05:15 +08:00
|
|
|
items: {
|
|
|
|
},
|
2020-07-09 08:01:29 +08:00
|
|
|
},
|
|
|
|
topic_list: {
|
|
|
|
type: :object,
|
|
|
|
properties: {
|
|
|
|
can_create_topic: {
|
|
|
|
type: :boolean,
|
2021-08-13 02:25:17 +08:00
|
|
|
},
|
|
|
|
draft: {
|
|
|
|
type: %i[string null],
|
2020-07-09 08:01:29 +08:00
|
|
|
},
|
|
|
|
draft_key: {
|
|
|
|
type: :string,
|
|
|
|
},
|
|
|
|
draft_sequence: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
for_period: {
|
|
|
|
type: :string,
|
|
|
|
},
|
|
|
|
per_page: {
|
|
|
|
type: :integer,
|
2023-01-09 19:18:21 +08:00
|
|
|
},
|
2020-07-09 08:01:29 +08:00
|
|
|
topics: {
|
|
|
|
type: :array,
|
|
|
|
items: {
|
|
|
|
type: :object,
|
|
|
|
properties: {
|
|
|
|
id: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
title: {
|
|
|
|
type: :string,
|
|
|
|
},
|
|
|
|
fancy_title: {
|
2022-02-11 10:01:19 +08:00
|
|
|
type: :string,
|
2020-07-09 08:01:29 +08:00
|
|
|
},
|
|
|
|
slug: {
|
|
|
|
type: :string,
|
|
|
|
},
|
|
|
|
posts_count: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
reply_count: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
highest_post_number: {
|
2021-08-13 02:25:17 +08:00
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
image_url: {
|
2020-07-09 08:01:29 +08:00
|
|
|
type: %i[string null],
|
|
|
|
},
|
|
|
|
created_at: {
|
|
|
|
type: :string,
|
|
|
|
},
|
|
|
|
last_posted_at: {
|
2022-02-11 10:01:19 +08:00
|
|
|
type: :string,
|
2020-07-09 08:01:29 +08:00
|
|
|
},
|
|
|
|
bumped: {
|
|
|
|
type: :boolean,
|
|
|
|
},
|
|
|
|
bumped_at: {
|
|
|
|
type: :string,
|
|
|
|
},
|
|
|
|
archetype: {
|
2022-02-11 10:01:19 +08:00
|
|
|
type: :string,
|
2020-07-09 08:01:29 +08:00
|
|
|
},
|
|
|
|
unseen: {
|
|
|
|
type: :boolean,
|
|
|
|
},
|
|
|
|
last_read_post_number: {
|
2021-07-05 14:17:31 +08:00
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
unread_posts: {
|
2020-07-09 08:01:29 +08:00
|
|
|
type: :integer,
|
2023-01-09 19:18:21 +08:00
|
|
|
},
|
2020-07-09 08:01:29 +08:00
|
|
|
pinned: {
|
2020-07-11 02:06:25 +08:00
|
|
|
type: :boolean,
|
2023-01-09 19:18:21 +08:00
|
|
|
},
|
2020-07-09 08:01:29 +08:00
|
|
|
unpinned: {
|
2020-07-11 02:06:25 +08:00
|
|
|
type: :boolean,
|
2023-01-09 19:18:21 +08:00
|
|
|
},
|
2020-07-09 08:01:29 +08:00
|
|
|
visible: {
|
2020-07-11 02:06:25 +08:00
|
|
|
type: :boolean,
|
2023-01-09 19:18:21 +08:00
|
|
|
},
|
2020-07-11 02:06:25 +08:00
|
|
|
closed: {
|
|
|
|
type: :boolean,
|
2020-07-09 08:01:29 +08:00
|
|
|
},
|
|
|
|
archived: {
|
2020-07-11 02:06:25 +08:00
|
|
|
type: :boolean,
|
2023-01-09 19:18:21 +08:00
|
|
|
},
|
2020-07-09 08:01:29 +08:00
|
|
|
notification_level: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
bookmarked: {
|
|
|
|
type: :boolean,
|
|
|
|
},
|
|
|
|
liked: {
|
|
|
|
type: :boolean,
|
|
|
|
},
|
|
|
|
views: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
like_count: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
has_summary: {
|
|
|
|
type: :boolean,
|
|
|
|
},
|
|
|
|
last_poster_username: {
|
|
|
|
type: :string,
|
|
|
|
},
|
|
|
|
category_id: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
op_like_count: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
pinned_globally: {
|
2021-08-13 02:25:17 +08:00
|
|
|
type: :boolean,
|
|
|
|
},
|
|
|
|
featured_link: {
|
|
|
|
type: %i[string null],
|
2023-01-09 19:18:21 +08:00
|
|
|
},
|
2020-07-09 08:01:29 +08:00
|
|
|
posters: {
|
|
|
|
type: :array,
|
|
|
|
items: {
|
|
|
|
type: :object,
|
|
|
|
properties: {
|
2021-08-13 02:25:17 +08:00
|
|
|
extras: {
|
|
|
|
type: %i[string null],
|
2020-07-09 08:01:29 +08:00
|
|
|
},
|
|
|
|
description: {
|
|
|
|
type: :string,
|
|
|
|
},
|
|
|
|
user_id: {
|
|
|
|
type: :integer,
|
2021-08-13 02:25:17 +08:00
|
|
|
},
|
|
|
|
primary_group_id: {
|
2024-06-27 10:44:39 +08:00
|
|
|
type: %i[integer null],
|
2020-07-09 08:01:29 +08:00
|
|
|
},
|
2023-01-09 19:18:21 +08:00
|
|
|
},
|
2020-07-09 08:01:29 +08:00
|
|
|
},
|
2023-01-09 19:18:21 +08:00
|
|
|
},
|
2020-07-09 08:01:29 +08:00
|
|
|
},
|
2023-01-09 19:18:21 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-07-09 08:01:29 +08:00
|
|
|
}
|
2023-01-09 19:18:21 +08:00
|
|
|
|
2021-08-13 18:22:15 +08:00
|
|
|
let(:period) { "all" }
|
2020-07-09 08:01:29 +08:00
|
|
|
|
|
|
|
run_test!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-07-10 07:39:05 +08:00
|
|
|
path "/t/{id}/notifications.json" do
|
|
|
|
post "Set notification level" do
|
|
|
|
tags "Topics"
|
2021-09-03 21:39:29 +08:00
|
|
|
operationId "setNotificationLevel"
|
2020-07-10 07:39:05 +08:00
|
|
|
consumes "application/json"
|
|
|
|
parameter name: "Api-Key", in: :header, type: :string, required: true
|
|
|
|
parameter name: "Api-Username", in: :header, type: :string, required: true
|
|
|
|
parameter name: :id, in: :path, schema: { type: :string }
|
|
|
|
|
|
|
|
parameter name: :request_body,
|
|
|
|
in: :body,
|
|
|
|
schema: {
|
|
|
|
type: :object,
|
|
|
|
properties: {
|
|
|
|
notification_level: {
|
|
|
|
type: :string,
|
|
|
|
enum: %w[0 1 2 3],
|
|
|
|
},
|
2023-01-09 19:18:21 +08:00
|
|
|
},
|
2020-07-10 07:39:05 +08:00
|
|
|
required: ["notification_level"],
|
|
|
|
}
|
2023-01-09 19:18:21 +08:00
|
|
|
|
2020-07-10 07:39:05 +08:00
|
|
|
produces "application/json"
|
|
|
|
response "200", "topic updated" do
|
2020-10-26 22:55:22 +08:00
|
|
|
schema type: :object, properties: { success: { type: :string, example: "OK" } }
|
2023-01-09 19:18:21 +08:00
|
|
|
|
2020-07-10 07:39:05 +08:00
|
|
|
let(:request_body) { { notification_level: "3" } }
|
|
|
|
let(:id) { Fabricate(:topic).id }
|
|
|
|
|
|
|
|
run_test!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-07-11 02:06:25 +08:00
|
|
|
path "/t/{id}/change-timestamp.json" do
|
|
|
|
put "Update topic timestamp" do
|
|
|
|
tags "Topics"
|
2021-09-03 21:39:29 +08:00
|
|
|
operationId "updateTopicTimestamp"
|
2020-07-11 02:06:25 +08:00
|
|
|
consumes "application/json"
|
|
|
|
parameter name: "Api-Key", in: :header, type: :string, required: true
|
|
|
|
parameter name: "Api-Username", in: :header, type: :string, required: true
|
|
|
|
parameter name: :id, in: :path, schema: { type: :string }
|
|
|
|
|
|
|
|
parameter name: :request_body,
|
|
|
|
in: :body,
|
|
|
|
schema: {
|
|
|
|
type: :object,
|
|
|
|
properties: {
|
|
|
|
timestamp: {
|
|
|
|
type: :string,
|
|
|
|
example: "1594291380",
|
|
|
|
},
|
2023-01-09 19:18:21 +08:00
|
|
|
},
|
2020-07-11 02:06:25 +08:00
|
|
|
required: ["timestamp"],
|
|
|
|
}
|
2023-01-09 19:18:21 +08:00
|
|
|
|
2020-07-11 02:06:25 +08:00
|
|
|
produces "application/json"
|
|
|
|
response "200", "topic updated" do
|
2020-10-26 22:55:22 +08:00
|
|
|
schema type: :object, properties: { success: { type: :string, example: "OK" } }
|
2023-01-09 19:18:21 +08:00
|
|
|
|
2020-07-11 02:06:25 +08:00
|
|
|
let(:request_body) { { timestamp: "1594291380" } }
|
|
|
|
let!(:post) { Fabricate(:post) }
|
|
|
|
let(:id) { post.topic.id }
|
|
|
|
|
|
|
|
run_test!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
path "/t/{id}/timer.json" do
|
|
|
|
post "Create topic timer" do
|
|
|
|
tags "Topics"
|
2021-09-03 21:39:29 +08:00
|
|
|
operationId "createTopicTimer"
|
2020-07-11 02:06:25 +08:00
|
|
|
consumes "application/json"
|
|
|
|
parameter name: "Api-Key", in: :header, type: :string, required: true
|
|
|
|
parameter name: "Api-Username", in: :header, type: :string, required: true
|
|
|
|
parameter name: :id, in: :path, schema: { type: :string }
|
|
|
|
|
|
|
|
parameter name: :request_body,
|
|
|
|
in: :body,
|
|
|
|
schema: {
|
|
|
|
type: :object,
|
|
|
|
properties: {
|
|
|
|
time: {
|
|
|
|
type: :string,
|
|
|
|
example: "",
|
|
|
|
},
|
|
|
|
status_type: {
|
|
|
|
type: :string,
|
|
|
|
},
|
|
|
|
based_on_last_post: {
|
|
|
|
type: :boolean,
|
|
|
|
},
|
|
|
|
category_id: {
|
|
|
|
type: :integer,
|
2023-01-09 19:18:21 +08:00
|
|
|
},
|
|
|
|
},
|
2020-07-11 02:06:25 +08:00
|
|
|
}
|
2023-01-09 19:18:21 +08:00
|
|
|
|
2020-07-11 02:06:25 +08:00
|
|
|
produces "application/json"
|
|
|
|
response "200", "topic updated" do
|
|
|
|
schema type: :object,
|
|
|
|
properties: {
|
2020-10-26 22:55:22 +08:00
|
|
|
success: {
|
|
|
|
type: :string,
|
|
|
|
example: "OK",
|
2020-07-11 02:06:25 +08:00
|
|
|
},
|
|
|
|
execute_at: {
|
2021-08-13 02:25:17 +08:00
|
|
|
type: :string,
|
|
|
|
},
|
|
|
|
duration: {
|
2020-07-11 02:06:25 +08:00
|
|
|
type: %i[string null],
|
|
|
|
},
|
|
|
|
based_on_last_post: {
|
|
|
|
type: :boolean,
|
|
|
|
},
|
|
|
|
closed: {
|
|
|
|
type: :boolean,
|
2021-08-13 02:25:17 +08:00
|
|
|
},
|
|
|
|
category_id: {
|
2024-06-27 10:44:39 +08:00
|
|
|
type: %i[integer null],
|
2023-01-09 19:18:21 +08:00
|
|
|
},
|
2020-07-11 02:06:25 +08:00
|
|
|
}
|
2023-01-09 19:18:21 +08:00
|
|
|
|
2020-12-09 01:13:45 +08:00
|
|
|
let(:request_body) { { time: Time.current + 1.day, status_type: "close" } }
|
2020-07-11 02:06:25 +08:00
|
|
|
let!(:topic_post) { Fabricate(:post) }
|
|
|
|
let(:id) { topic_post.topic.id }
|
|
|
|
|
|
|
|
run_test!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-02-11 10:01:19 +08:00
|
|
|
path "/t/external_id/{external_id}.json" do
|
|
|
|
get "Get topic by external_id" do
|
|
|
|
tags "Topics"
|
|
|
|
operationId "getTopicByExternalId"
|
|
|
|
consumes "application/json"
|
|
|
|
parameter name: :external_id, in: :path, type: :string, required: true
|
|
|
|
expected_request_schema = nil
|
|
|
|
|
|
|
|
produces "application/json"
|
|
|
|
response "301", "redirects to /t/{topic_id}.json" do
|
|
|
|
expected_response_schema = nil
|
|
|
|
schema expected_response_schema
|
|
|
|
|
|
|
|
let(:topic) { Fabricate(:topic, external_id: "external_id_1") }
|
|
|
|
let(:external_id) { topic.external_id }
|
|
|
|
|
2022-03-18 09:27:51 +08:00
|
|
|
run_test! { |response| expect(response).to redirect_to(topic.relative_url + ".json") }
|
2022-02-11 10:01:19 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-07-09 08:01:29 +08:00
|
|
|
end
|