/*
 * 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.UserScoreLog;
import com.yami.shop.user.comment.service.UserScoreLogService;
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/userScoreLog" )
public class UserScoreLogController {

    private final UserScoreLogService userScoreLogService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param userScoreLog 用户积分记录
     * @return 分页数据
     */
    @GetMapping("/page" )
    public ResponseEntity<IPage<UserScoreLog>> getUserScoreLogPage(PageParam<UserScoreLog> page, UserScoreLog userScoreLog) {
        return ResponseEntity.ok(userScoreLogService.getPage(page,userScoreLog));
    }


    /**
     * 通过id查询用户积分记录
     * @param logId id
     * @return 单个数据
     */
    @GetMapping("/info/{logId}" )
    public ResponseEntity<UserScoreLog> getById(@PathVariable("logId") Long logId) {
        return ResponseEntity.ok(userScoreLogService.getById(logId));
    }

    /**
     * 新增用户积分记录
     * @param userScoreLog 用户积分记录
     * @return 是否新增成功
     */
    @SysLog("新增用户积分记录" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('user:userScoreLog:save')" )
    public ResponseEntity<Boolean> save(@RequestBody @Valid UserScoreLog userScoreLog) {
        return ResponseEntity.ok(userScoreLogService.save(userScoreLog));
    }

    /**
     * 修改用户积分记录
     * @param userScoreLog 用户积分记录
     * @return 是否修改成功
     */
    @SysLog("修改用户积分记录" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('user:userScoreLog:update')" )
    public ResponseEntity<Boolean> updateById(@RequestBody @Valid UserScoreLog userScoreLog) {
        return ResponseEntity.ok(userScoreLogService.updateById(userScoreLog));
    }

    /**
     * 通过id删除用户积分记录
     * @param logId id
     * @return 是否删除成功
     */
    @SysLog("删除用户积分记录" )
    @DeleteMapping("/{logId}" )
    @PreAuthorize("@pms.hasPermission('user:userScoreLog:delete')" )
    public ResponseEntity<Boolean> removeById(@PathVariable Long logId) {
        return ResponseEntity.ok(userScoreLogService.removeById(logId));
    }

}
