---
title: "Comment by Ruge Wit on \"Rust Development: Creating a REST API with Actix Web for Beginners\" | Hashnode"
description: "Inside Database::update_todo_by_id we create a new todo, but don&#39;t fill the field &quot;created_at&quot;, so that field will be null"
url: "https://hashnode.com/posts/rust-development-creating-a-rest-api-with-actix-web-for-beginners/640c7acc0fc3ad7a73a9d4d5/comment/6562704429658b9b067c2934"
---

[Discussion](https://hashnode.com/posts/rust-development-creating-a-rest-api-with-actix-web-for-beginners/640c7acc0fc3ad7a73a9d4d5)

Comment [Rust Development: Creating a REST API with Actix Web for Beginners](https://hashnode.com/posts/rust-development-creating-a-rest-api-with-actix-web-for-beginners/640c7acc0fc3ad7a73a9d4d5)

[Ruge Wit](https://hashnode.com/@rugivit)

[Nov 25, 2023](https://hashnode.com/posts/rust-development-creating-a-rest-api-with-actix-web-for-beginners/640c7acc0fc3ad7a73a9d4d5/comment/6562704429658b9b067c2934)

Inside Database::update\_todo\_by\_id we create a new todo, but don't fill the field "created\_at", so that field will be null

[Raphael Carubbi](https://hashnode.com/@rcarubbi)

[Dec 6, 2023](https://hashnode.com/posts/rust-development-creating-a-rest-api-with-actix-web-for-beginners/640c7acc0fc3ad7a73a9d4d5/comment/6562704429658b9b067c2934#reply-656ff322d65dd4cd71f39c48)

you get by id first and then pass the current value to the new Todo instance:

```
pub fn update_todo_by_id(&self, id: &str, todo: Todo) -> Option<Todo> {
    let mut todos = self.todos.lock().unwrap();
    let updated_at = Utc::now();
    let index = todos.iter().position(|todo| todo.id == Some(id.to_string()))?;
    let todo = Todo {
        id: Some(id.to_string()),
        updated_at: Some(updated_at),
        created_at: todos[index].created_at,
        ..todo
    };
    todos[index] = todo.clone();
    Some(todo)
}
```
