Practice assignment

Sales reporting take-home (Spring Data JPA)

Finance wants a revenue report and a paginated sales list without loading the whole table into memory. A JPQL aggregation is sketched in SaleRepository — you may use, improve or replace it. Work in ReportService.

The starter

GET /api/reports/revenue-by-category?from=YYYY-MM-DD&to=YYYY-MM-DD
GET /api/sales?region=EE&page=0&size=20
 → {content, totalElements, totalPages, page}

Requirements

  1. Revenue + count per category in the inclusive date range, sorted by revenue descending, 2 decimals. Aggregate in the database. from == to is valid; from > to is 400.
  2. Paginated sales, newest soldOn first, tie-break on id ascending. size 1–100, otherwise 400.

Grading rubric

AreaPoints
Correctness (provided tests)30
Aggregation done in the DB, no N+1 / full-table load20
Pagination & sorting correctness, limits10
Own tests (edge dates, empty ranges)15
Indexes / query plan discussion10
Structure & naming5
NOTES.md (Postgres vs H2, indexes, caching)10

Levels: junior ≥ 60, mid ≥ 75, senior ≥ 85 (and a strong NOTES.md).

What reviewers look for

Common mistakes

How to run it

mvn verify. The provided tests use H2; a senior NOTES.md talks about the Postgres plan anyway.

Generate a reporting-style assignment from a job posting, or try the CSV import sample if you want a related operations task.

Download the import sample Generate one from a job ad

Related practice tasks

Frequently asked questions

Is this a data-science take-home?
No. It is a backend reporting API: JPQL or SQL, pagination, and a discussion of indexes.
Can I write a native Postgres query?
Yes if you keep the HTTP contract. The tests run on H2, so a Postgres-only query will need a Testcontainers suite of your own, or you stay with portable JPQL and discuss Postgres in NOTES.md.
Should I cache the report?
Only with a short TTL and a clear invalidation story. A stale financial report is worse than a slightly slower query. Say what you would do; do not quietly cache for the timebox unless you have tests for it.

Practice only. This is an original HireCheck practice assignment, not a real employer's take-home, and it is not affiliated with any company mentioned as a role example.