
package com.tmerclub.cloud.delivery.controller.platform;

import com.tmerclub.cloud.common.response.ServerResponseEntity;
import com.tmerclub.cloud.common.util.BeanUtil;
import com.tmerclub.cloud.delivery.dto.DeliveryCompanyDTO;
import com.tmerclub.cloud.delivery.model.DeliveryCompany;
import com.tmerclub.cloud.delivery.service.DeliveryCompanyService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author lth
 * @Date 2021/4/27 10:17
 */
@RestController("platformDeliveryCompanyController")
@RequestMapping("/p/deliveryCompany")
@Tag(name = "物流公司")
public class DeliveryCompanyController {

    @Autowired
    private DeliveryCompanyService deliveryCompanyService;


    @DeleteMapping
    @Operation(summary = "根据id删除物流公司信息", description = "根据id删除物流公司信息")
    public ServerResponseEntity<Void> deleteById(@RequestParam("deliveryCompanyId") Long deliveryCompanyId) {
        deliveryCompanyService.deleteById(deliveryCompanyId);
        return ServerResponseEntity.success();
    }

    @PostMapping
    @Operation(summary = "新增物流公司信息", description = "新增物流公司信息")
    public ServerResponseEntity<Void> save(@Valid @RequestBody DeliveryCompanyDTO deliveryCompanyDTO) {
        DeliveryCompany deliveryCompany = BeanUtil.map(deliveryCompanyDTO, DeliveryCompany.class);
        deliveryCompanyService.save(deliveryCompany);
        return ServerResponseEntity.success();
    }

    @PutMapping
    @Operation(summary = "更新物流信息", description = "更新物流信息")
    public ServerResponseEntity<Void> update(@Valid @RequestBody DeliveryCompanyDTO deliveryCompanyDTO) {
        DeliveryCompany deliveryCompany = BeanUtil.map(deliveryCompanyDTO, DeliveryCompany.class);
        deliveryCompanyService.update(deliveryCompany);
        return ServerResponseEntity.success();
    }

}
