/*
 * Copyright (c) 2018-2999 广州亚米信息科技有限公司 All rights reserved.
 *
 * https://www.gz-yami.com/
 *
 */

package com.yami.shop.user.platform.controller;

import com.yami.shop.user.comment.model.UserLevelCategory;
import com.yami.shop.user.comment.service.UserLevelCategoryService;
import com.yami.shop.common.annotation.SysLog;

import javax.validation.Valid;

import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import lombok.AllArgsConstructor;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yami.shop.common.util.PageParam;
import com.baomidou.mybatisplus.core.metadata.IPage;


/**
 * 用户等级分类管理实现
 *
 * @author LGH
 * @version 1.0.0
 * @since 2020-02-26
 */
@RestController
@AllArgsConstructor
@RequestMapping("/user/userLevelCategory" )
public class UserLevelCategoryController {

    private final UserLevelCategoryService userLevelCategoryService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param userLevelCategory
     * @return 分页数据
     */
    @GetMapping("/page" )
    public ResponseEntity<IPage<UserLevelCategory>> getUserLevelCategoryPage(PageParam<UserLevelCategory> page, UserLevelCategory userLevelCategory) {
        return ResponseEntity.ok(userLevelCategoryService.page(page, new LambdaQueryWrapper<UserLevelCategory>()));
    }


    /**
     * 通过id查询
     * @param userLevelCategoryId id
     * @return 单个数据
     */
    @GetMapping("/info/{userLevelCategoryId}" )
    public ResponseEntity<UserLevelCategory> getById(@PathVariable("userLevelCategoryId") Long userLevelCategoryId) {
        return ResponseEntity.ok(userLevelCategoryService.getById(userLevelCategoryId));
    }

    /**
     * 新增
     * @param userLevelCategory
     * @return 是否新增成功
     */
    @SysLog("新增" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('user:userLevelCategory:save')" )
    public ResponseEntity<Boolean> save(@RequestBody @Valid UserLevelCategory userLevelCategory) {
        return ResponseEntity.ok(userLevelCategoryService.save(userLevelCategory));
    }

    /**
     * 修改
     * @param userLevelCategory
     * @return 是否修改成功
     */
    @SysLog("修改" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('user:userLevelCategory:update')" )
    public ResponseEntity<Boolean> updateById(@RequestBody @Valid UserLevelCategory userLevelCategory) {
        return ResponseEntity.ok(userLevelCategoryService.updateById(userLevelCategory));
    }

    /**
     * 通过id删除
     * @param userLevelCategoryId id
     * @return 是否删除成功
     */
    @SysLog("删除" )
    @DeleteMapping("/{userLevelCategoryId}" )
    @PreAuthorize("@pms.hasPermission('user:userLevelCategory:delete')" )
    public ResponseEntity<Boolean> removeById(@PathVariable Long userLevelCategoryId) {
        return ResponseEntity.ok(userLevelCategoryService.removeById(userLevelCategoryId));
    }

}
