2022-09-27 17:59:05 +08:00
|
|
|
package report
|
|
|
|
|
|
|
|
import (
|
2022-10-24 16:51:05 +08:00
|
|
|
"github.com/answerdev/answer/internal/entity"
|
|
|
|
"github.com/answerdev/answer/internal/schema"
|
|
|
|
"github.com/answerdev/answer/internal/service/object_info"
|
|
|
|
"github.com/answerdev/answer/internal/service/report_common"
|
|
|
|
"github.com/answerdev/answer/pkg/obj"
|
2022-09-27 17:59:05 +08:00
|
|
|
"golang.org/x/net/context"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ReportService user service
|
|
|
|
type ReportService struct {
|
|
|
|
reportRepo report_common.ReportRepo
|
|
|
|
objectInfoService *object_info.ObjService
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewReportService new report service
|
|
|
|
func NewReportService(reportRepo report_common.ReportRepo,
|
2022-11-01 15:25:44 +08:00
|
|
|
objectInfoService *object_info.ObjService,
|
|
|
|
) *ReportService {
|
2022-09-27 17:59:05 +08:00
|
|
|
return &ReportService{
|
|
|
|
reportRepo: reportRepo,
|
|
|
|
objectInfoService: objectInfoService,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddReport add report
|
|
|
|
func (rs *ReportService) AddReport(ctx context.Context, req *schema.AddReportReq) (err error) {
|
|
|
|
objectTypeNumber, err := obj.GetObjectTypeNumberByObjectID(req.ObjectID)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO this reported user id should be get by revision
|
|
|
|
objInfo, err := rs.objectInfoService.GetInfo(ctx, req.ObjectID)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
report := &entity.Report{
|
|
|
|
UserID: req.UserID,
|
2022-11-24 16:11:43 +08:00
|
|
|
ReportedUserID: objInfo.ObjectCreatorUserID,
|
2022-09-27 17:59:05 +08:00
|
|
|
ObjectID: req.ObjectID,
|
|
|
|
ObjectType: objectTypeNumber,
|
|
|
|
ReportType: req.ReportType,
|
|
|
|
Content: req.Content,
|
|
|
|
Status: entity.ReportStatusPending,
|
|
|
|
}
|
|
|
|
return rs.reportRepo.AddReport(ctx, report)
|
|
|
|
}
|