package dao

import (
	"github.com/sirupsen/logrus"
	"youngee_b_api/app/entity"
)

type LocalLifeReviewDao struct{}

func (p LocalLifeReviewDao) Create(reviewInfo *entity.ReviewLocalLife) error {
	err := Db.Create(&reviewInfo).Error
	if err != nil {
		return err
	}
	return nil
}

func (p LocalLifeReviewDao) GetLocalReviewByStatus(status int64) ([]*entity.ReviewLocalLife, error) {
	var reviewLocalLifes []*entity.ReviewLocalLife
	err := Db.Model(entity.ReviewLocalLife{}).Where("status = ?", status).Find(&reviewLocalLifes).Error
	if err != nil {
		logrus.Errorf("[GetLocalReviewByStatus] error query mysql, err:%+v", err)
		return nil, err
	}
	return reviewLocalLifes, nil
}

func (p LocalLifeReviewDao) UpdateLocalReview(reviewLocalLife *entity.ReviewLocalLife) error {
	err := Db.Debug().Model(&entity.ReviewLocalLife{}).Where("id = ?", reviewLocalLife.ID).Updates(reviewLocalLife).Error
	if err != nil {
		return err
	}
	return nil
}
