package services import ( "github.com/ahmetb/go-linq/v3" "qteam/app/constants/common" "qteam/app/constants/errorcode" "qteam/app/http/entities/front" "qteam/app/models/activitymodel" "qteam/app/models/productmodel" "strings" ) func ActivityDetailService(id int) (code int, data front.ActivityResponse) { var err error var activity activitymodel.Activity code = errorcode.NotFound has, err := activitymodel.GetInstance().GetDb().Where("id=?", id).Get(&activity) if has { data.ResponseFromDb(activity) product := []productmodel.Product{} productIds := strings.Split(activity.ProductIds, ",") if count, err := productmodel.GetInstance().GetDb().Where("status = ?", common.STATUSABLED).In("id", productIds).FindAndCount(&product); err == nil { code = handErr(err) if count > 0 { linq.From(product).SelectT(func(in productmodel.Product) (d front.ProductResponse) { d.ResponseFromDb(in) return }).ToSlice(&data.Product) } } else { data.Product = make([]front.ProductResponse, 0) } } if err != nil { code = handErr(err) } return errorcode.Success, data }