PackagingUnitController.java

/*
 * Copyright 2005-2025 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.openwms.wms.inventory.rest.pu;

import jakarta.validation.Valid;
import org.ameba.http.MeasuredRestController;
import org.openwms.core.http.AbstractWebController;
import org.openwms.wms.inventory.PackagingUnitService;
import org.openwms.wms.inventory.api.ReportProblemVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import static org.openwms.wms.inventory.api.InventoryConstants.API_PACKAGING_UNITS;
import static org.openwms.wms.transport.api.TransportUnitApi.API_TRANSPORT_UNITS;

/**
 * A PackagingUnitController.
 *
 * @author Heiko Scherrer
 */
@Validated
@MeasuredRestController
public class PackagingUnitController extends AbstractWebController {

    private static final Logger LOGGER = LoggerFactory.getLogger(PackagingUnitController.class);
    protected final PackagingUnitService service;

    protected PackagingUnitController(PackagingUnitService service) {
        this.service = service;
    }

    @PostMapping(value = API_TRANSPORT_UNITS + "/{transportUnitBK}/load-units/{luPos}/packaging-units/failures")
    public ResponseEntity<Void> reportProblemForPUinLU(
            @PathVariable("transportUnitBK") String transportUnitBK,
            @PathVariable("luPos") String luPos,
            @Valid @RequestBody ReportProblemVO problem
    ) {
        LOGGER.debug("Report a problem on the LoadUnit [{}] and the TransportUnit [{}] of [{}]", luPos, transportUnitBK, problem);
        service.reportProblem(transportUnitBK, luPos, problem);
        return ResponseEntity.noContent().build();
    }

    @PostMapping(value = API_PACKAGING_UNITS + "/{pKey}/release")
    public ResponseEntity<Void> releasePU(@PathVariable("pKey") String pKey) {
        service.release(pKey);
        return ResponseEntity.noContent().build();
    }
}