PackagingUnitDeletionController.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.DeletePURequestVO;
import org.springframework.context.MessageSource;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;

import static org.openwms.wms.inventory.api.InventoryConstants.API_PACKAGING_UNITS;

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

    protected final PackagingUnitService service;

    protected PackagingUnitDeletionController(MessageSource messageSource, PackagingUnitService service) {
        super(messageSource);
        this.service = service;
    }

    @DeleteMapping(value = API_PACKAGING_UNITS)
    public ResponseEntity<Void> deleteOnLocation(@Valid @RequestBody DeletePURequestVO request) {
        service.deleteOnLocation(request);
        return ResponseEntity.noContent().build();
    }

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