Class MaterialController
java.lang.Object
com.university.bookstore.controller.MaterialController
REST Controller for Material management operations.
This controller demonstrates how the existing MaterialStore interface can be easily exposed as REST endpoints without modifying the core business logic. It showcases the extensibility of the hexagonal architecture design.
All operations delegate to the existing MaterialStore implementation, maintaining the same business logic and validation rules.
- Since:
- 2024-12-19
- Version:
- 1.0
- Author:
- Navid Mohaghegh
-
Constructor Summary
ConstructorsConstructorDescriptionMaterialController(MaterialStore materialStore) Constructor with dependency injection of MaterialStore. -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.http.ResponseEntity<Material> createMaterial(Material material) POST /api/materials - Create a new materialorg.springframework.http.ResponseEntity<Void> deleteMaterial(String id) DELETE /api/materials/{id} - Delete a materialGET /api/materials - Retrieve all materialsorg.springframework.http.ResponseEntity<MaterialStore.InventoryStats> GET /api/materials/stats - Get inventory statisticsorg.springframework.http.ResponseEntity<Material> GET /api/materials/{id} - Retrieve a specific material by IDorg.springframework.http.ResponseEntity<Integer> GET /api/materials/count - Get total material countgetMaterialsByPriceRange(double min, double max) Get materials by price range.GET /api/materials/type/{type} - Get materials by typegetRecentMaterials(int years) GET /api/materials/recent?years={years} - Get recent materialsGET /api/materials/search/creator?q={query} - Search materials by creatorGET /api/materials/search/title?q={query} - Search materials by titleorg.springframework.http.ResponseEntity<Material> updateMaterial(String id, Material material) PUT /api/materials/{id} - Update an existing material
-
Constructor Details
-
MaterialController
Constructor with dependency injection of MaterialStore.- Parameters:
materialStore- the material store implementation
-
-
Method Details
-
getAllMaterials
-
getMaterialById
-
createMaterial
-
updateMaterial
@PutMapping("/{id}") public org.springframework.http.ResponseEntity<Material> updateMaterial(@PathVariable("id") String id, @RequestBody Material material) PUT /api/materials/{id} - Update an existing material- Parameters:
id- the material IDmaterial- the updated material- Returns:
- the updated material or 404 if not found
-
deleteMaterial
-
searchByTitle
-
searchByCreator
-
getMaterialsByType
@GetMapping("/type/{type}") public org.springframework.http.ResponseEntity<List<Material>> getMaterialsByType(@PathVariable("type") Material.MaterialType type) GET /api/materials/type/{type} - Get materials by type- Parameters:
type- the material type- Returns:
- list of materials of the specified type
-
getRecentMaterials
@GetMapping("/recent") public org.springframework.http.ResponseEntity<List<Material>> getRecentMaterials(@RequestParam(value="years",defaultValue="5") int years) GET /api/materials/recent?years={years} - Get recent materials- Parameters:
years- number of years to look back- Returns:
- list of recent materials
-
getMaterialsByPriceRange
@GetMapping("/price-range") public org.springframework.http.ResponseEntity<List<Material>> getMaterialsByPriceRange(@RequestParam("min") double min, @RequestParam("max") double max) Get materials by price range.- Parameters:
min- minimum pricemax- maximum price- Returns:
- list of materials in price range
-
getInventoryStats
@GetMapping("/stats") public org.springframework.http.ResponseEntity<MaterialStore.InventoryStats> getInventoryStats()GET /api/materials/stats - Get inventory statistics- Returns:
- inventory statistics
-
getMaterialCount
GET /api/materials/count - Get total material count- Returns:
- total number of materials
-