1
- use super :: { custom , custom_or_404 , goh , redirect } ;
1
+ use super :: { goh , redirect , OptionalExtension , ServerError } ;
2
2
use super :: { FullArticle , FullEpisode , OtherContribs , PgFilter , PgPool } ;
3
3
use crate :: models:: creator_contributions:: CreatorContributions ;
4
4
use crate :: models:: {
@@ -20,20 +20,20 @@ use crate::schema::titles::dsl as t;
20
20
use crate :: templates:: { self , RenderRucte } ;
21
21
use diesel:: dsl:: { any, min} ;
22
22
use diesel:: prelude:: * ;
23
- use tokio_diesel:: { AsyncError , AsyncRunQueryDsl , OptionalExtension } ;
23
+ use tokio_diesel:: { AsyncError , AsyncRunQueryDsl } ;
24
24
use warp:: filters:: BoxedFilter ;
25
25
use warp:: http:: response:: Builder ;
26
26
use warp:: reply:: Response ;
27
- use warp:: { self , Filter , Rejection , Reply } ;
27
+ use warp:: { self , Filter , Reply } ;
28
28
29
29
pub fn routes ( s : PgFilter ) -> BoxedFilter < ( impl Reply , ) > {
30
30
use warp:: path:: { end, param} ;
31
- let list = goh ( ) . and ( end ( ) ) . and ( s. clone ( ) ) . and_then ( list_creators) ;
32
- let one = goh ( ) . and ( s) . and ( param ( ) ) . and ( end ( ) ) . and_then ( one_creator) ;
31
+ let list = goh ( ) . and ( end ( ) ) . and ( s. clone ( ) ) . map_async ( list_creators) ;
32
+ let one = goh ( ) . and ( s) . and ( param ( ) ) . and ( end ( ) ) . map_async ( one_creator) ;
33
33
list. or ( one) . unify ( ) . boxed ( )
34
34
}
35
35
36
- async fn list_creators ( db : PgPool ) -> Result < Response , Rejection > {
36
+ async fn list_creators ( db : PgPool ) -> Result < Response , ServerError > {
37
37
use crate :: models:: creator_contributions:: creator_contributions:: dsl as cc;
38
38
let all = cc:: creator_contributions
39
39
. select ( (
@@ -45,21 +45,20 @@ async fn list_creators(db: PgPool) -> Result<Response, Rejection> {
45
45
cc:: latest_issue,
46
46
) )
47
47
. load_async :: < CreatorContributions > ( & db)
48
- . await
49
- . map_err ( custom) ?;
50
- Builder :: new ( ) . html ( |o| templates:: creators ( o, & all) )
48
+ . await ?;
49
+ Ok ( Builder :: new ( ) . html ( |o| templates:: creators ( o, & all) ) ?)
51
50
}
52
51
53
52
async fn one_creator (
54
53
db : PgPool ,
55
54
slug : String ,
56
- ) -> Result < Response , Rejection > {
55
+ ) -> Result < Response , ServerError > {
57
56
let creator = c:: creators
58
57
. filter ( c:: slug. eq ( slug. clone ( ) ) )
59
58
. first_async :: < Creator > ( & db)
60
59
. await
61
- . optional ( )
62
- . map_err ( custom ) ? ;
60
+ . optional ( ) ? ;
61
+
63
62
let creator = if let Some ( creator) = creator {
64
63
creator
65
64
} else {
@@ -69,7 +68,7 @@ async fn one_creator(
69
68
. replace ( ".html" , "" ) ;
70
69
log:: info!( "Looking for creator fallback {:?} -> {:?}" , slug, target) ;
71
70
if target == "anderas%eriksson" || target == "andreas%erikssson" {
72
- return redirect ( "/who/andreas-eriksson" ) ;
71
+ return Ok ( redirect ( "/who/andreas-eriksson" ) ) ;
73
72
}
74
73
let found = ca:: creator_aliases
75
74
. inner_join ( c:: creators)
@@ -78,9 +77,9 @@ async fn one_creator(
78
77
. select ( c:: slug)
79
78
. first_async :: < String > ( & db)
80
79
. await
81
- . map_err ( custom_or_404 ) ?;
80
+ . or_404 ( ) ?;
82
81
log:: debug!( "Found replacement: {:?}" , found) ;
83
- return redirect ( & format ! ( "/who/{}" , found) ) ;
82
+ return Ok ( redirect ( & format ! ( "/who/{}" , found) ) ) ;
84
83
} ;
85
84
86
85
let about_raw = a:: articles
@@ -92,23 +91,16 @@ async fn one_creator(
92
91
. order ( min ( i:: magic) )
93
92
. group_by ( a:: articles:: all_columns ( ) )
94
93
. load_async :: < Article > ( & db)
95
- . await
96
- . map_err ( custom) ?;
94
+ . await ?;
97
95
let mut about = Vec :: with_capacity ( about_raw. len ( ) ) ;
98
96
for article in about_raw. into_iter ( ) {
99
97
let published = i:: issues
100
98
. inner_join ( p:: publications)
101
99
. select ( ( i:: year, ( i:: number, i:: number_str) ) )
102
100
. filter ( p:: article_id. eq ( article. id ) )
103
101
. load_async :: < IssueRef > ( & db)
104
- . await
105
- . map_err ( custom) ?;
106
- about. push ( (
107
- FullArticle :: load_async ( article, & db)
108
- . await
109
- . map_err ( custom) ?,
110
- published,
111
- ) ) ;
102
+ . await ?;
103
+ about. push ( ( FullArticle :: load_async ( article, & db) . await ?, published) ) ;
112
104
}
113
105
114
106
let e_t_columns = ( t:: titles:: all_columns ( ) , e:: episodes:: all_columns ( ) ) ;
@@ -125,13 +117,10 @@ async fn one_creator(
125
117
. order ( min ( i:: magic) )
126
118
. group_by ( e_t_columns)
127
119
. load_async :: < ( Title , Episode ) > ( & db)
128
- . await
129
- . map_err ( custom) ?;
120
+ . await ?;
130
121
let mut main_episodes = Vec :: with_capacity ( main_episodes_raw. len ( ) ) ;
131
122
for ( t, ep) in main_episodes_raw. into_iter ( ) {
132
- let e = FullEpisode :: load_details_async ( ep, & db)
133
- . await
134
- . map_err ( custom) ?;
123
+ let e = FullEpisode :: load_details_async ( ep, & db) . await ?;
135
124
main_episodes. push ( ( t, e) ) ;
136
125
}
137
126
@@ -143,31 +132,23 @@ async fn one_creator(
143
132
. order ( min ( i:: magic) )
144
133
. group_by ( a:: articles:: all_columns ( ) )
145
134
. load_async :: < Article > ( & db)
146
- . await
147
- . map_err ( custom) ?;
135
+ . await ?;
148
136
let mut articles_by = Vec :: with_capacity ( articles_by_raw. len ( ) ) ;
149
137
for article in articles_by_raw. into_iter ( ) {
150
138
let published = i:: issues
151
139
. inner_join ( p:: publications)
152
140
. select ( ( i:: year, ( i:: number, i:: number_str) ) )
153
141
. filter ( p:: article_id. eq ( article. id ) )
154
142
. load_async :: < IssueRef > ( & db)
155
- . await
156
- . map_err ( custom) ?;
157
- articles_by. push ( (
158
- FullArticle :: load_async ( article, & db)
159
- . await
160
- . map_err ( custom) ?,
161
- published,
162
- ) )
143
+ . await ?;
144
+ articles_by
145
+ . push ( ( FullArticle :: load_async ( article, & db) . await ?, published) )
163
146
}
164
147
165
- let covers = CoverSet :: by ( & creator, & db) . await . map_err ( custom) ?;
166
- let others = OtherContribs :: for_creator ( & creator, & db)
167
- . await
168
- . map_err ( custom) ?;
148
+ let covers = CoverSet :: by ( & creator, & db) . await ?;
149
+ let others = OtherContribs :: for_creator ( & creator, & db) . await ?;
169
150
170
- Builder :: new ( ) . html ( |o| {
151
+ Ok ( Builder :: new ( ) . html ( |o| {
171
152
templates:: creator (
172
153
o,
173
154
& creator,
@@ -177,7 +158,7 @@ async fn one_creator(
177
158
& articles_by,
178
159
& others,
179
160
)
180
- } )
161
+ } ) ? )
181
162
}
182
163
183
164
pub struct CoverSet {
0 commit comments