Skip to content

Commit

Permalink
Add an endpoint to return events for a content ID
Browse files Browse the repository at this point in the history
  • Loading branch information
pezholio committed Dec 13, 2024
1 parent 61fde85 commit b0d56d6
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
7 changes: 7 additions & 0 deletions app/controllers/v2/content_items_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ def linkables
).call
end

def events
render json: Queries::GetEvents.call(
content_id: path_params[:content_id],
action: query_params[:action],
)
end

def host_content
results = GetHostContentService.new(
path_params[:content_id],
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def content_id_constraint(request)
get "/content/:content_id/host-content/:host_content_id", to: "content_items#host_content_item"
# Point legacy `embedded` endpoint to `host_content` endpoint
get "/content/:content_id/embedded", to: "content_items#host_content"
get "/content/:content_id/events", to: "content_items#events"
post "/content/:content_id/publish", to: "content_items#publish"
post "/content/:content_id/republish", to: "content_items#republish"
post "/content/:content_id/unpublish", to: "content_items#unpublish"
Expand Down
16 changes: 16 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ message queue for other apps (e.g. `email-alert-service`) to consume.
- [`GET /v2/content/:content_id`](#get-v2contentcontent_id)
- [`GET /v2/content/:content_id/host-content`](#get-v2contentcontent_idhost-content)
- [`GET /v2/content/:content_id/host-content/:host_content_id`](#get-v2contentcontent_idhost-contenthost_content_id)
- [`GET /v2/content/:content_id/events`](#get-v2contentcontent_idevents)
- [`PATCH /v2/links/:content_id`](#patch-v2linkscontent_id)
- [`GET /v2/links/:content_id`](#get-v2linkscontent_id)
- [`GET /v2/expanded-links/:content_id`](#get-v2expanded-linkscontent_id)
Expand Down Expand Up @@ -429,6 +430,21 @@ included within the response.
- Specify a particular edition of this document
- If omitted the most recent edition.

## `GET /v2/content/:content_id/events`

Retrieves a list of all events for a given `:content_id`

### Path parameters

- [`content_id`](model.md#content_id)
- Identifies the document to return events for

### Query parameters

- `action` *(optional)*
- Specify what action type to filter for
- If omitted, returns all actions

## `GET /v2/content/:content_id/host-content`

Retrieves a summary list of content which has an embedded reference to the target `:content_id`.
Expand Down
21 changes: 21 additions & 0 deletions spec/controllers/v2/content_items_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -553,4 +553,25 @@
expect(items.length).to eq(4)
end
end

describe "events" do
let(:edition) { create(:live_edition) }
let(:document) { edition.document }

let!(:put_content_events) { create_list(:event, 3, content_id: document.content_id, action: "PutContent") }
let!(:publish_events) { create_list(:event, 3, content_id: document.content_id, action: "Publish") }
let!(:other_events) { create_list(:event, 3) }

it "returns all events for a content_id" do
get :events, params: { content_id: document.content_id }

expect(parsed_response).to eq([put_content_events, publish_events].flatten.map(&:as_json))
end

it "returns all events for a content_id and action type" do
get :events, params: { content_id: document.content_id, action: "Publish" }

expect(parsed_response).to eq(publish_events.flatten.map(&:as_json))
end
end
end

0 comments on commit b0d56d6

Please sign in to comment.