Class MaterialController

java.lang.Object
com.university.bookstore.controller.MaterialController

@RestController @RequestMapping("/api/materials") public class MaterialController extends Object
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 Details

    • MaterialController

      public MaterialController(MaterialStore materialStore)
      Constructor with dependency injection of MaterialStore.
      Parameters:
      materialStore - the material store implementation
  • Method Details

    • getAllMaterials

      @GetMapping public org.springframework.http.ResponseEntity<List<Material>> getAllMaterials()
      GET /api/materials - Retrieve all materials
      Returns:
      list of all materials
    • getMaterialById

      @GetMapping("/{id}") public org.springframework.http.ResponseEntity<Material> getMaterialById(@PathVariable("id") String id)
      GET /api/materials/{id} - Retrieve a specific material by ID
      Parameters:
      id - the material ID
      Returns:
      the material if found, 404 if not found
    • createMaterial

      @PostMapping public org.springframework.http.ResponseEntity<Material> createMaterial(@RequestBody Material material)
      POST /api/materials - Create a new material
      Parameters:
      material - the material to create
      Returns:
      the created material or 400 if invalid
    • 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 ID
      material - the updated material
      Returns:
      the updated material or 404 if not found
    • deleteMaterial

      @DeleteMapping("/{id}") public org.springframework.http.ResponseEntity<Void> deleteMaterial(@PathVariable("id") String id)
      DELETE /api/materials/{id} - Delete a material
      Parameters:
      id - the material ID
      Returns:
      204 if deleted, 404 if not found
    • searchByTitle

      @GetMapping("/search/title") public org.springframework.http.ResponseEntity<List<Material>> searchByTitle(@RequestParam("q") String q)
      GET /api/materials/search/title?q={query} - Search materials by title
      Parameters:
      q - the search query
      Returns:
      list of matching materials
    • searchByCreator

      @GetMapping("/search/creator") public org.springframework.http.ResponseEntity<List<Material>> searchByCreator(@RequestParam("q") String q)
      GET /api/materials/search/creator?q={query} - Search materials by creator
      Parameters:
      q - the search query
      Returns:
      list of matching materials
    • 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 price
      max - 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

      @GetMapping("/count") public org.springframework.http.ResponseEntity<Integer> getMaterialCount()
      GET /api/materials/count - Get total material count
      Returns:
      total number of materials