@@ -20,6 +20,8 @@ pub use self::middleware::{Middleware, RequestUser};
20
20
21
21
pub mod middleware;
22
22
23
+ /// The model representing a row in the `users` database table.
24
+ ///
23
25
#[ derive( Clone , Debug , PartialEq , Eq ) ]
24
26
pub struct User {
25
27
pub id : i32 ,
@@ -31,6 +33,8 @@ pub struct User {
31
33
pub api_token : String ,
32
34
}
33
35
36
+ /// The serialization format for the `User` model.
37
+ ///
34
38
#[ derive( RustcDecodable , RustcEncodable ) ]
35
39
pub struct EncodableUser {
36
40
pub id : i32 ,
@@ -41,6 +45,8 @@ pub struct EncodableUser {
41
45
}
42
46
43
47
impl User {
48
+ /// Queries the database for a user with a certain `gh_login` value.
49
+ ///
44
50
pub fn find_by_login ( conn : & GenericConnection ,
45
51
login : & str ) -> CargoResult < User > {
46
52
let stmt = try!( conn. prepare ( "SELECT * FROM users
@@ -52,6 +58,8 @@ impl User {
52
58
Ok ( Model :: from_row ( & row) )
53
59
}
54
60
61
+ /// Queries the database for a user with a certain `api_token` value.
62
+ ///
55
63
pub fn find_by_api_token ( conn : & GenericConnection ,
56
64
token : & str ) -> CargoResult < User > {
57
65
let stmt = try!( conn. prepare ( "SELECT * FROM users \
@@ -62,6 +70,8 @@ impl User {
62
70
} )
63
71
}
64
72
73
+ /// Updates a user or inserts a new user into the database.
74
+ ///
65
75
pub fn find_or_insert ( conn : & GenericConnection ,
66
76
login : & str ,
67
77
email : Option < & str > ,
@@ -102,10 +112,14 @@ impl User {
102
112
} ) ) ) )
103
113
}
104
114
115
+ /// Generates a new crates.io API token.
116
+ ///
105
117
pub fn new_api_token ( ) -> String {
106
118
thread_rng ( ) . gen_ascii_chars ( ) . take ( 32 ) . collect ( )
107
119
}
108
120
121
+ /// Converts this `User` model into an `EncodableUser` for JSON serialization.
122
+ ///
109
123
pub fn encodable ( self ) -> EncodableUser {
110
124
let User { id, email, api_token : _, gh_access_token : _,
111
125
name, gh_login, avatar } = self ;
0 commit comments