@@ -69,6 +69,10 @@ def create_notebook(
6969 shutil .copytree (dataset_folder , new_folder_path , dirs_exist_ok = True )
7070
7171 notebook_data = params .model_dump ()
72+ notebook_data = {
73+ ** notebook_data ,
74+ "name" : notebook_data .get ("name" ) or "Untitled Notebook" ,
75+ }
7276 notebook_data ["file_path" ] = new_folder_path
7377 notebook_model = Notebook (** notebook_data )
7478 db .add (notebook_model )
@@ -338,3 +342,56 @@ async def create_dataset_from_notebook(
338342 ) from e
339343
340344 return dataset
345+
346+
347+ @router .patch ("/{notebook_id}" )
348+ @inject
349+ async def update_notebook (
350+ notebook_id : int ,
351+ params : schemas .NotebookUpdateParams ,
352+ session_factory : sessionmaker = Depends (lambda : di ["session_factory" ]),
353+ ):
354+ """Updates the name of a notebook with the provided ID.
355+
356+ Parameters
357+ ----------
358+ notebook_id : int
359+ ID of the notebook to update.
360+ params : NotebookUpdateParams
361+ A dictionary containing the new values for the notebook.
362+ name : str
363+ New name for the notebook.
364+ session_factory : Callable[..., ContextManager[Session]]
365+ A factory that creates a context manager that handles a SQLAlchemy session.
366+ The generated session can be used to access and query the database.
367+
368+ Returns
369+ -------
370+ Dict
371+ A dictionary containing the updated dataset record.
372+ """
373+ with session_factory () as db :
374+ try :
375+ notebook = db .get (Notebook , notebook_id )
376+ if not notebook :
377+ raise HTTPException (
378+ status_code = status .HTTP_404_NOT_FOUND ,
379+ detail = "Notebook not found" ,
380+ )
381+ if not params .name or params .name == notebook .name :
382+ raise HTTPException (
383+ status_code = status .HTTP_304_NOT_MODIFIED ,
384+ detail = "No fields to update" ,
385+ )
386+
387+ setattr (notebook , "name" , params .name )
388+ db .commit ()
389+ db .refresh (notebook )
390+ except Exception as e :
391+ log .error (f"Error updating notebook { notebook_id } : { e } " )
392+ raise HTTPException (
393+ status_code = status .HTTP_500_INTERNAL_SERVER_ERROR ,
394+ detail = "Failed to update notebook" ,
395+ ) from e
396+
397+ return notebook
0 commit comments