
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.TranscityFreeDTO;
import com.tmerclub.cloud.delivery.model.TranscityFree;
import com.tmerclub.cloud.delivery.service.TranscityFreeService;
import com.tmerclub.cloud.delivery.vo.TranscityFreeVO;
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("appTranscityFreeController")
@RequestMapping("/transcityFree")
@Tag(name = "指定条件包邮城市项")
public class TranscityFreeController {

    @Autowired
    private TranscityFreeService transcityFreeService;


    @GetMapping("/page")
    @Operation(summary = "获取指定条件包邮城市项列表", description = "分页获取指定条件包邮城市项列表")
    public ServerResponseEntity<PageVO<TranscityFreeVO>> page(@Valid PageDTO pageDTO) {
        PageVO<TranscityFreeVO> transcityFreePage = transcityFreeService.page(pageDTO);
        return ServerResponseEntity.success(transcityFreePage);
    }

    @GetMapping
    @Operation(summary = "获取指定条件包邮城市项", description = "根据transcityFreeId获取指定条件包邮城市项")
    public ServerResponseEntity<TranscityFreeVO> getByTranscityFreeId(@RequestParam Long transcityFreeId) {
        return ServerResponseEntity.success(transcityFreeService.getByTranscityFreeId(transcityFreeId));
    }

    @PostMapping
    @Operation(summary = "保存指定条件包邮城市项", description = "保存指定条件包邮城市项")
    public ServerResponseEntity<Void> save(@Valid @RequestBody TranscityFreeDTO transcityFreeDTO) {
        TranscityFree transcityFree = BeanUtil.map(transcityFreeDTO, TranscityFree.class);
        transcityFree.setTranscityFreeId(null);
        transcityFreeService.save(transcityFree);
        return ServerResponseEntity.success();
    }

    @PutMapping
    @Operation(summary = "更新指定条件包邮城市项", description = "更新指定条件包邮城市项")
    public ServerResponseEntity<Void> update(@Valid @RequestBody TranscityFreeDTO transcityFreeDTO) {
        TranscityFree transcityFree = BeanUtil.map(transcityFreeDTO, TranscityFree.class);
        transcityFreeService.update(transcityFree);
        return ServerResponseEntity.success();
    }

    @DeleteMapping
    @Operation(summary = "删除指定条件包邮城市项", description = "根据指定条件包邮城市项id删除指定条件包邮城市项")
    public ServerResponseEntity<Void> delete(@RequestParam Long transcityFreeId) {
        transcityFreeService.deleteById(transcityFreeId);
        return ServerResponseEntity.success();
    }
}
