package com.younike.member.controller;

import java.util.List;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import com.younike.common.bean.APIResult;
import com.younike.common.bean.ResultGenerator;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import com.younike.common.core.page.PageParam;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.younike.common.annotation.OpLog;
import com.younike.common.core.controller.BaseController;
import com.younike.common.constant.BusinessType;
import com.younike.service.pojo.AppMemberVlog;
import com.younike.service.service.IAppMemberVlogService;

/**
 * 会员日记Controller
 *
 * @author dail
 * @date 2022-05-24
 */
@RestController
@RequestMapping("/appMemberVlog")
public class AppMemberVlogController extends BaseController {
    @Autowired
    private IAppMemberVlogService appMemberVlogService;

    /**
     * 查询会员日记列表
     */
    @RequiresPermissions("vlog:list")
    @PostMapping("/list")
    public Page list(@RequestBody PageParam<AppMemberVlog> page) {

        return appMemberVlogService.page(page);
    }


    /**
     * 获取会员日记详细信息
     */
    @RequiresPermissions("vlog:query")
    @GetMapping(value = "/{memberVlogId}")
    public APIResult getInfo(@PathVariable("memberVlogId") String memberVlogId) {
        return ResultGenerator.getSuccessResult(appMemberVlogService.getById(memberVlogId));
    }

    /**
     * 新增会员日记
     */
    @RequiresPermissions("vlog:add")
    @OpLog(title = "会员日记", type = BusinessType.INSERT)
    @PostMapping
    public APIResult add(@RequestBody AppMemberVlog appMemberVlog) {
        return ResultGenerator.getSuccessResult(appMemberVlogService.save(appMemberVlog));
    }

    /**
     * 修改会员日记
     */
    @RequiresPermissions("vlog:edit")
    @OpLog(title = "会员日记", type = BusinessType.UPDATE)
    @PutMapping
    public APIResult edit(@RequestBody AppMemberVlog appMemberVlog) {
        return ResultGenerator.getSuccessResult(appMemberVlogService.updateById(appMemberVlog));
    }

    /**
     * 删除会员日记
     */
    @RequiresPermissions("vlog:remove")
    @OpLog(title = "会员日记", type = BusinessType.DELETE)
    @DeleteMapping("/{memberVlogIds}")
    public APIResult remove(@PathVariable List<String> memberVlogIds) {
        return ResultGenerator.getSuccessResult(appMemberVlogService.removeByIds(memberVlogIds));
    }
}
