package com.ruoyi.wx.web.controller;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.wx.web.domain.dto.CreditDto;
import com.ruoyi.wx.web.service.IWxPersonCenterService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 *
 * 微信个人中心
 */
@Slf4j
@RestController
@RequestMapping("/wx/person")
public class WxPersonCenterController {
    @Autowired
    private IWxPersonCenterService wxPersonCenterService;

    /**
     *
     * 个人中心首页用户内容
     * @return
     */
    @GetMapping("/info")
    public AjaxResult getIndex() {
        try {
            return wxPersonCenterService.getIndex();
        } catch (SecurityException e) {
            return AjaxResult.error(e.getMessage());
        }
    }

    /**
     * 新增积分
     */
    @PostMapping("/add/credit")
    public AjaxResult addCredit(@RequestBody CreditDto creditDto) {
        try {
            boolean add = wxPersonCenterService.addCredit(creditDto);
            if (add) {
                return AjaxResult.success();
            }
            return AjaxResult.error();
        } catch (Exception e) {
            return AjaxResult.error(e.getMessage());
        }
    }

}
