@@ -34,7 +34,7 @@ pub struct Version {
34
34
}
35
35
36
36
pub enum Author {
37
- User ( User ) ,
37
+ User ( User ) , //TODO: not used. this should be removed.
38
38
Name ( String ) ,
39
39
}
40
40
@@ -167,25 +167,22 @@ impl Version {
167
167
168
168
pub fn authors ( & self , conn : & GenericConnection ) -> CargoResult < Vec < Author > > {
169
169
let stmt = conn. prepare ( "SELECT * FROM version_authors
170
- WHERE version_id = $1" ) ?;
170
+ WHERE version_id = $1
171
+ ORDER BY name ASC" ) ?;
171
172
let rows = stmt. query ( & [ & self . id ] ) ?;
172
- let mut authors = rows. into_iter ( ) . map ( |row| {
173
+ rows. into_iter ( ) . map ( |row| {
173
174
let user_id: Option < i32 > = row. get ( "user_id" ) ;
174
175
let name: String = row. get ( "name" ) ;
175
176
Ok ( match user_id {
176
177
Some ( id) => Author :: User ( User :: find ( conn, id) ?) ,
177
178
None => Author :: Name ( name) ,
178
179
} )
179
- } ) . collect :: < CargoResult < Vec < Author > > > ( ) ?;
180
- authors. sort_by ( |ref a, ref b| a. name ( ) . cmp ( & b. name ( ) ) ) ;
181
- Ok ( authors)
180
+ } ) . collect ( )
182
181
}
183
182
184
183
pub fn add_author ( & self ,
185
184
conn : & GenericConnection ,
186
185
name : & str ) -> CargoResult < ( ) > {
187
- println ! ( "add author: {}" , name) ;
188
- // TODO: at least try to link `name` to a pre-existing user
189
186
conn. execute ( "INSERT INTO version_authors (version_id, name)
190
187
VALUES ($1, $2)" , & [ & self . id , & name] ) ?;
191
188
Ok ( ( ) )
@@ -219,15 +216,6 @@ impl Model for Version {
219
216
fn table_name ( _: Option < Version > ) -> & ' static str { "versions" }
220
217
}
221
218
222
- impl Author {
223
- fn name ( & self ) -> Option < & str > {
224
- match self {
225
- & Author :: Name ( ref n) => { Some ( & n) } ,
226
- & Author :: User ( ref u) => { u. name . as_ref ( ) . map ( String :: as_str) }
227
- }
228
- }
229
- }
230
-
231
219
/// Handles the `GET /versions` route.
232
220
pub fn index ( req : & mut Request ) -> CargoResult < Response > {
233
221
let conn = req. tx ( ) ?;
0 commit comments