From e9747247d58a0423d5e40fda5c5b37b4b4526495 Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Mon, 23 Jan 2023 13:14:21 +0100 Subject: [feature] Implement `/api/v1/reports` endpoints on client API (#1330) * start adding report client api * route + test reports get * start report create endpoint * you can create reports now babyy * stub account report processor * add single reportGet endpoint * fix test * add more filtering params to /api/v1/reports GET * update swagger * use marshalIndent in tests * add + test missing Link info --- internal/typeutils/internaltofrontend.go | 38 ++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'internal/typeutils/internaltofrontend.go') diff --git a/internal/typeutils/internaltofrontend.go b/internal/typeutils/internaltofrontend.go index 00903cfe0..dbd1a3822 100644 --- a/internal/typeutils/internaltofrontend.go +++ b/internal/typeutils/internaltofrontend.go @@ -807,6 +807,44 @@ func (c *converter) DomainBlockToAPIDomainBlock(ctx context.Context, b *gtsmodel return domainBlock, nil } +func (c *converter) ReportToAPIReport(ctx context.Context, r *gtsmodel.Report) (*apimodel.Report, error) { + report := &apimodel.Report{ + ID: r.ID, + CreatedAt: util.FormatISO8601(r.CreatedAt), + ActionTaken: !r.ActionTakenAt.IsZero(), + Category: "other", // todo: only support default 'other' category right now + Comment: r.Comment, + Forwarded: *r.Forwarded, + StatusIDs: r.StatusIDs, + RuleIDs: []int{}, // todo: not supported yet + } + + if !r.ActionTakenAt.IsZero() { + actionTakenAt := util.FormatISO8601(r.ActionTakenAt) + report.ActionTakenAt = &actionTakenAt + } + + if actionComment := r.ActionTaken; actionComment != "" { + report.ActionComment = &actionComment + } + + if r.TargetAccount == nil { + tAccount, err := c.db.GetAccountByID(ctx, r.TargetAccountID) + if err != nil { + return nil, fmt.Errorf("ReportToAPIReport: error getting target account with id %s from the db: %s", r.TargetAccountID, err) + } + r.TargetAccount = tAccount + } + + apiAccount, err := c.AccountToAPIAccountPublic(ctx, r.TargetAccount) + if err != nil { + return nil, fmt.Errorf("ReportToAPIReport: error converting target account to api: %s", err) + } + report.TargetAccount = apiAccount + + return report, nil +} + // convertAttachmentsToAPIAttachments will convert a slice of GTS model attachments to frontend API model attachments, falling back to IDs if no GTS models supplied. func (c *converter) convertAttachmentsToAPIAttachments(ctx context.Context, attachments []*gtsmodel.MediaAttachment, attachmentIDs []string) ([]apimodel.Attachment, error) { var errs gtserror.MultiError -- cgit v1.2.3