Skip to content

Add get order status via MontonioClient facade#39

Open
rammrain wants to merge 3 commits into
mainfrom
task-16
Open

Add get order status via MontonioClient facade#39
rammrain wants to merge 3 commits into
mainfrom
task-16

Conversation

@rammrain
Copy link
Copy Markdown
Member

@rammrain rammrain commented Apr 10, 2026

Summary

  • Introduce MontonioClient as the top-level SDK entry point with domain-scoped access: client.orders().get(uuid)
  • OrderService.get(uuid) validates null/blank input and delegates GET /orders/{uuid} to the HTTP client
  • Lazy-cached domain services — orders() creates OrderService on first call, reuses it after
  • Widen MontonioHttpClient three-arg constructor to public for cross-package testability

New Issues Created

Test plan

  • MontonioClientTest — null config rejection, orders() returns non-null, lazy-caching returns same instance
  • OrderServiceTest — successful retrieval, null/blank/empty UUID validation, 404 error, multiple payment intents, all payment statuses via parameterized test
  • Full build passes (./gradlew build)

Closes #16

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added SDK operation to fetch detailed order status by order identifier, returning full order and payment intent details.
  • Tests

    • Added extensive tests for order retrieval: successful responses, UUID trimming/validation, multiple payment intents, all payment statuses and 404/error mapping.
  • Documentation

    • Added design document describing the new order retrieval flow, client wiring and expected behaviours.

Introduce MontonioClient as the top-level SDK entry point with
domain-scoped access: client.orders().get(uuid). OrderService
validates the UUID and delegates GET /orders/{uuid} to the HTTP
client, returning the existing OrderResponse.

Widen MontonioHttpClient three-arg constructor to public so
OrderService (and SDK consumers) can inject test doubles.

Closes #16
Related: #37 (thread safety), #38 (create order operation)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 10, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: deab4a38-085f-4c85-8d52-09cb55b5d8b2

📥 Commits

Reviewing files that changed from the base of the PR and between 8bf63b8 and 9bfc337.

📒 Files selected for processing (3)
  • src/main/java/ee/bitweb/montonio/sdk/MontonioClient.java
  • src/main/java/ee/bitweb/montonio/sdk/order/OrderService.java
  • src/test/java/ee/bitweb/montonio/sdk/order/OrderServiceTest.java
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/main/java/ee/bitweb/montonio/sdk/order/OrderService.java
  • src/test/java/ee/bitweb/montonio/sdk/order/OrderServiceTest.java

📝 Walkthrough

Walkthrough

This PR adds GET /orders/{uuid}: a new MontonioClient facade exposing a lazily cached OrderService which validates and trims UUIDs, delegates retrieval to MontonioHttpClient, and returns OrderResponse. Includes design doc and unit tests covering success, validation and 404→MontonioApiException. (50 words)

Changes

Cohort / File(s) Summary
Design Documentation
docs/plans/2026-04-10-get-order-status-design.md
New design doc describing facade pattern, lazy service instantiation, UUID validation, delegation to MontonioHttpClient, and test expectations.
Client Facade
src/main/java/ee/bitweb/montonio/sdk/MontonioClient.java
Adds MontonioClient that holds a shared MontonioHttpClient and lazily caches an OrderService using double-checked locking; validates non-null configuration.
Order Service
src/main/java/ee/bitweb/montonio/sdk/order/OrderService.java
New OrderService with get(String uuid) that trims/validates uuid, throws MontonioValidationException("uuid", ...) for null/blank, and calls httpClient.get("/orders/"+trimmedUuid, OrderResponse.class).
HTTP Client visibility
src/main/java/ee/bitweb/montonio/sdk/http/MontonioHttpClient.java
Changed three-arg constructor visibility to public to allow direct construction in tests.
Unit tests
src/test/java/ee/bitweb/montonio/sdk/MontonioClientTest.java, src/test/java/ee/bitweb/montonio/sdk/order/OrderServiceTest.java
Adds tests for MontonioClient wiring and caching; extensive OrderService tests with a stub HttpClient covering deserialization, request URI formation, UUID trimming/validation, 404→MontonioApiException, multiple payment intents and all PaymentStatus values.

Sequence Diagram

sequenceDiagram
    participant Client
    participant MontonioClient
    participant OrderService
    participant MontonioHttpClient
    participant HttpClient
    participant Server

    Client->>MontonioClient: orders()
    activate MontonioClient
    MontonioClient->>MontonioClient: lazy instantiate OrderService (cached)
    MontonioClient-->>Client: OrderService
    deactivate MontonioClient

    Client->>OrderService: get(uuid)
    activate OrderService
    OrderService->>OrderService: validate & trim uuid
    OrderService->>MontonioHttpClient: get("/orders/{uuid}", OrderResponse.class)
    deactivate OrderService

    activate MontonioHttpClient
    MontonioHttpClient->>HttpClient: send(HttpRequest)
    deactivate MontonioHttpClient

    activate HttpClient
    HttpClient->>Server: GET /orders/{uuid}
    Server-->>HttpClient: 200 JSON / 4xx error
    deactivate HttpClient

    activate MontonioHttpClient
    MontonioHttpClient->>MontonioHttpClient: map/deserialize response (OrderResponse or MontonioApiException)
    MontonioHttpClient-->>Client: return or throw mapped result
    deactivate MontonioHttpClient
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐰 I nibble docs and craft a tiny route,
UUIDs trimmed, services cached en route.
HTTP calls hop, responses tumble in,
Tests clap their paws for each status and pin.
A rabbitly cheer — orders fetched with a grin!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 2.17% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately describes the main change: adding order status retrieval through a MontonioClient facade pattern.
Linked Issues check ✅ Passed All coding requirements from issue #16 are met: GET order by UUID implemented, OrderResponse with required fields returned, API errors mapped to typed exceptions, service interface exposed for testability, and comprehensive unit tests with stubbed HTTP layer.
Out of Scope Changes check ✅ Passed All changes are directly scoped to implementing the get order status feature; no unrelated modifications detected in the PR.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch task-16

Warning

Review ran into problems

🔥 Problems

Timed out fetching pipeline failures after 30000ms


Comment @coderabbitai help to get the list of available commands and usage tips.

@rammrain
Copy link
Copy Markdown
Member Author

@coderabbitai review

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@docs/plans/2026-04-10-get-order-status-design.md`:
- Around line 29-33: The fenced code block containing "MontonioClient →
MontonioHttpClient → HttpClient (java.net)" is missing a language identifier;
update the opening triple-backtick to include a language (e.g., ```text) so
markdownlint MD040 is satisfied and the block renders correctly.

In `@src/main/java/ee/bitweb/montonio/sdk/MontonioClient.java`:
- Around line 9-10: The orders() lazy cache in MontonioClient is not thread-safe
(orderService can be instantiated multiple times); make orderService a volatile
field and change orders() to use double-checked locking (check null,
synchronized(this) block, re-check null, then assign) or alternatively make the
accessor synchronized to ensure a single instance; apply the same pattern to the
other lazily-initialized service fields instantiated in the same way elsewhere
in this class (the other service fields initialized like orderService).

In `@src/main/java/ee/bitweb/montonio/sdk/order/OrderService.java`:
- Around line 15-20: The get method in OrderService should normalize the uuid
(trim whitespace) before validation and before concatenating into the request
path to avoid unchecked URI errors; update OrderService.get to first assign a
trimmed version of the input (e.g., normalizedUuid = uuid == null ? null :
uuid.trim()), validate normalizedUuid and throw MontonioValidationException when
null/blank, and then call httpClient.get("/orders/" + normalizedUuid,
OrderResponse.class) so the request path never contains leading/trailing spaces.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e5af1d7b-24ab-46cf-8e2e-13bd64366d95

📥 Commits

Reviewing files that changed from the base of the PR and between 1cc27bf and 04a706d.

📒 Files selected for processing (6)
  • docs/plans/2026-04-10-get-order-status-design.md
  • src/main/java/ee/bitweb/montonio/sdk/MontonioClient.java
  • src/main/java/ee/bitweb/montonio/sdk/http/MontonioHttpClient.java
  • src/main/java/ee/bitweb/montonio/sdk/order/OrderService.java
  • src/test/java/ee/bitweb/montonio/sdk/MontonioClientTest.java
  • src/test/java/ee/bitweb/montonio/sdk/order/OrderServiceTest.java

Comment thread docs/plans/2026-04-10-get-order-status-design.md Outdated
Comment thread src/main/java/ee/bitweb/montonio/sdk/MontonioClient.java Outdated
Comment thread src/main/java/ee/bitweb/montonio/sdk/order/OrderService.java
- Add language identifier to fenced code block in design doc (MD040)
- Make orders() thread-safe with volatile + double-checked locking
- Trim UUID before validation and path construction to prevent
  whitespace in request URIs
- Add test for UUID trimming behavior

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 10, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
src/test/java/ee/bitweb/montonio/sdk/order/OrderServiceTest.java (1)

120-125: Strengthen the empty-UUID test to assert the exception contract, not only the type.

For consistency with the null/blank tests, also verify field == "uuid" (and optionally message content).

Suggested patch
 `@Test`
 void getWithEmptyUuidThrowsValidationException() {
     OrderService service = createServiceWithStub(200, "{}");
-
-    assertThrows(MontonioValidationException.class, () -> service.get(""));
+    MontonioValidationException exception = assertThrows(
+            MontonioValidationException.class,
+            () -> service.get("")
+    );
+    assertEquals("uuid", exception.getField());
+    assertTrue(exception.getMessage().contains("must not be null or blank"));
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/test/java/ee/bitweb/montonio/sdk/order/OrderServiceTest.java` around
lines 120 - 125, The test getWithEmptyUuidThrowsValidationException should
assert the exception's validation contract, not just its type: capture the
thrown MontonioValidationException from OrderService.get("") (same flow as in
getWithNullUuidThrowsValidationException/getWithBlankUuidThrowsValidationException),
then assert that exception.getField() equals "uuid" (and optionally assert
message content). Update the test method
getWithEmptyUuidThrowsValidationException to store the thrown exception and add
the field assertion to match the other UUID validation tests.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/main/java/ee/bitweb/montonio/sdk/MontonioClient.java`:
- Around line 18-20: The package-private constructor
MontonioClient(MontonioHttpClient httpClient) should guard against a null
httpClient to fail fast; update the MontonioClient constructor to validate the
incoming httpClient and throw a clear exception (e.g., NullPointerException or
IllegalArgumentException with a message like "httpClient must not be null") when
null is passed so that faults are caught at construction time instead of later
in orders() or other call paths.

In `@src/main/java/ee/bitweb/montonio/sdk/order/OrderService.java`:
- Around line 11-13: The OrderService constructor should validate the injected
dependency and fail fast: check the constructor parameter httpClient in
OrderService and if it is null throw a clear exception (e.g.,
IllegalArgumentException or NullPointerException) with a descriptive message so
construction fails immediately rather than later in get(...); update the
constructor to perform this null-check before assigning to this.httpClient.

---

Nitpick comments:
In `@src/test/java/ee/bitweb/montonio/sdk/order/OrderServiceTest.java`:
- Around line 120-125: The test getWithEmptyUuidThrowsValidationException should
assert the exception's validation contract, not just its type: capture the
thrown MontonioValidationException from OrderService.get("") (same flow as in
getWithNullUuidThrowsValidationException/getWithBlankUuidThrowsValidationException),
then assert that exception.getField() equals "uuid" (and optionally assert
message content). Update the test method
getWithEmptyUuidThrowsValidationException to store the thrown exception and add
the field assertion to match the other UUID validation tests.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 48b67464-8464-45e1-b23f-6bc54de01a58

📥 Commits

Reviewing files that changed from the base of the PR and between 04a706d and 8bf63b8.

📒 Files selected for processing (4)
  • docs/plans/2026-04-10-get-order-status-design.md
  • src/main/java/ee/bitweb/montonio/sdk/MontonioClient.java
  • src/main/java/ee/bitweb/montonio/sdk/order/OrderService.java
  • src/test/java/ee/bitweb/montonio/sdk/order/OrderServiceTest.java
✅ Files skipped from review due to trivial changes (1)
  • docs/plans/2026-04-10-get-order-status-design.md

Comment thread src/main/java/ee/bitweb/montonio/sdk/MontonioClient.java
Comment thread src/main/java/ee/bitweb/montonio/sdk/order/OrderService.java
- Fail fast on null httpClient in MontonioClient and OrderService
  constructors
- Strengthen empty UUID test to assert field name and message content

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.

Get order status — API operation

1 participant