summaryrefslogtreecommitdiff
path: root/internal/typeutils/internaltofrontend.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2023-01-23 13:14:21 +0100
committerLibravatar GitHub <noreply@github.com>2023-01-23 13:14:21 +0100
commite9747247d58a0423d5e40fda5c5b37b4b4526495 (patch)
tree5574b05f1dec1ad88c49b9891f1e54719f1b9eb1 /internal/typeutils/internaltofrontend.go
parent[chore] bump go version to 1.19.5 (#1377) (diff)
downloadgotosocial-e9747247d58a0423d5e40fda5c5b37b4b4526495.tar.xz
[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
Diffstat (limited to 'internal/typeutils/internaltofrontend.go')
-rw-r--r--internal/typeutils/internaltofrontend.go38
1 files changed, 38 insertions, 0 deletions
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