@@ -38,13 +38,44 @@ type App struct {
38
38
webTestFileStore WebTestFileStore
39
39
}
40
40
41
- // DatabaseVacuum implements core.App.
41
+ func New (
42
+ db database.Querier ,
43
+ fileStore FileStore ,
44
+ bus core.Bus ,
45
+ config * models.Config ,
46
+ endpointFactory endpoint.Factory ,
47
+ webTestFileStore WebTestFileStore ,
48
+ ) (App , func ()) {
49
+ a := App {
50
+ db : db ,
51
+ fileStore : fileStore ,
52
+ bus : bus ,
53
+ config : config ,
54
+ endpointFactory : endpointFactory ,
55
+ webTestFileStore : webTestFileStore ,
56
+ }
57
+
58
+ return a , a .init ()
59
+ }
60
+
61
+ func (a App ) init () func () {
62
+ return closers (
63
+ a .bus .OnEnvelopeCreated (func (ctx context.Context , evt models.EventEnvelopeCreated ) error {
64
+ return a .MailmanEnqueue (ctx , evt .ID )
65
+ }),
66
+ a .bus .OnEnvelopeDeleted (func (ctx context.Context , evt models.EventEnvelopeDeleted ) error {
67
+ return a .AttachmentOrphanDelete (ctx , a .Tracer (trace .SourceApp ))
68
+ }),
69
+ )
70
+ }
71
+
42
72
func (a App ) DatabaseVacuum (ctx context.Context ) error {
43
73
return repo .Vacuum (ctx , a .db )
44
74
}
45
75
46
76
func (a App ) RuleEndpointsGet (ctx context.Context , id int64 ) (models.RuleEndpoints , error ) {
47
- return repo .RuleEndpointsGet (ctx , a .db , id )
77
+ res , err := repo .RuleEndpointsGet (ctx , a .db , id )
78
+ return res , checkErr (err )
48
79
}
49
80
50
81
func (a App ) EnvelopeCount (ctx context.Context ) (int , error ) {
@@ -54,15 +85,15 @@ func (a App) EnvelopeCount(ctx context.Context) (int, error) {
54
85
func (a App ) RuleDelete (ctx context.Context , id int64 ) error {
55
86
r , err := repo .RuleGet (ctx , a .db , id )
56
87
if err != nil {
57
- return err
88
+ return checkErr ( err )
58
89
}
59
90
60
91
err = rule .Delete (r )
61
92
if err != nil {
62
93
return err
63
94
}
64
95
65
- return repo .RuleDelete (ctx , a .db , id )
96
+ return checkErr ( repo .RuleDelete (ctx , a .db , id ) )
66
97
}
67
98
68
99
func (App ) RuleExpressionCheck (ctx context.Context , expression string ) error {
@@ -80,18 +111,19 @@ func (App) RuleExpressionCheck(ctx context.Context, expression string) error {
80
111
}
81
112
82
113
func (a App ) AttachmentGet (ctx context.Context , id int64 ) (models.Attachment , error ) {
83
- return repo .AttachmentGet (ctx , a .db , id )
114
+ res , err := repo .AttachmentGet (ctx , a .db , id )
115
+ return res , checkErr (err )
84
116
}
85
117
86
118
func (a App ) EnvelopeSend (ctx context.Context , envelopeID int64 , endpointID int64 ) error {
87
119
env , err := repo .EnvelopeGet (ctx , a .db , envelopeID )
88
120
if err != nil {
89
- return err
121
+ return checkErr ( err )
90
122
}
91
123
92
124
endModel , err := repo .EndpointGet (ctx , a .db , endpointID )
93
125
if err != nil {
94
- return err
126
+ return checkErr ( err )
95
127
}
96
128
97
129
end , err := a .endpointFactory .Build (endModel )
@@ -102,39 +134,6 @@ func (a App) EnvelopeSend(ctx context.Context, envelopeID int64, endpointID int6
102
134
return end .Send (ctx , a .fileStore , env )
103
135
}
104
136
105
- func New (
106
- db database.Querier ,
107
- fileStore FileStore ,
108
- bus core.Bus ,
109
- config * models.Config ,
110
- endpointFactory endpoint.Factory ,
111
- webTestFileStore WebTestFileStore ,
112
- ) (App , func ()) {
113
- a := App {
114
- db : db ,
115
- fileStore : fileStore ,
116
- bus : bus ,
117
- config : config ,
118
- endpointFactory : endpointFactory ,
119
- webTestFileStore : webTestFileStore ,
120
- }
121
-
122
- return a , a .init ()
123
- }
124
-
125
- func (a App ) init () func () {
126
- return closers (
127
- a .bus .OnEnvelopeCreated (func (ctx context.Context , evt models.EventEnvelopeCreated ) error {
128
- return a .MailmanEnqueue (ctx , evt .ID )
129
- }),
130
- a .bus .OnEnvelopeDeleted (func (ctx context.Context , evt models.EventEnvelopeDeleted ) error {
131
- return a .AttachmentOrphanDelete (ctx , a .Tracer (trace .SourceApp ))
132
- }),
133
- )
134
- }
135
-
136
- var ErrorLogin = fmt .Errorf ("login invalid" )
137
-
138
137
func (a App ) AuthSMTPAnonymous () bool {
139
138
return a .config .AuthSMTP .Anonymous
140
139
}
@@ -149,15 +148,15 @@ func (a App) AuthHTTPLogin(ctx context.Context, username, password string) (mode
149
148
return models.User {}, nil
150
149
}
151
150
152
- return models.User {}, ErrorLogin
151
+ return models.User {}, models . ErrAuthInvalid
153
152
}
154
153
155
154
func (a App ) AuthSMTPLogin (ctx context.Context , username , password string ) error {
156
155
if a .config .AuthSMTP .Anonymous || auth .Check (a .config .AuthSMTP , username , password ) {
157
156
return nil
158
157
}
159
158
160
- return ErrorLogin
159
+ return models . ErrAuthInvalid
161
160
}
162
161
163
162
func (a App ) EnvelopeCreate (ctx context.Context , dtoMsg models.DTOMessageCreate , dtoDatts []models.DTOAttachmentCreate ) (int64 , error ) {
@@ -202,7 +201,7 @@ func (a App) EnvelopeCreate(ctx context.Context, dtoMsg models.DTOMessageCreate,
202
201
203
202
func (a App ) EnvelopeDelete (ctx context.Context , id int64 ) error {
204
203
if err := repo .EnvelopeDelete (ctx , a .db , id ); err != nil {
205
- return err
204
+ return checkErr ( err )
206
205
}
207
206
208
207
a .bus .EnvelopeDeleted (ctx )
@@ -211,7 +210,8 @@ func (a App) EnvelopeDelete(ctx context.Context, id int64) error {
211
210
}
212
211
213
212
func (a App ) EnvelopeGet (ctx context.Context , id int64 ) (models.Envelope , error ) {
214
- return repo .EnvelopeGet (ctx , a .db , id )
213
+ res , err := repo .EnvelopeGet (ctx , a .db , id )
214
+ return res , checkErr (err )
215
215
}
216
216
217
217
func (a App ) EnvelopeList (ctx context.Context , page pagination.Page , req models.DTOEnvelopeListRequest ) (models.DTOEnvelopeListResult , error ) {
@@ -232,7 +232,8 @@ func (a App) EnvelopeDrop(ctx context.Context) error {
232
232
}
233
233
234
234
func (a App ) MessageHTMLGet (ctx context.Context , id int64 ) (string , error ) {
235
- return repo .MessageHTMLGet (ctx , a .db , id )
235
+ res , err := repo .MessageHTMLGet (ctx , a .db , id )
236
+ return res , checkErr (err )
236
237
}
237
238
238
239
func (a App ) AttachmentList (ctx context.Context , page pagination.Page , req models.DTOAttachmentListRequest ) (models.DTOAttachmentListResult , error ) {
@@ -284,7 +285,7 @@ func (a App) RuleCreate(ctx context.Context, req models.DTORuleCreate) (int64, e
284
285
func (a App ) RuleUpdate (ctx context.Context , req models.DTORuleUpdate ) error {
285
286
r , err := repo .RuleGet (ctx , a .db , req .ID )
286
287
if err != nil {
287
- return err
288
+ return checkErr ( err )
288
289
}
289
290
290
291
r , err = rule .Update (r , req )
@@ -294,21 +295,22 @@ func (a App) RuleUpdate(ctx context.Context, req models.DTORuleUpdate) error {
294
295
295
296
err = repo .RuleUpdate (ctx , a .db , r )
296
297
if err != nil {
297
- return err
298
+ return checkErr ( err )
298
299
}
299
300
300
301
if req .Endpoints != nil {
301
302
err := repo .RuleEndpointsSet (ctx , a .db , r .ID , * req .Endpoints )
302
303
if err != nil {
303
- return err
304
+ return checkErr ( err )
304
305
}
305
306
}
306
307
307
308
return nil
308
309
}
309
310
310
311
func (a App ) RuleGet (ctx context.Context , id int64 ) (models.Rule , error ) {
311
- return repo .RuleGet (ctx , a .db , id )
312
+ res , err := repo .RuleGet (ctx , a .db , id )
313
+ return res , checkErr (err )
312
314
}
313
315
314
316
func (a App ) RuleList (ctx context.Context ) ([]models.Rule , error ) {
@@ -322,7 +324,7 @@ func (a App) RuleEndpointsList(ctx context.Context) ([]models.RuleEndpoints, err
322
324
func (a App ) EndpointTest (ctx context.Context , id int64 ) error {
323
325
e , err := repo .EndpointGet (ctx , a .db , id )
324
326
if err != nil {
325
- return err
327
+ return checkErr ( err )
326
328
}
327
329
328
330
end , err := a .endpointFactory .Build (e )
0 commit comments