1
1
use actix_web:: { get, post, web, HttpResponse , Responder } ;
2
2
use fplus_lib:: core:: {
3
- application:: file:: VerifierInput , ApplicationQueryParams , CompleteNewApplicationProposalInfo , CreateApplicationInfo , DcReachedInfo , GithubQueryParams , LDNApplication , RefillInfo , ValidationPullRequestData , VerifierActionsQueryParams
4
- } ;
3
+ application:: file:: VerifierInput , ApplicationQueryParams ,
4
+ CompleteNewApplicationProposalInfo , CreateApplicationInfo , DcReachedInfo ,
5
+ GithubQueryParams , LDNApplication , RefillInfo , ValidationPullRequestData ,
6
+ VerifierActionsQueryParams ,
7
+ } ;
5
8
6
9
#[ post( "/application" ) ]
7
10
pub async fn create ( info : web:: Json < CreateApplicationInfo > ) -> impl Responder {
@@ -21,24 +24,30 @@ pub async fn single(query: web::Query<ApplicationQueryParams>) -> impl Responder
21
24
let ApplicationQueryParams { id, owner, repo } = query. into_inner ( ) ;
22
25
23
26
match LDNApplication :: load_from_db ( id, owner, repo) . await {
24
- Ok ( app_file) => return HttpResponse :: Ok ( ) . body ( serde_json:: to_string_pretty ( & app_file) . unwrap ( ) ) ,
27
+ Ok ( app_file) => {
28
+ return HttpResponse :: Ok ( ) . body ( serde_json:: to_string_pretty ( & app_file) . unwrap ( ) )
29
+ }
25
30
Err ( e) => return HttpResponse :: BadRequest ( ) . body ( e. to_string ( ) ) ,
26
31
} ;
27
32
}
28
33
29
34
#[ post( "/application/trigger" ) ]
30
- pub async fn trigger (
31
- query : web :: Query < VerifierActionsQueryParams > ,
32
- ) -> impl Responder {
33
- let ldn_application = match LDNApplication :: load ( query . id . clone ( ) , query . owner . clone ( ) , query . repo . clone ( ) ) . await {
34
- Ok ( app) => app,
35
- Err ( e) => {
36
- return HttpResponse :: BadRequest ( ) . body ( e. to_string ( ) ) ;
37
- }
38
- } ;
35
+ pub async fn trigger ( query : web :: Query < VerifierActionsQueryParams > ) -> impl Responder {
36
+ let ldn_application =
37
+ match LDNApplication :: load ( query . id . clone ( ) , query . owner . clone ( ) , query . repo . clone ( ) ) . await
38
+ {
39
+ Ok ( app) => app,
40
+ Err ( e) => {
41
+ return HttpResponse :: BadRequest ( ) . body ( e. to_string ( ) ) ;
42
+ }
43
+ } ;
39
44
dbg ! ( & ldn_application) ;
40
45
match ldn_application
41
- . complete_governance_review ( query. github_username . clone ( ) , query. owner . clone ( ) , query. repo . clone ( ) )
46
+ . complete_governance_review (
47
+ query. github_username . clone ( ) ,
48
+ query. owner . clone ( ) ,
49
+ query. repo . clone ( ) ,
50
+ )
42
51
. await
43
52
{
44
53
Ok ( app) => HttpResponse :: Ok ( ) . body ( serde_json:: to_string_pretty ( & app) . unwrap ( ) ) ,
@@ -54,24 +63,28 @@ pub async fn propose(
54
63
info : web:: Json < CompleteNewApplicationProposalInfo > ,
55
64
query : web:: Query < VerifierActionsQueryParams > ,
56
65
) -> impl Responder {
57
- let CompleteNewApplicationProposalInfo {
58
- signer,
59
- request_id,
60
- } = info. into_inner ( ) ;
61
- let ldn_application = match LDNApplication :: load ( query. id . clone ( ) , query. owner . clone ( ) , query. repo . clone ( ) ) . await {
62
- Ok ( app) => app,
63
- Err ( e) => {
64
- return HttpResponse :: BadRequest ( ) . body ( e. to_string ( ) ) ;
65
- }
66
- } ;
66
+ let CompleteNewApplicationProposalInfo { signer, request_id } = info. into_inner ( ) ;
67
+ let ldn_application =
68
+ match LDNApplication :: load ( query. id . clone ( ) , query. owner . clone ( ) , query. repo . clone ( ) ) . await
69
+ {
70
+ Ok ( app) => app,
71
+ Err ( e) => {
72
+ return HttpResponse :: BadRequest ( ) . body ( e. to_string ( ) ) ;
73
+ }
74
+ } ;
67
75
let updated_signer = VerifierInput {
68
76
github_username : query. github_username . clone ( ) , // Use the provided `github_username` parameter
69
77
signing_address : signer. signing_address ,
70
78
created_at : signer. created_at ,
71
79
message_cid : signer. message_cid ,
72
80
} ;
73
81
match ldn_application
74
- . complete_new_application_proposal ( updated_signer, request_id, query. owner . clone ( ) , query. repo . clone ( ) )
82
+ . complete_new_application_proposal (
83
+ updated_signer,
84
+ request_id,
85
+ query. owner . clone ( ) ,
86
+ query. repo . clone ( ) ,
87
+ )
75
88
. await
76
89
{
77
90
Ok ( app) => HttpResponse :: Ok ( ) . body ( serde_json:: to_string_pretty ( & app) . unwrap ( ) ) ,
@@ -86,24 +99,28 @@ pub async fn approve(
86
99
query : web:: Query < VerifierActionsQueryParams > ,
87
100
info : web:: Json < CompleteNewApplicationProposalInfo > ,
88
101
) -> impl Responder {
89
- let CompleteNewApplicationProposalInfo {
90
- signer,
91
- request_id,
92
- } = info. into_inner ( ) ;
93
- let ldn_application = match LDNApplication :: load ( query. id . clone ( ) , query. owner . clone ( ) , query. repo . clone ( ) ) . await {
94
- Ok ( app) => app,
95
- Err ( e) => {
96
- return HttpResponse :: BadRequest ( ) . body ( e. to_string ( ) ) ;
97
- }
98
- } ;
102
+ let CompleteNewApplicationProposalInfo { signer, request_id } = info. into_inner ( ) ;
103
+ let ldn_application =
104
+ match LDNApplication :: load ( query. id . clone ( ) , query. owner . clone ( ) , query. repo . clone ( ) ) . await
105
+ {
106
+ Ok ( app) => app,
107
+ Err ( e) => {
108
+ return HttpResponse :: BadRequest ( ) . body ( e. to_string ( ) ) ;
109
+ }
110
+ } ;
99
111
let updated_signer = VerifierInput {
100
112
github_username : query. github_username . clone ( ) , // Use the provided `github_username` parameter
101
113
signing_address : signer. signing_address ,
102
114
created_at : signer. created_at ,
103
115
message_cid : signer. message_cid ,
104
116
} ;
105
117
match ldn_application
106
- . complete_new_application_approval ( updated_signer, request_id, query. owner . clone ( ) , query. repo . clone ( ) )
118
+ . complete_new_application_approval (
119
+ updated_signer,
120
+ request_id,
121
+ query. owner . clone ( ) ,
122
+ query. repo . clone ( ) ,
123
+ )
107
124
. await
108
125
{
109
126
Ok ( app) => HttpResponse :: Ok ( ) . body ( serde_json:: to_string_pretty ( & app) . unwrap ( ) ) ,
@@ -114,17 +131,19 @@ pub async fn approve(
114
131
#[ get( "/applications" ) ]
115
132
pub async fn all_applications ( ) -> impl Responder {
116
133
match LDNApplication :: all_applications ( ) . await {
117
- Ok ( apps) => {
118
- match serde_json:: to_string_pretty ( & apps) {
119
- Ok ( json) => HttpResponse :: Ok ( ) . content_type ( "application/json" ) . body ( json) ,
120
- Err ( e) => HttpResponse :: InternalServerError ( ) . body ( format ! ( "Failed to serialize applications: {}" , e) ) ,
121
- }
134
+ Ok ( apps) => match serde_json:: to_string_pretty ( & apps) {
135
+ Ok ( json) => HttpResponse :: Ok ( )
136
+ . content_type ( "application/json" )
137
+ . body ( json) ,
138
+ Err ( e) => HttpResponse :: InternalServerError ( )
139
+ . body ( format ! ( "Failed to serialize applications: {}" , e) ) ,
122
140
} ,
123
- Err ( errors) => {
124
- match serde_json:: to_string_pretty ( & errors) {
125
- Ok ( json) => HttpResponse :: BadRequest ( ) . content_type ( "application/json" ) . body ( json) ,
126
- Err ( e) => HttpResponse :: InternalServerError ( ) . body ( format ! ( "Failed to serialize errors: {}" , e) ) ,
127
- }
141
+ Err ( errors) => match serde_json:: to_string_pretty ( & errors) {
142
+ Ok ( json) => HttpResponse :: BadRequest ( )
143
+ . content_type ( "application/json" )
144
+ . body ( json) ,
145
+ Err ( e) => HttpResponse :: InternalServerError ( )
146
+ . body ( format ! ( "Failed to serialize errors: {}" , e) ) ,
128
147
} ,
129
148
}
130
149
}
@@ -160,7 +179,7 @@ pub async fn refill(data: web::Json<RefillInfo>) -> actix_web::Result<impl Respo
160
179
161
180
#[ post( "/application/totaldcreached" ) ]
162
181
pub async fn total_dc_reached ( data : web:: Json < DcReachedInfo > ) -> actix_web:: Result < impl Responder > {
163
- let DcReachedInfo { id, owner, repo} = data. into_inner ( ) ;
182
+ let DcReachedInfo { id, owner, repo } = data. into_inner ( ) ;
164
183
match LDNApplication :: total_dc_reached ( id, owner, repo) . await {
165
184
Ok ( applications) => Ok ( HttpResponse :: Ok ( ) . json ( applications) ) ,
166
185
Err ( e) => Ok ( HttpResponse :: BadRequest ( ) . body ( e. to_string ( ) ) ) ,
@@ -171,7 +190,12 @@ pub async fn total_dc_reached(data: web::Json<DcReachedInfo>) -> actix_web::Resu
171
190
pub async fn validate_application_flow (
172
191
info : web:: Json < ValidationPullRequestData > ,
173
192
) -> impl Responder {
174
- let ValidationPullRequestData { pr_number, user_handle, owner, repo } = info. into_inner ( ) ;
193
+ let ValidationPullRequestData {
194
+ pr_number,
195
+ user_handle,
196
+ owner,
197
+ repo,
198
+ } = info. into_inner ( ) ;
175
199
let pr_number = pr_number. trim_matches ( '"' ) . parse :: < u64 > ( ) ;
176
200
match pr_number {
177
201
Ok ( pr_number) => {
@@ -188,7 +212,12 @@ pub async fn validate_application_flow(
188
212
pub async fn validate_application_trigger (
189
213
info : web:: Json < ValidationPullRequestData > ,
190
214
) -> impl Responder {
191
- let ValidationPullRequestData { pr_number, user_handle, owner, repo } = info. into_inner ( ) ;
215
+ let ValidationPullRequestData {
216
+ pr_number,
217
+ user_handle,
218
+ owner,
219
+ repo,
220
+ } = info. into_inner ( ) ;
192
221
let pr_number = pr_number. trim_matches ( '"' ) . parse :: < u64 > ( ) ;
193
222
194
223
match pr_number {
@@ -206,7 +235,12 @@ pub async fn validate_application_trigger(
206
235
pub async fn validate_application_proposal (
207
236
info : web:: Json < ValidationPullRequestData > ,
208
237
) -> impl Responder {
209
- let ValidationPullRequestData { pr_number, user_handle : _, owner, repo } = info. into_inner ( ) ;
238
+ let ValidationPullRequestData {
239
+ pr_number,
240
+ user_handle : _,
241
+ owner,
242
+ repo,
243
+ } = info. into_inner ( ) ;
210
244
let pr_number = pr_number. trim_matches ( '"' ) . parse :: < u64 > ( ) ;
211
245
212
246
match pr_number {
@@ -222,7 +256,12 @@ pub async fn validate_application_proposal(
222
256
pub async fn validate_application_approval (
223
257
info : web:: Json < ValidationPullRequestData > ,
224
258
) -> impl Responder {
225
- let ValidationPullRequestData { pr_number, user_handle : _, owner, repo } = info. into_inner ( ) ;
259
+ let ValidationPullRequestData {
260
+ pr_number,
261
+ user_handle : _,
262
+ owner,
263
+ repo,
264
+ } = info. into_inner ( ) ;
226
265
let pr_number = pr_number. trim_matches ( '"' ) . parse :: < u64 > ( ) ;
227
266
228
267
match pr_number {
@@ -238,29 +277,36 @@ pub async fn validate_application_approval(
238
277
pub async fn validate_application_merge (
239
278
info : web:: Json < ValidationPullRequestData > ,
240
279
) -> impl Responder {
241
- let ValidationPullRequestData { pr_number, user_handle : _, owner, repo } = info. into_inner ( ) ;
280
+ let ValidationPullRequestData {
281
+ pr_number,
282
+ user_handle : _,
283
+ owner,
284
+ repo,
285
+ } = info. into_inner ( ) ;
242
286
let pr_number = pr_number. trim_matches ( '"' ) . parse :: < u64 > ( ) ;
243
287
244
288
match pr_number {
245
- Ok ( pr_number) => match LDNApplication :: validate_merge_application ( pr_number, owner, repo) . await {
246
- Ok ( result) => HttpResponse :: Ok ( ) . json ( result) ,
247
- Err ( e) => HttpResponse :: InternalServerError ( ) . json ( e. to_string ( ) ) ,
248
- } ,
289
+ Ok ( pr_number) => {
290
+ match LDNApplication :: validate_merge_application ( pr_number, owner, repo) . await {
291
+ Ok ( result) => HttpResponse :: Ok ( ) . json ( result) ,
292
+ Err ( e) => HttpResponse :: InternalServerError ( ) . json ( e. to_string ( ) ) ,
293
+ }
294
+ }
249
295
Err ( _) => HttpResponse :: BadRequest ( ) . json ( "Invalid PR Number" ) ,
250
296
}
251
297
}
252
298
253
299
#[ post( "application/cache/renewal" ) ]
254
- pub async fn cache_renewal (
255
- info : web:: Json < GithubQueryParams > ,
256
- ) -> impl Responder {
300
+ pub async fn cache_renewal ( info : web:: Json < GithubQueryParams > ) -> impl Responder {
257
301
let GithubQueryParams { owner, repo } = info. into_inner ( ) ;
258
302
let active_result = LDNApplication :: cache_renewal_active ( owner. clone ( ) , repo. clone ( ) ) . await ;
259
303
260
304
let merged_result = LDNApplication :: cache_renewal_merged ( owner, repo) . await ;
261
305
262
306
match ( active_result, merged_result) {
263
- ( Ok ( _) , Ok ( _) ) => HttpResponse :: Ok ( ) . json ( "Cache renewal for active and merged applications succeeded" ) ,
307
+ ( Ok ( _) , Ok ( _) ) => {
308
+ HttpResponse :: Ok ( ) . json ( "Cache renewal for active and merged applications succeeded" )
309
+ }
264
310
( Err ( e) , _) | ( _, Err ( e) ) => HttpResponse :: InternalServerError ( ) . json ( e. to_string ( ) ) ,
265
311
}
266
312
}
0 commit comments