package com.bizzan.bitrade.controller;

import static com.bizzan.bitrade.constant.SysConstant.SESSION_MEMBER;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.SessionAttribute;

import com.bizzan.bitrade.entity.MemberFeedback;
import com.bizzan.bitrade.entity.transform.AuthMember;
import com.bizzan.bitrade.service.MemberFeedbackService;
import com.bizzan.bitrade.util.MessageResult;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

@Api(value = "MemberFeedbackController" , tags = "意见反馈接口")
@RestController
@Slf4j
@RequestMapping("feedback")
public class MemberFeedbackController extends BaseController {

	@Autowired
	private MemberFeedbackService feedbackService;
	
	@ApiOperation(value="保存反馈意见", notes="保存反馈意见")
	@PostMapping("save")
    public MessageResult save(@SessionAttribute(SESSION_MEMBER) AuthMember user, MemberFeedback feedback) {
		feedback.setCreateTime(new Date());
		feedback.setMemberId(user.getId());
		feedbackService.save(feedback);
		return success();
	}
	
	@GetMapping("list")
    public MessageResult<Page<MemberFeedback>> list(@SessionAttribute(SESSION_MEMBER) AuthMember user, int pageNo, int pageSize) {
		MessageResult<Page<MemberFeedback>> mr = new MessageResult<Page<MemberFeedback>>(0, "success");
		Page<MemberFeedback> data = feedbackService.pageByMemberId(pageNo, pageSize, user.getId());
		mr.setData(data);
        return mr;
	}
}
