package com.goi.erp.controller; import com.goi.erp.entity.TankInventory; import com.goi.erp.service.TankInventoryService; import lombok.RequiredArgsConstructor; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; import java.math.BigDecimal; import java.security.Principal; import java.util.UUID; @RestController @RequiredArgsConstructor @RequestMapping("/tank/inventory") public class TankInventoryController { private final TankInventoryService tankInventoryService; /** * 단일 탱크 inventory 조회 */ @GetMapping("/{tankUuid}") @PreAuthorize("hasAuthority('TANK_READ')") public TankInventory getInventory(@PathVariable UUID tankUuid) { return tankInventoryService.findByTankUuid(tankUuid) .orElseThrow(() -> new IllegalStateException("Inventory not found. tankUuid=" + tankUuid) ); } /** * inventory upsert (절대값) */ @PostMapping("/{tankUuid}") @PreAuthorize("hasAuthority('TANK_WRITE')") public TankInventory upsertInventory( @PathVariable UUID tankUuid, @RequestParam String materialKind, @RequestParam BigDecimal qtyTotal, Principal principal ) { return tankInventoryService.upsertInventory( tankUuid, materialKind, qtyTotal, principal.getName() // ✅ updatedBy ); } /** * inventory delta 적용 */ @PostMapping("/{tankUuid}/delta") @PreAuthorize("hasAuthority('TANK_WRITE')") public TankInventory applyDelta( @PathVariable UUID tankUuid, @RequestParam String materialKind, @RequestParam BigDecimal deltaQty, Principal principal ) { return tankInventoryService.applyDelta( tankUuid, materialKind, deltaQty, principal.getName() // ✅ updatedBy ); } }