From b6fbdc66c1ce1ec61ebfb6fcc0351ea627a1d288 Mon Sep 17 00:00:00 2001
From: tobi <31960611+tsmethurst@users.noreply.github.com>
Date: Wed, 22 Feb 2023 16:05:26 +0100
Subject: [chore] Deinterface processor and subprocessors (#1501)
* [chore] Deinterface processor and subprocessors
* expose subprocessors via function calls
* missing license header
---
 internal/processing/report/create.go     |   3 +-
 internal/processing/report/get.go        | 112 +++++++++++++++++++++++++++++++
 internal/processing/report/getreport.go  |  51 --------------
 internal/processing/report/getreports.go |  79 ----------------------
 internal/processing/report/report.go     |  15 +----
 5 files changed, 116 insertions(+), 144 deletions(-)
 create mode 100644 internal/processing/report/get.go
 delete mode 100644 internal/processing/report/getreport.go
 delete mode 100644 internal/processing/report/getreports.go
(limited to 'internal/processing/report')
diff --git a/internal/processing/report/create.go b/internal/processing/report/create.go
index a7e83b656..726d11666 100644
--- a/internal/processing/report/create.go
+++ b/internal/processing/report/create.go
@@ -33,7 +33,8 @@ import (
 	"github.com/superseriousbusiness/gotosocial/internal/uris"
 )
 
-func (p *processor) Create(ctx context.Context, account *gtsmodel.Account, form *apimodel.ReportCreateRequest) (*apimodel.Report, gtserror.WithCode) {
+// Create creates one user report / flag, using the provided form parameters.
+func (p *Processor) Create(ctx context.Context, account *gtsmodel.Account, form *apimodel.ReportCreateRequest) (*apimodel.Report, gtserror.WithCode) {
 	if account.ID == form.AccountID {
 		err := errors.New("cannot report your own account")
 		return nil, gtserror.NewErrorBadRequest(err, err.Error())
diff --git a/internal/processing/report/get.go b/internal/processing/report/get.go
new file mode 100644
index 000000000..af2079b8a
--- /dev/null
+++ b/internal/processing/report/get.go
@@ -0,0 +1,112 @@
+/*
+   GoToSocial
+   Copyright (C) 2021-2023 GoToSocial Authors admin@gotosocial.org
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU Affero General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU Affero General Public License for more details.
+
+   You should have received a copy of the GNU Affero General Public License
+   along with this program.  If not, see .
+*/
+
+package report
+
+import (
+	"context"
+	"fmt"
+	"strconv"
+
+	apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
+	"github.com/superseriousbusiness/gotosocial/internal/db"
+	"github.com/superseriousbusiness/gotosocial/internal/gtserror"
+	"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
+	"github.com/superseriousbusiness/gotosocial/internal/util"
+)
+
+// Get returns the user view of a moderation report, with the given id.
+func (p *Processor) Get(ctx context.Context, account *gtsmodel.Account, id string) (*apimodel.Report, gtserror.WithCode) {
+	report, err := p.db.GetReportByID(ctx, id)
+	if err != nil {
+		if err == db.ErrNoEntries {
+			return nil, gtserror.NewErrorNotFound(err)
+		}
+		return nil, gtserror.NewErrorInternalError(err)
+	}
+
+	if report.AccountID != account.ID {
+		err = fmt.Errorf("report with id %s does not belong to account %s", report.ID, account.ID)
+		return nil, gtserror.NewErrorNotFound(err)
+	}
+
+	apiReport, err := p.tc.ReportToAPIReport(ctx, report)
+	if err != nil {
+		return nil, gtserror.NewErrorInternalError(fmt.Errorf("error converting report to api: %s", err))
+	}
+
+	return apiReport, nil
+}
+
+// GetMultiple returns multiple reports created by the given account, filtered according to the provided parameters.
+func (p *Processor) GetMultiple(
+	ctx context.Context,
+	account *gtsmodel.Account,
+	resolved *bool,
+	targetAccountID string,
+	maxID string,
+	sinceID string,
+	minID string,
+	limit int,
+) (*apimodel.PageableResponse, gtserror.WithCode) {
+	reports, err := p.db.GetReports(ctx, resolved, account.ID, targetAccountID, maxID, sinceID, minID, limit)
+	if err != nil {
+		if err == db.ErrNoEntries {
+			return util.EmptyPageableResponse(), nil
+		}
+		return nil, gtserror.NewErrorInternalError(err)
+	}
+
+	count := len(reports)
+	items := make([]interface{}, 0, count)
+	nextMaxIDValue := ""
+	prevMinIDValue := ""
+	for i, r := range reports {
+		item, err := p.tc.ReportToAPIReport(ctx, r)
+		if err != nil {
+			return nil, gtserror.NewErrorInternalError(fmt.Errorf("error converting report to api: %s", err))
+		}
+
+		if i == count-1 {
+			nextMaxIDValue = item.ID
+		}
+
+		if i == 0 {
+			prevMinIDValue = item.ID
+		}
+
+		items = append(items, item)
+	}
+
+	extraQueryParams := []string{}
+	if resolved != nil {
+		extraQueryParams = append(extraQueryParams, "resolved="+strconv.FormatBool(*resolved))
+	}
+	if targetAccountID != "" {
+		extraQueryParams = append(extraQueryParams, "target_account_id="+targetAccountID)
+	}
+
+	return util.PackagePageableResponse(util.PageableResponseParams{
+		Items:            items,
+		Path:             "/api/v1/reports",
+		NextMaxIDValue:   nextMaxIDValue,
+		PrevMinIDValue:   prevMinIDValue,
+		Limit:            limit,
+		ExtraQueryParams: extraQueryParams,
+	})
+}
diff --git a/internal/processing/report/getreport.go b/internal/processing/report/getreport.go
deleted file mode 100644
index 6d4a18daa..000000000
--- a/internal/processing/report/getreport.go
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
-   GoToSocial
-   Copyright (C) 2021-2023 GoToSocial Authors admin@gotosocial.org
-
-   This program is free software: you can redistribute it and/or modify
-   it under the terms of the GNU Affero General Public License as published by
-   the Free Software Foundation, either version 3 of the License, or
-   (at your option) any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU Affero General Public License for more details.
-
-   You should have received a copy of the GNU Affero General Public License
-   along with this program.  If not, see .
-*/
-
-package report
-
-import (
-	"context"
-	"fmt"
-
-	apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
-	"github.com/superseriousbusiness/gotosocial/internal/db"
-	"github.com/superseriousbusiness/gotosocial/internal/gtserror"
-	"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
-)
-
-func (p *processor) ReportGet(ctx context.Context, account *gtsmodel.Account, id string) (*apimodel.Report, gtserror.WithCode) {
-	report, err := p.db.GetReportByID(ctx, id)
-	if err != nil {
-		if err == db.ErrNoEntries {
-			return nil, gtserror.NewErrorNotFound(err)
-		}
-		return nil, gtserror.NewErrorInternalError(err)
-	}
-
-	if report.AccountID != account.ID {
-		err = fmt.Errorf("report with id %s does not belong to account %s", report.ID, account.ID)
-		return nil, gtserror.NewErrorNotFound(err)
-	}
-
-	apiReport, err := p.tc.ReportToAPIReport(ctx, report)
-	if err != nil {
-		return nil, gtserror.NewErrorInternalError(fmt.Errorf("error converting report to api: %s", err))
-	}
-
-	return apiReport, nil
-}
diff --git a/internal/processing/report/getreports.go b/internal/processing/report/getreports.go
deleted file mode 100644
index e58e847a2..000000000
--- a/internal/processing/report/getreports.go
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
-   GoToSocial
-   Copyright (C) 2021-2023 GoToSocial Authors admin@gotosocial.org
-
-   This program is free software: you can redistribute it and/or modify
-   it under the terms of the GNU Affero General Public License as published by
-   the Free Software Foundation, either version 3 of the License, or
-   (at your option) any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU Affero General Public License for more details.
-
-   You should have received a copy of the GNU Affero General Public License
-   along with this program.  If not, see .
-*/
-
-package report
-
-import (
-	"context"
-	"fmt"
-	"strconv"
-
-	apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
-	"github.com/superseriousbusiness/gotosocial/internal/db"
-	"github.com/superseriousbusiness/gotosocial/internal/gtserror"
-	"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
-	"github.com/superseriousbusiness/gotosocial/internal/util"
-)
-
-func (p *processor) ReportsGet(ctx context.Context, account *gtsmodel.Account, resolved *bool, targetAccountID string, maxID string, sinceID string, minID string, limit int) (*apimodel.PageableResponse, gtserror.WithCode) {
-	reports, err := p.db.GetReports(ctx, resolved, account.ID, targetAccountID, maxID, sinceID, minID, limit)
-	if err != nil {
-		if err == db.ErrNoEntries {
-			return util.EmptyPageableResponse(), nil
-		}
-		return nil, gtserror.NewErrorInternalError(err)
-	}
-
-	count := len(reports)
-	items := make([]interface{}, 0, count)
-	nextMaxIDValue := ""
-	prevMinIDValue := ""
-	for i, r := range reports {
-		item, err := p.tc.ReportToAPIReport(ctx, r)
-		if err != nil {
-			return nil, gtserror.NewErrorInternalError(fmt.Errorf("error converting report to api: %s", err))
-		}
-
-		if i == count-1 {
-			nextMaxIDValue = item.ID
-		}
-
-		if i == 0 {
-			prevMinIDValue = item.ID
-		}
-
-		items = append(items, item)
-	}
-
-	extraQueryParams := []string{}
-	if resolved != nil {
-		extraQueryParams = append(extraQueryParams, "resolved="+strconv.FormatBool(*resolved))
-	}
-	if targetAccountID != "" {
-		extraQueryParams = append(extraQueryParams, "target_account_id="+targetAccountID)
-	}
-
-	return util.PackagePageableResponse(util.PageableResponseParams{
-		Items:            items,
-		Path:             "/api/v1/reports",
-		NextMaxIDValue:   nextMaxIDValue,
-		PrevMinIDValue:   prevMinIDValue,
-		Limit:            limit,
-		ExtraQueryParams: extraQueryParams,
-	})
-}
diff --git a/internal/processing/report/report.go b/internal/processing/report/report.go
index 8658ac808..b5f4b301e 100644
--- a/internal/processing/report/report.go
+++ b/internal/processing/report/report.go
@@ -19,31 +19,20 @@
 package report
 
 import (
-	"context"
-
-	apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
 	"github.com/superseriousbusiness/gotosocial/internal/concurrency"
 	"github.com/superseriousbusiness/gotosocial/internal/db"
-	"github.com/superseriousbusiness/gotosocial/internal/gtserror"
-	"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
 	"github.com/superseriousbusiness/gotosocial/internal/messages"
 	"github.com/superseriousbusiness/gotosocial/internal/typeutils"
 )
 
-type Processor interface {
-	ReportsGet(ctx context.Context, account *gtsmodel.Account, resolved *bool, targetAccountID string, maxID string, sinceID string, minID string, limit int) (*apimodel.PageableResponse, gtserror.WithCode)
-	ReportGet(ctx context.Context, account *gtsmodel.Account, id string) (*apimodel.Report, gtserror.WithCode)
-	Create(ctx context.Context, account *gtsmodel.Account, form *apimodel.ReportCreateRequest) (*apimodel.Report, gtserror.WithCode)
-}
-
-type processor struct {
+type Processor struct {
 	db           db.DB
 	tc           typeutils.TypeConverter
 	clientWorker *concurrency.WorkerPool[messages.FromClientAPI]
 }
 
 func New(db db.DB, tc typeutils.TypeConverter, clientWorker *concurrency.WorkerPool[messages.FromClientAPI]) Processor {
-	return &processor{
+	return Processor{
 		tc:           tc,
 		db:           db,
 		clientWorker: clientWorker,
-- 
cgit v1.2.3