Welcome to the Farm Management System project! This application is a Spring Boot REST API designed to manage fields and crops on a farm. It allows planting, watering, and harvesting crops while tracking their growth stages to maximize productivity.
This project follows a Layered Architecture, where each layer has a specific responsibility:
- API Layer – Manages HTTP requests and responses.
- Application Layer – Implements business logic.
- Persistence Layer – Handles database access via JDBC.
- DTOs – Transfers data between layers.
- Domain Layer – Contains core business logic.
Crops go through growth stages depending on how often they are watered. Each crop category has its own optimal watering range.
| Crop Type | Ideal Watering | NOT_READY | MATURE | EXPIRED |
|---|---|---|---|---|
| Vegetables | 5 | waterCount < 4 | 4 <= waterCount <= 6 | waterCount > 6 |
| Fruits | 7 | waterCount < 6 | 6 <= waterCount <= 8 | waterCount > 8 |
| Grains | 9 | waterCount < 8 | 8 <= waterCount <= 10 | waterCount > 10 |
Method: POST
Endpoint: /fields
{
"name": "Greenfield",
"maxCrops": 10,
"dimensions": 1500
}Validation Rules: name must be at least 3 characters
maxCrops must be between 1 and 10
dimensions must be between 100 and 2000
Method: GET
Endpoint: /fields
min_dimensions(optional)max_dimensions(optional)
Returns a list of all fields with their associated crops.
Method: POST
Endpoint: /fields/{fieldId}/crops
{
"type": "vegetable"
}Method: POST
Endpoint: /fields/{fieldId}/crops/waters
Waters all crops in the specified field by increasing their waterCount by 1. Returns the list of crops with updated status.
Method: GET
Endpoint: /fields/{fieldId}/crops/{cropId}
Retrieves details of a specific crop, including:
Crop type
Planting date
Water count
Crop status (NOT_READY, MATURE, or EXPIRED)
###Harvest Crops Method: POST Endpoint: /fields/{fieldId}/crops/harvest
Harvests all crops that are in MATURE status.
Removes crops that are EXPIRED from the field.
Returns a list of harvested crops.
Rules: If no crops are mature, the system returns a 422 Unprocessable Entity error with a message indicating that no crops were harvested.
Method: GET
Endpoint: /fields/{fieldId}
Retrieves details of a specific field, including:
- Field name
- Dimensions
- Maximum crop capacity
- List of associated crops (with their IDs and types)
###Get All Crops in a Field Method: GET Endpoint: /fields/{fieldId}/crops
Retrieves a list of all crops planted in a specific field, including:
Crop ID
Type
Water count
Current status (NOT_READY, MATURE, EXPIRED)