package models

import (
	"log"
	"github.com/jinzhu/gorm"
)


type RaspFeedbackList struct {
	Id 			string 	`json:"id" gorm:"PRIMARY_KEY"`
	Addr        string  `json:"addr"`
	Description string	`json:"description"`
	Addtime 	int64	`json:"addtime"`
}

type ReqRaspFeedbackList struct {
	Addr string `json:"addr" binding:"required"`
	Page int32 `json:"page"`
	Pagesize int32 `json:"pagesize"`
}


func AddFeedBackList(fd RaspFeedbackList)bool{
	err:=db.Create(&fd)
	if err!=nil{
		db.Save(&fd)
		log.Println(err)
		return false
	}
	return true
}

func GetAddrFeedBackList(req *ReqRaspFeedbackList) ([]*RaspFeedbackList, error) {
	var txs []*RaspFeedbackList
	maps := map[string]interface{}{"return_addr":req.Addr}
	err := db.Where(maps).Order("id "+"desc").Offset((req.Page-1)*req.Pagesize).Limit(req.Pagesize).Find(&txs).Error
	if err != nil && err != gorm.ErrRecordNotFound {
		return nil, err
	}

	return txs, nil
}