@@ -20,25 +20,24 @@ import (
20
20
type SpamReportStatusType int
21
21
22
22
const (
23
- SpamReportStatusTypePending = iota // 0
24
- SpamReportStatusTypeProcessing // 1
25
- SpamReportStatusTypeProcessed // 2
26
- SpamReportStatusTypeDismissed // 3
23
+ SpamReportStatusTypePending = iota // 0
24
+ SpamReportStatusTypeLocked // 1
25
+ SpamReportStatusTypeProcessed // 2
26
+ SpamReportStatusTypeDismissed // 3
27
27
)
28
28
29
29
func (t SpamReportStatusType ) String () string {
30
30
switch t {
31
31
case SpamReportStatusTypePending :
32
- return "Pending "
33
- case SpamReportStatusTypeProcessing :
34
- return "Processing "
32
+ return "pending "
33
+ case SpamReportStatusTypeLocked :
34
+ return "locked "
35
35
case SpamReportStatusTypeProcessed :
36
- return "Processed "
36
+ return "processed "
37
37
case SpamReportStatusTypeDismissed :
38
- return "Dismissed"
39
- default :
40
- panic (fmt .Sprintf ("unknown SpamReportStatusType: %d" , t ))
38
+ return "dismissed"
41
39
}
40
+ return "unknown"
42
41
}
43
42
44
43
type SpamReport struct {
@@ -58,26 +57,49 @@ func init() {
58
57
db .RegisterModel (new (SpamReport ))
59
58
}
60
59
61
- type ListSpamReportResults struct {
60
+ type ListSpamReportsOptions struct {
61
+ db.ListOptions
62
+ Status SpamReportStatusType
63
+ }
64
+
65
+ type ListSpamReportsResults struct {
62
66
ID int64
67
+ CreatedUnix timeutil.TimeStamp
68
+ UpdatedUnix timeutil.TimeStamp
63
69
Status SpamReportStatusType
64
70
UserName string
65
71
ReporterName string
66
72
}
67
73
68
- func ListSpamReports (ctx context.Context , opts * db. ListOptions ) ([]* ListSpamReportResults , int64 , error ) {
74
+ func ListSpamReports (ctx context.Context , opts * ListSpamReportsOptions ) ([]* ListSpamReportsResults , int64 , error ) {
69
75
opts .SetDefaultValues ()
70
76
count , err := db .GetEngine (ctx ).Count (new (SpamReport ))
71
77
if err != nil {
72
78
return nil , 0 , fmt .Errorf ("Count: %w" , err )
73
79
}
74
- spamReports := make ([]* ListSpamReportResults , 0 , opts .PageSize )
80
+ spamReports := make ([]* ListSpamReportsResults , 0 , opts .PageSize )
75
81
err = db .GetEngine (ctx ).Table ("user_spamreport" ).
76
- Select ("user_spamreport.id, user_spamreport.status, user.name as user_name, reporter.name as reporter_name" ).
82
+ Select ("user_spamreport.id, user_spamreport.created_unix, user_spamreport.updated_unix, user_spamreport. status, user.name as user_name, reporter.name as reporter_name" ).
77
83
Join ("LEFT" , "`user`" , "`user`.id = user_spamreport.user_id" ).
78
84
Join ("LEFT" , "`user` as reporter" , "`reporter`.id = user_spamreport.reporter_id" ).
85
+ Where ("status = ?" , opts .Status ).
79
86
Limit (opts .PageSize , (opts .Page - 1 )* opts .PageSize ).
80
87
Find (& spamReports )
81
88
82
89
return spamReports , count , err
83
90
}
91
+
92
+ type SpamReportStatusCounts struct {
93
+ Count int64
94
+ Status SpamReportStatusType
95
+ }
96
+
97
+ func GetSpamReportStatusCounts (ctx context.Context ) ([]* SpamReportStatusCounts , error ) {
98
+ statusCounts := make ([]* SpamReportStatusCounts , 0 , 4 ) // 4 status types
99
+ err := db .GetEngine (ctx ).Table ("user_spamreport" ).
100
+ Select ("count(*) as count, status" ).
101
+ GroupBy ("status" ).
102
+ Find (& statusCounts )
103
+
104
+ return statusCounts , err
105
+ }
0 commit comments