Skip to content

Feature/agt 002 commission calculation#46

Draft
ester-bloch wants to merge 3 commits into
hajk1:masterfrom
ester-bloch:feature/AGT-002-Commission-Calculation
Draft

Feature/agt 002 commission calculation#46
ester-bloch wants to merge 3 commits into
hajk1:masterfrom
ester-bloch:feature/AGT-002-Commission-Calculation

Conversation

@ester-bloch

@ester-bloch ester-bloch commented Mar 2, 2026

Copy link
Copy Markdown
Contributor

PR: feature/AGT-002-Commission-Calculation

Implemented commission-per-agent report for completed voyages.

What this PR adds

Implements the commission‑per‑agent report for completed voyages as specified in AGT‑002.
When a voyage reaches COMPLETED status, clients can now call:

GET /api/v1/voyages/{voyageId}/commissions

and receive a breakdown of each agent’s delivered orders, their total value and the commission earned, plus a grand total.

Key behaviors & business rules

  • Only voyages with status COMPLETED are allowed (409 Conflict otherwise).
  • Only FreightOrders with status DELIVERED are considered.
  • Orders are grouped by agent and aggregated:
    • count of orders
    • sum of finalPrice
    • commission = agent.commissionPercent / 100 × totalOrderValue
  • Responses follow the DTO pattern used throughout the project.
  • Empty agent list / zero total for voyages with no delivered orders.

What changed

Area Summary of changes
DTOs Added AgentCommissionResponse and VoyageCommissionReportResponse.
Repository New findByVoyageIdAndStatus(Long, OrderStatus) method.
Service VoyageService.calculateCommissions(Long) method performs validation, querying, grouping, calculation and builds the response.
Controller New endpoint and Swagger docs added to VoyageController.
Tests New VoyageCommissionTest covers happy path, stats assertions, and edge/error cases (non‑completed voyage, missing voyage, mixed agent types, excluded orders).
Misc Minimal additional imports; existing code style and patterns respected.

Testing

  • ./mvnw test passes – all existing and new tests are green.
  • Coverage includes:
    • Correct calculations for multiple agents.
    • Behavior when no delivered orders exist.
    • Exclusion of non‑DELIVERED orders.
    • Proper HTTP status codes for invalid requests.
    • Internal vs. external agent handling.

Notes

  • DTOs follow the fromEntity() design pattern.
  • The new logic is read‑only and annotated with @Transactional(readOnly = true).
  • Swagger annotations added for good API documentation.

This PR completes the backend implementation described in docs/AGT-002-DESIGN.md and is ready for review.
Closes AGT-002

@ester-bloch

Copy link
Copy Markdown
Contributor Author

@claude please review my PR deeply. point at all problems you can find.

…ers, ports, vessels, and voyages; add email existence check in agent creation
@hajk1

hajk1 commented Mar 3, 2026

Copy link
Copy Markdown
Owner

@ester-bloch
Please resolve the merge conflicts.

@hajk1 hajk1 marked this pull request as draft March 5, 2026 12:23
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.

2 participants