@@ -102,11 +102,12 @@ pub async fn edit_snippet(
102102 ctx : Context < ' _ > ,
103103 #[ autocomplete = "autocomplete_snippet" ]
104104 #[ description = "The snippet's id" ]
105- id : String ,
105+ #[ rename = "id" ]
106+ id_and_title : String ,
106107 #[ description = "The snippet's title" ] title : Option < String > ,
107108 #[ description = "The snippet's content" ] content : Option < String > ,
108109) -> Result < ( ) , Error > {
109- match get_snippet_lazy ( & ctx, & id ) {
110+ match get_snippet ( & ctx, & id_and_title ) {
110111 Some ( mut snippet) => {
111112 if let Some ( title) = title {
112113 snippet. title = title;
@@ -118,7 +119,8 @@ pub async fn edit_snippet(
118119
119120 {
120121 let mut rwlock_guard = ctx. data ( ) . state . write ( ) . unwrap ( ) ;
121- rwlock_guard. snippets . push ( snippet. clone ( ) ) ;
122+ let editing_snippet = rwlock_guard. snippets . iter_mut ( ) . find ( |s| s. format_output ( ) . eq ( & id_and_title) ) . unwrap ( ) ;
123+ * editing_snippet = snippet. clone ( ) ;
122124 println ! ( "Snippet edited '{}: {}'" , snippet. title, snippet. content) ;
123125 rwlock_guard. write ( ) ;
124126 }
@@ -128,7 +130,7 @@ pub async fn edit_snippet(
128130 }
129131 None => {
130132 let title = & "Failed to edit snippet" ;
131- let content = & & format ! ( "The snippet '{id }' does not exist" ) ;
133+ let content = & & format ! ( "The snippet '{id_and_title }' does not exist" ) ;
132134 respond_err ( & ctx, title, content) . await ;
133135 }
134136 } ;
@@ -234,7 +236,7 @@ impl Embeddable for Snippet {
234236}
235237
236238// Exact matches the snippet id and name.
237- fn _get_snippet ( ctx : & Context < ' _ > , id : & str ) -> Option < Snippet > {
239+ fn get_snippet ( ctx : & Context < ' _ > , id : & str ) -> Option < Snippet > {
238240 let data = ctx. data ( ) ;
239241 let rwlock_guard = data. state . read ( ) . unwrap ( ) ;
240242
0 commit comments