Skip to content

chore: Add IsSubscribedToResource endpoint#4081

Merged
Rockyy174 merged 1 commit into
operately:mainfrom
Rockyy174:fix-is-subscribed
Jan 26, 2026
Merged

chore: Add IsSubscribedToResource endpoint#4081
Rockyy174 merged 1 commit into
operately:mainfrom
Rockyy174:fix-is-subscribed

Conversation

@Rockyy174
Copy link
Copy Markdown
Collaborator

No description provided.

Signed-off-by: Adriano Lazzaretti <lazzaretti136@gmail.com>
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue, and left some high level feedback:

  • In IsSubscribedToResourceTest, the "returns 404 for non-existent resource" case appears in both the permissions and functionality describes with very similar setup and assertions; consider consolidating this into a shared helper or a single describe to avoid duplication and keep the intent clearer.
  • The long case in load_resource/2 over resource_type is getting quite large; consider extracting the mapping from resource_type to {module, function} (or a small behaviour) to make it easier to extend and to reduce the size and branching of this function.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `IsSubscribedToResourceTest`, the "returns 404 for non-existent resource" case appears in both the permissions and functionality describes with very similar setup and assertions; consider consolidating this into a shared helper or a single describe to avoid duplication and keep the intent clearer.
- The long `case` in `load_resource/2` over `resource_type` is getting quite large; consider extracting the mapping from `resource_type` to `{module, function}` (or a small behaviour) to make it easier to extend and to reduce the size and branching of this function.

## Individual Comments

### Comment 1
<location> `app/lib/operately_web/api/queries/is_resource_subscribed.ex:27-31` </location>
<code_context>
+    |> respond()
+  end
+
+  defp respond(result) do
+    case result do
+      {:ok, ctx} -> {:ok, ctx.serialized}
+      {:error, :resource_id, _} -> {:error, :bad_request}
+      {:error, :resource, %{error: :invalid_resource_type}} -> {:error, :bad_request}
+      {:error, :resource, _} -> {:error, :not_found}
+      {:error, :check_permissions, _} -> {:error, :not_found}
</code_context>

<issue_to_address>
**issue (bug_risk):** The `invalid_resource_type` error shape from `load_resource/2` will not match the `respond/1` clause and will currently resolve as `:not_found` instead of `:bad_request`.

`load_resource/2` returns `{:error, :invalid_resource_type}`, which becomes `{:error, :resource, :invalid_resource_type}` in the `Action` pipeline. `respond/1` is instead matching `{:error, :resource, %{error: :invalid_resource_type}}`, so this clause never fires and the error falls through to `:not_found`. To return `:bad_request` for this case, either update the pattern in `respond/1` to `{:error, :resource, :invalid_resource_type}` or change `load_resource/2` to emit a `%{error: :invalid_resource_type}` map.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread app/lib/operately_web/api/queries/is_resource_subscribed.ex
@Rockyy174 Rockyy174 merged commit d403b03 into operately:main Jan 26, 2026
3 checks passed
@Rockyy174 Rockyy174 deleted the fix-is-subscribed branch January 26, 2026 13:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant