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

import com.tmerclub.cloud.common.database.dto.PageDTO;
import com.tmerclub.cloud.common.database.vo.PageVO;
import com.tmerclub.cloud.common.response.ServerResponseEntity;
import com.tmerclub.cloud.common.util.BeanUtil;
import com.tmerclub.cloud.delivery.dto.TranscityDTO;
import com.tmerclub.cloud.delivery.model.Transcity;
import com.tmerclub.cloud.delivery.service.TranscityService;
import com.tmerclub.cloud.delivery.vo.TranscityVO;
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 tmerclub
 * @date 2020-12-07 15:10:01
 */
@RestController("appTranscityController")
@RequestMapping("/transcity")
@Tag(name = "运费项和运费城市关联信息")
public class TranscityController {

    @Autowired
    private TranscityService transcityService;


    @GetMapping("/page")
    @Operation(summary = "获取运费项和运费城市关联信息列表", description = "分页获取运费项和运费城市关联信息列表")
    public ServerResponseEntity<PageVO<TranscityVO>> page(@Valid PageDTO pageDTO) {
        PageVO<TranscityVO> transcityPage = transcityService.page(pageDTO);
        return ServerResponseEntity.success(transcityPage);
    }

    @GetMapping
    @Operation(summary = "获取运费项和运费城市关联信息", description = "根据transcityId获取运费项和运费城市关联信息")
    public ServerResponseEntity<TranscityVO> getByTranscityId(@RequestParam Long transcityId) {
        return ServerResponseEntity.success(transcityService.getByTranscityId(transcityId));
    }

    @PostMapping
    @Operation(summary = "保存运费项和运费城市关联信息", description = "保存运费项和运费城市关联信息")
    public ServerResponseEntity<Void> save(@Valid @RequestBody TranscityDTO transcityDTO) {
        Transcity transcity = BeanUtil.map(transcityDTO, Transcity.class);
        transcity.setTranscityId(null);
        transcityService.save(transcity);
        return ServerResponseEntity.success();
    }

    @PutMapping
    @Operation(summary = "更新运费项和运费城市关联信息", description = "更新运费项和运费城市关联信息")
    public ServerResponseEntity<Void> update(@Valid @RequestBody TranscityDTO transcityDTO) {
        Transcity transcity = BeanUtil.map(transcityDTO, Transcity.class);
        transcityService.update(transcity);
        return ServerResponseEntity.success();
    }

    @DeleteMapping
    @Operation(summary = "删除运费项和运费城市关联信息", description = "根据运费项和运费城市关联信息id删除运费项和运费城市关联信息")
    public ServerResponseEntity<Void> delete(@RequestParam Long transcityId) {
        transcityService.deleteById(transcityId);
        return ServerResponseEntity.success();
    }
}
