@@ -24,21 +24,9 @@ pub struct NewCrateOwnerInvitation {
2424 pub crate_id : i32 ,
2525}
2626
27- /// The model representing a row in the `crate_owner_invitations` database table.
28- #[ derive( Clone , Debug , Identifiable , Queryable ) ]
29- #[ diesel( primary_key( invited_user_id, crate_id) ) ]
30- pub struct CrateOwnerInvitation {
31- pub invited_user_id : i32 ,
32- pub invited_by_user_id : i32 ,
33- pub crate_id : i32 ,
34- pub created_at : NaiveDateTime ,
35- #[ diesel( deserialize_as = String ) ]
36- pub token : SecretString ,
37- }
38-
39- impl CrateOwnerInvitation {
27+ impl NewCrateOwnerInvitation {
4028 pub async fn create (
41- invite : & NewCrateOwnerInvitation ,
29+ & self ,
4230 conn : & mut AsyncPgConnection ,
4331 config : & config:: Server ,
4432 ) -> QueryResult < NewCrateOwnerInvitationOutcome > {
@@ -50,7 +38,7 @@ impl CrateOwnerInvitation {
5038 // This does a SELECT FOR UPDATE + DELETE instead of a DELETE with a WHERE clause to
5139 // use the model's `is_expired` method, centralizing our expiration checking logic.
5240 let existing: Option < CrateOwnerInvitation > = crate_owner_invitations:: table
53- . find ( ( invite . invited_user_id , invite . crate_id ) )
41+ . find ( ( self . invited_user_id , self . crate_id ) )
5442 . for_update ( )
5543 . first ( conn)
5644 . await
@@ -68,7 +56,7 @@ impl CrateOwnerInvitation {
6856 . await ?;
6957
7058 let res: Option < CrateOwnerInvitation > = diesel:: insert_into ( crate_owner_invitations:: table)
71- . values ( invite )
59+ . values ( self )
7260 // The ON CONFLICT DO NOTHING clause results in not creating the invite if another one
7361 // already exists. This does not cause problems with expired invitation as those are
7462 // deleted before doing this INSERT.
@@ -84,7 +72,21 @@ impl CrateOwnerInvitation {
8472 None => NewCrateOwnerInvitationOutcome :: AlreadyExists ,
8573 } )
8674 }
75+ }
8776
77+ /// The model representing a row in the `crate_owner_invitations` database table.
78+ #[ derive( Clone , Debug , Identifiable , Queryable ) ]
79+ #[ diesel( primary_key( invited_user_id, crate_id) ) ]
80+ pub struct CrateOwnerInvitation {
81+ pub invited_user_id : i32 ,
82+ pub invited_by_user_id : i32 ,
83+ pub crate_id : i32 ,
84+ pub created_at : NaiveDateTime ,
85+ #[ diesel( deserialize_as = String ) ]
86+ pub token : SecretString ,
87+ }
88+
89+ impl CrateOwnerInvitation {
8890 pub async fn find_by_id (
8991 user_id : i32 ,
9092 crate_id : i32 ,
0 commit comments