package com.amms.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.amms.domain.vo.Result;
import com.amms.domain.Tourist;
import com.amms.service.ITouristService;

import java.util.List;

/**
 * 普通用户子Controller
 */
@RestController
@RequestMapping("/tourist")
public class TouristController {

    @Autowired
    private ITouristService touristService;

    /**
     * 查询普通用户子列表
     */
    @GetMapping("/list")
    public PageInfo list(Tourist tourist, @RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize") Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Tourist> tourists = touristService.selectTouristList(tourist);
        return new PageInfo(tourists);
    }

    /**
     * 查询全部普通用户子列表
     */
    @GetMapping("/listAll")
    public List<Tourist> listAll(Tourist tourist) {
        return touristService.selectTouristList(tourist);
    }

    /**
     * 获取普通用户子详细信息
     */
    @GetMapping(value = "/info/{id}")
    public Result getInfo(@PathVariable("id") Long id) {
        return Result.success(touristService.selectTouristById(id));
    }

    /**
     * 新增普通用户子
     */
    @PostMapping("/add")
    public Result add(@RequestBody Tourist tourist) {
        return touristService.insertTourist(tourist) > 0 ? Result.success("新增成功") : Result.error("新增失败");
    }

    /**
     * 修改普通用户子
     */
    @PutMapping
    public Result update(@RequestBody Tourist tourist) {
        return touristService.updateTourist(tourist) > 0 ? Result.success("修改成功") : Result.error("修改失败");
    }

    /**
     * 删除普通用户子
     */
	@DeleteMapping("/{id}")
    public Result delete(@PathVariable Long id) {
        return touristService.deleteTouristById(id) > 0 ? Result.success("删除成功") : Result.error("删除失败");
    }
}
