@@ -156,17 +156,12 @@ impl QueryProject {
156156 // The choice was either to relax the schema constraint to allow duplicate project names
157157 // or to append a number to the project name to ensure uniqueness.
158158 let name = Self :: unique_name ( context, & query_organization, project_name) . await ?;
159- let json_project = JsonNewProject {
160- name,
161- slug : Some ( project_slug) ,
162- url : None ,
163- visibility : None ,
164- } ;
165-
159+ let insert_project =
160+ InsertProject :: new ( query_organization. id , name, project_slug, None , None ) ;
166161 if let Some ( auth_user) = auth_user {
167- Self :: create ( log, context, auth_user, & query_organization, json_project ) . await
162+ Self :: create ( log, context, auth_user, & query_organization, insert_project ) . await
168163 } else {
169- Self :: create_inner ( log, context, & query_organization, json_project ) . await
164+ Self :: create_inner ( log, context, & query_organization, insert_project ) . await
170165 }
171166 }
172167
@@ -252,7 +247,7 @@ impl QueryProject {
252247 context : & ApiContext ,
253248 auth_user : & AuthUser ,
254249 query_organization : & QueryOrganization ,
255- json_project : JsonNewProject ,
250+ insert_project : InsertProject ,
256251 ) -> Result < Self , HttpError > {
257252 // Check to see if user has permission to create a project within the organization
258253 context
@@ -265,7 +260,7 @@ impl QueryProject {
265260 . map_err ( forbidden_error) ?;
266261
267262 let query_project =
268- Self :: create_inner ( log, context, query_organization, json_project ) . await ?;
263+ Self :: create_inner ( log, context, query_organization, insert_project ) . await ?;
269264
270265 let timestamp = DateTime :: now ( ) ;
271266 // Connect the user to the project as a `Maintainer`
@@ -289,10 +284,8 @@ impl QueryProject {
289284 log : & Logger ,
290285 context : & ApiContext ,
291286 query_organization : & QueryOrganization ,
292- json_project : JsonNewProject ,
287+ insert_project : InsertProject ,
293288 ) -> Result < Self , HttpError > {
294- let insert_project =
295- InsertProject :: from_json ( conn_lock ! ( context) , query_organization, json_project) ?;
296289 diesel:: insert_into ( project_table:: table)
297290 . values ( & insert_project)
298291 . execute ( conn_lock ! ( context) )
@@ -466,6 +459,26 @@ pub struct InsertProject {
466459}
467460
468461impl InsertProject {
462+ pub fn new (
463+ organization_id : OrganizationId ,
464+ name : ResourceName ,
465+ slug : Slug ,
466+ url : Option < Url > ,
467+ visibility : Option < Visibility > ,
468+ ) -> Self {
469+ let timestamp = DateTime :: now ( ) ;
470+ Self {
471+ uuid : ProjectUuid :: new ( ) ,
472+ organization_id,
473+ name,
474+ slug,
475+ url,
476+ visibility : visibility. unwrap_or_default ( ) ,
477+ created : timestamp,
478+ modified : timestamp,
479+ }
480+ }
481+
469482 pub fn from_json (
470483 conn : & mut DbConnection ,
471484 organization : & QueryOrganization ,
@@ -478,17 +491,7 @@ impl InsertProject {
478491 visibility,
479492 } = project;
480493 let slug = ok_slug ! ( conn, & name, slug, project, QueryProject ) ?;
481- let timestamp = DateTime :: now ( ) ;
482- Ok ( Self {
483- uuid : ProjectUuid :: new ( ) ,
484- organization_id : organization. id ,
485- name,
486- slug,
487- url,
488- visibility : visibility. unwrap_or_default ( ) ,
489- created : timestamp,
490- modified : timestamp,
491- } )
494+ Ok ( Self :: new ( organization. id , name, slug, url, visibility) )
492495 }
493496}
494497
0 commit comments