package models

import (
	"log"
)


type RaspFeedback struct {
	Id 			string 	`json:"id" gorm:"PRIMARY_KEY"`
	Addr        string `json:"addr"`
	Description string	`json:"description"`
	Complete 	bool	`json:"complete"`
}

func IsComplete(id string)bool{
	var feedback RaspFeedback
	err:=db.Model(&RaspFeedback{}).Where("id=?",id).First(&feedback).Error
	if err!=nil{
		log.Println(err)
		return true
	}
	//fmt.Println(feedback)
	if feedback==(RaspFeedback{}){
		return true
	}
	return feedback.Complete
}

func AddFeedBack(fd RaspFeedback)bool{
	if err:=db.Create(&fd).Error;err != nil {
		db.Save(&fd)
		log.Println(err)
		return false
	}
	return true
}

func DelFeedBack(id string){
	err:=db.Delete(&RaspFeedback{}).Where("id=?",id).Error
	if err!=nil{
		log.Println(err)
	}
}


func DropFeedBack(){
	db.DropTable(&RaspFeedback{})
}

func Complete(fd RaspFeedback){
	db.Model(&fd).Update("Complete",true)

}