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.AppMemberCollection;
import com.younike.service.service.IAppMemberCollectionService;

/**
 * 会员收藏记录Controller
 *
 * @author dail
 * @date 2022-05-24
 */
@RestController
@RequestMapping("/appMemberCollection")
public class AppMemberCollectionController extends BaseController {
    @Autowired
    private IAppMemberCollectionService appMemberCollectionService;

    /**
     * 查询会员收藏记录列表
     */
    @RequiresPermissions("collection:list")
    @PostMapping("/list")
    public Page list(@RequestBody PageParam<AppMemberCollection> page) {

        return appMemberCollectionService.page(page);
    }


    /**
     * 获取会员收藏记录详细信息
     */
    @RequiresPermissions("collection:query")
    @GetMapping(value = "/{memberCollectionId}")
    public APIResult getInfo(@PathVariable("memberCollectionId") String memberCollectionId) {
        return ResultGenerator.getSuccessResult(appMemberCollectionService.getById(memberCollectionId));
    }

    /**
     * 新增会员收藏记录
     */
    @RequiresPermissions("collection:add")
    @OpLog(title = "会员收藏记录", type = BusinessType.INSERT)
    @PostMapping
    public APIResult add(@RequestBody AppMemberCollection appMemberCollection) {
        return ResultGenerator.getSuccessResult(appMemberCollectionService.save(appMemberCollection));
    }

    /**
     * 修改会员收藏记录
     */
    @RequiresPermissions("collection:edit")
    @OpLog(title = "会员收藏记录", type = BusinessType.UPDATE)
    @PutMapping
    public APIResult edit(@RequestBody AppMemberCollection appMemberCollection) {
        return ResultGenerator.getSuccessResult(appMemberCollectionService.updateById(appMemberCollection));
    }

    /**
     * 删除会员收藏记录
     */
    @RequiresPermissions("collection:remove")
    @OpLog(title = "会员收藏记录", type = BusinessType.DELETE)
    @DeleteMapping("/{memberCollectionIds}")
    public APIResult remove(@PathVariable List<String> memberCollectionIds) {
        return ResultGenerator.getSuccessResult(appMemberCollectionService.removeByIds(memberCollectionIds));
    }
}
