package dao

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

type ProjectReviewDao struct{}

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

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

func (p ProjectReviewDao) UpdateProjectReview(reviewProject *entity.ReviewProject) error {
	err := Db.Debug().Model(&entity.ReviewProject{}).Where("id = ?", reviewProject.ID).Updates(reviewProject).Error
	if err != nil {
		return err
	}
	return nil
}
