1
1
use cargo_registry:: {
2
- models:: { Crate , Keyword , NewCrate } ,
2
+ models:: { Category , Crate , Keyword , NewCrate } ,
3
3
schema:: { crates, version_downloads} ,
4
4
util:: errors:: AppResult ,
5
5
} ;
@@ -13,6 +13,7 @@ use super::VersionBuilder;
13
13
/// If you want to test logic that happens as part of a publish request, use `PublishBuilder`
14
14
/// instead.
15
15
pub struct CrateBuilder < ' a > {
16
+ categories : Vec < & ' a str > ,
16
17
downloads : Option < i32 > ,
17
18
keywords : Vec < & ' a str > ,
18
19
krate : NewCrate < ' a > ,
@@ -27,6 +28,7 @@ impl<'a> CrateBuilder<'a> {
27
28
/// doesn't exist in the database, `expect_build` will fail.
28
29
pub fn new ( name : & str , owner_id : i32 ) -> CrateBuilder < ' _ > {
29
30
CrateBuilder {
31
+ categories : Vec :: new ( ) ,
30
32
downloads : None ,
31
33
keywords : Vec :: new ( ) ,
32
34
krate : NewCrate {
@@ -91,6 +93,12 @@ impl<'a> CrateBuilder<'a> {
91
93
self
92
94
}
93
95
96
+ /// Adds a category to the crate.
97
+ pub fn category ( mut self , category : & ' a str ) -> Self {
98
+ self . categories . push ( category) ;
99
+ self
100
+ }
101
+
94
102
/// Adds a keyword to the crate.
95
103
pub fn keyword ( mut self , keyword : & ' a str ) -> Self {
96
104
self . keywords . push ( keyword) ;
@@ -143,6 +151,10 @@ impl<'a> CrateBuilder<'a> {
143
151
select ( refresh_recent_crate_downloads) . execute ( connection) ?;
144
152
}
145
153
154
+ if !self . categories . is_empty ( ) {
155
+ Category :: update_crate ( connection, & krate, & self . categories ) ?;
156
+ }
157
+
146
158
if !self . keywords . is_empty ( ) {
147
159
Keyword :: update_crate ( connection, & krate, & self . keywords ) ?;
148
160
}
0 commit comments