| 19 | } |
| 20 | |
| 21 | pub async fn update_note_by_id( |
| 22 | db: &DbConn, |
| 23 | id: i32, |
| 24 | form_data: note::Model, |
| 25 | ) -> Result<note::Model, DbErr> { |
| 26 | let note: note::ActiveModel = Note::find_by_id(id) |
| 27 | .one(db) |
| 28 | .await? |
| 29 | .ok_or(DbErr::Custom("Cannot find note.".to_owned())) |
| 30 | .map(Into::into)?; |
| 31 | |
| 32 | note::ActiveModel { |
| 33 | id: note.id, |
| 34 | title: Set(form_data.title.to_owned()), |
| 35 | text: Set(form_data.text.to_owned()), |
| 36 | } |
| 37 | .update(db) |
| 38 | .await |
| 39 | } |
| 40 | |
| 41 | pub async fn delete_note(db: &DbConn, id: i32) -> Result<DeleteResult, DbErr> { |
| 42 | let note: note::ActiveModel = Note::find_by_id(id) |