summaryrefslogtreecommitdiff
path: root/internal/processing/report
diff options
context:
space:
mode:
Diffstat (limited to 'internal/processing/report')
-rw-r--r--internal/processing/report/create.go3
-rw-r--r--internal/processing/report/get.go (renamed from internal/processing/report/getreports.go)35
-rw-r--r--internal/processing/report/getreport.go51
-rw-r--r--internal/processing/report/report.go15
4 files changed, 38 insertions, 66 deletions
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/getreports.go b/internal/processing/report/get.go
index e58e847a2..af2079b8a 100644
--- a/internal/processing/report/getreports.go
+++ b/internal/processing/report/get.go
@@ -30,7 +30,40 @@ import (
"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) {
+// 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 {
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 <http://www.gnu.org/licenses/>.
-*/
-
-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/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,