CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl-labs/springboot-error-handling

Error handling for Spring Boot APIs — @ControllerAdvice, structured error

84

1.76x
Quality

75%

Does it follow best practices?

Impact

99%

1.76x

Average score across 5 eval scenarios

SecuritybySnyk

Passed

No known issues

Overview
Quality
Evals
Security
Files

task.mdevals/scenario-3/

Build a Warehouse Inventory Tracking API

Problem/Feature Description

A warehouse needs a REST API to track product inventory and stock movements. Build it using Spring Boot and Java.

Resources:

  • Product: { id, sku, name, description, category, unitPrice }
  • StockLevel: { productId, warehouseLocation, quantity, lastUpdated }
  • StockMovement: { id, productId, type (IN/OUT/ADJUSTMENT), quantity, reason, timestamp, performedBy }

Endpoints:

  • GET /api/products -- list products, support filtering by category and search by name
  • POST /api/products -- create a product (sku required and must be unique, name required, unitPrice > 0)
  • GET /api/products/{id} -- get product with current stock level
  • PUT /api/products/{id} -- update product details (cannot change SKU)
  • GET /api/products/{id}/movements -- get stock movement history for a product, support pagination
  • POST /api/stock/receive -- receive stock (productId, quantity > 0, warehouseLocation required, performedBy required)
  • POST /api/stock/dispatch -- dispatch stock (productId, quantity > 0, warehouseLocation required, performedBy required; cannot dispatch more than available stock)
  • POST /api/stock/adjust -- adjust stock level (productId, quantity can be positive or negative, reason required, performedBy required; resulting stock cannot be negative)
  • GET /api/stock/levels -- get current stock levels across all products and locations
  • GET /api/stock/low -- get products where stock is below a threshold (threshold query param, default 10)

Business rules:

  • SKU format: 3 uppercase letters followed by a hyphen and 4 digits (e.g., ABC-1234)
  • Stock quantity can never go negative
  • Every stock change must create a StockMovement audit record
  • Dispatch requires sufficient stock at the specified location

Use H2 embedded database with Spring Data JPA.

Output Specification

Produce a complete Spring Boot project:

  • src/main/java/com/example/ -- controller, service, entity, and repository packages
  • pom.xml or build.gradle -- with dependencies
  • src/main/resources/application.properties -- H2 and application configuration

You may create additional files as needed for a well-structured codebase.

evals

tile.json