feat: ability to create a task #14
@ -1,2 +1,3 @@
|
|||||||
mod database_connection;
|
mod database_connection;
|
||||||
pub(crate) mod projects;
|
pub(crate) mod projects;
|
||||||
|
pub(crate) mod tasks;
|
||||||
|
30
src/server/tasks.rs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
|||||||
|
use crate::errors::error::Error;
|
||||||
![]() Avoid using Using Replace **Avoid using `unwrap()` for database operations.**
Using `unwrap()` can lead to panics if the database operation fails. Consider handling the error with `map_err` or `expect` with a meaningful message.
Replace `unwrap()` with proper error handling to prevent potential panics.
<!-- This is an auto-generated comment by CodeRabbit -->
|
|||||||
|
use crate::errors::error_vec::ErrorVec;
|
||||||
![]() Avoid using Using Replace **Avoid using `unwrap()` for database operations.**
Using `unwrap()` can lead to panics if the database operation fails. Consider handling the error with `map_err` or `expect` with a meaningful message.
Replace `unwrap()` with proper error handling to prevent potential panics.
<!-- This is an auto-generated comment by CodeRabbit -->
|
|||||||
|
use crate::models::task::{NewTask, Task};
|
||||||
![]() Avoid using Using Replace **Avoid using `unwrap()` for database operations.**
Using `unwrap()` can lead to panics if the database operation fails. Consider handling the error with `map_err` or `expect` with a meaningful message.
Replace `unwrap()` with proper error handling to prevent potential panics.
<!-- This is an auto-generated comment by CodeRabbit -->
|
|||||||
|
use crate::server::database_connection::establish_database_connection;
|
||||||
![]() Avoid using Using Replace **Avoid using `unwrap()` for database operations.**
Using `unwrap()` can lead to panics if the database operation fails. Consider handling the error with `map_err` or `expect` with a meaningful message.
Replace `unwrap()` with proper error handling to prevent potential panics.
<!-- This is an auto-generated comment by CodeRabbit -->
|
|||||||
|
use diesel::{RunQueryDsl, SelectableHelper};
|
||||||
![]() Avoid using Using Replace **Avoid using `unwrap()` for database operations.**
Using `unwrap()` can lead to panics if the database operation fails. Consider handling the error with `map_err` or `expect` with a meaningful message.
Replace `unwrap()` with proper error handling to prevent potential panics.
<!-- This is an auto-generated comment by CodeRabbit -->
|
|||||||
|
use dioxus::prelude::*;
|
||||||
![]() Avoid using Using Replace **Avoid using `unwrap()` for database operations.**
Using `unwrap()` can lead to panics if the database operation fails. Consider handling the error with `map_err` or `expect` with a meaningful message.
Replace `unwrap()` with proper error handling to prevent potential panics.
<!-- This is an auto-generated comment by CodeRabbit -->
|
|||||||
|
use validator::Validate;
|
||||||
![]() Avoid using Using Replace **Avoid using `unwrap()` for database operations.**
Using `unwrap()` can lead to panics if the database operation fails. Consider handling the error with `map_err` or `expect` with a meaningful message.
Replace `unwrap()` with proper error handling to prevent potential panics.
<!-- This is an auto-generated comment by CodeRabbit -->
|
|||||||
|
use crate::errors::task_create_error::TaskCreateError;
|
||||||
![]() Avoid using Using Replace **Avoid using `unwrap()` for database operations.**
Using `unwrap()` can lead to panics if the database operation fails. Consider handling the error with `map_err` or `expect` with a meaningful message.
Replace `unwrap()` with proper error handling to prevent potential panics.
<!-- This is an auto-generated comment by CodeRabbit -->
|
|||||||
|
|
||||||
![]() Avoid using Using Replace **Avoid using `unwrap()` for database operations.**
Using `unwrap()` can lead to panics if the database operation fails. Consider handling the error with `map_err` or `expect` with a meaningful message.
Replace `unwrap()` with proper error handling to prevent potential panics.
<!-- This is an auto-generated comment by CodeRabbit -->
|
|||||||
|
#[server]
|
||||||
![]() Avoid using Using Replace **Avoid using `unwrap()` for database operations.**
Using `unwrap()` can lead to panics if the database operation fails. Consider handling the error with `map_err` or `expect` with a meaningful message.
Replace `unwrap()` with proper error handling to prevent potential panics.
<!-- This is an auto-generated comment by CodeRabbit -->
|
|||||||
|
pub(crate) async fn create_task(new_task: NewTask)
|
||||||
![]() Avoid using Using Replace **Avoid using `unwrap()` for database operations.**
Using `unwrap()` can lead to panics if the database operation fails. Consider handling the error with `map_err` or `expect` with a meaningful message.
Replace `unwrap()` with proper error handling to prevent potential panics.
<!-- This is an auto-generated comment by CodeRabbit -->
|
|||||||
|
-> Result<Task, ServerFnError<ErrorVec<TaskCreateError>>> {
|
||||||
![]() Avoid using Using Replace **Avoid using `unwrap()` for database operations.**
Using `unwrap()` can lead to panics if the database operation fails. Consider handling the error with `map_err` or `expect` with a meaningful message.
Replace `unwrap()` with proper error handling to prevent potential panics.
<!-- This is an auto-generated comment by CodeRabbit -->
|
|||||||
|
use crate::schema::tasks;
|
||||||
![]() Avoid using Using Replace **Avoid using `unwrap()` for database operations.**
Using `unwrap()` can lead to panics if the database operation fails. Consider handling the error with `map_err` or `expect` with a meaningful message.
Replace `unwrap()` with proper error handling to prevent potential panics.
<!-- This is an auto-generated comment by CodeRabbit -->
|
|||||||
|
|
||||||
![]() Avoid using Using Replace **Avoid using `unwrap()` for database operations.**
Using `unwrap()` can lead to panics if the database operation fails. Consider handling the error with `map_err` or `expect` with a meaningful message.
Replace `unwrap()` with proper error handling to prevent potential panics.
<!-- This is an auto-generated comment by CodeRabbit -->
|
|||||||
|
new_task.validate()
|
||||||
![]() Avoid using Using Replace **Avoid using `unwrap()` for database operations.**
Using `unwrap()` can lead to panics if the database operation fails. Consider handling the error with `map_err` or `expect` with a meaningful message.
Replace `unwrap()` with proper error handling to prevent potential panics.
<!-- This is an auto-generated comment by CodeRabbit -->
|
|||||||
|
.map_err::<ErrorVec<TaskCreateError>, _>(|errors| errors.into())?;
|
||||||
![]() Avoid using Using Replace **Avoid using `unwrap()` for database operations.**
Using `unwrap()` can lead to panics if the database operation fails. Consider handling the error with `map_err` or `expect` with a meaningful message.
Replace `unwrap()` with proper error handling to prevent potential panics.
<!-- This is an auto-generated comment by CodeRabbit -->
|
|||||||
|
|
||||||
![]() Avoid using Using Replace **Avoid using `unwrap()` for database operations.**
Using `unwrap()` can lead to panics if the database operation fails. Consider handling the error with `map_err` or `expect` with a meaningful message.
Replace `unwrap()` with proper error handling to prevent potential panics.
<!-- This is an auto-generated comment by CodeRabbit -->
|
|||||||
|
let mut connection = establish_database_connection()
|
||||||
![]() Avoid using Using Replace **Avoid using `unwrap()` for database operations.**
Using `unwrap()` can lead to panics if the database operation fails. Consider handling the error with `map_err` or `expect` with a meaningful message.
Replace `unwrap()` with proper error handling to prevent potential panics.
<!-- This is an auto-generated comment by CodeRabbit -->
|
|||||||
|
.map_err::<ErrorVec<TaskCreateError>, _>(
|
||||||
![]() Avoid using Using Replace **Avoid using `unwrap()` for database operations.**
Using `unwrap()` can lead to panics if the database operation fails. Consider handling the error with `map_err` or `expect` with a meaningful message.
Replace `unwrap()` with proper error handling to prevent potential panics.
<!-- This is an auto-generated comment by CodeRabbit -->
|
|||||||
|
|_| vec![TaskCreateError::Error(Error::ServerInternal)].into()
|
||||||
![]() Avoid using Using Replace **Avoid using `unwrap()` for database operations.**
Using `unwrap()` can lead to panics if the database operation fails. Consider handling the error with `map_err` or `expect` with a meaningful message.
Replace `unwrap()` with proper error handling to prevent potential panics.
<!-- This is an auto-generated comment by CodeRabbit -->
|
|||||||
|
)?;
|
||||||
![]() Avoid using Using Replace **Avoid using `unwrap()` for database operations.**
Using `unwrap()` can lead to panics if the database operation fails. Consider handling the error with `map_err` or `expect` with a meaningful message.
Replace `unwrap()` with proper error handling to prevent potential panics.
<!-- This is an auto-generated comment by CodeRabbit -->
![]() Consider adding logging for database connection errors. While the error handling for database connection is appropriate, consider logging the error for better traceability.
**Consider adding logging for database connection errors.**
While the error handling for database connection is appropriate, consider logging the error for better traceability.
```rust
.map_err::<ErrorVec<TaskCreateError>, _>(
|e| {
log::error!("Database connection error: {:?}", e);
vec![TaskCreateError::Error(Error::ServerInternal)].into()
}
)?;
```
<!-- This is an auto-generated comment by CodeRabbit -->
|
|||||||
|
|
||||||
![]() Avoid using Using Replace **Avoid using `unwrap()` for database operations.**
Using `unwrap()` can lead to panics if the database operation fails. Consider handling the error with `map_err` or `expect` with a meaningful message.
Replace `unwrap()` with proper error handling to prevent potential panics.
<!-- This is an auto-generated comment by CodeRabbit -->
|
|||||||
|
let new_task = diesel::insert_into(tasks::table)
|
||||||
![]() Avoid using Using Replace **Avoid using `unwrap()` for database operations.**
Using `unwrap()` can lead to panics if the database operation fails. Consider handling the error with `map_err` or `expect` with a meaningful message.
Replace `unwrap()` with proper error handling to prevent potential panics.
<!-- This is an auto-generated comment by CodeRabbit -->
|
|||||||
|
.values(&new_task)
|
||||||
![]() Avoid using Using Replace **Avoid using `unwrap()` for database operations.**
Using `unwrap()` can lead to panics if the database operation fails. Consider handling the error with `map_err` or `expect` with a meaningful message.
Replace `unwrap()` with proper error handling to prevent potential panics.
<!-- This is an auto-generated comment by CodeRabbit -->
|
|||||||
|
.returning(Task::as_returning())
|
||||||
![]() Avoid using Using Replace **Avoid using `unwrap()` for database operations.**
Using `unwrap()` can lead to panics if the database operation fails. Consider handling the error with `map_err` or `expect` with a meaningful message.
Replace `unwrap()` with proper error handling to prevent potential panics.
<!-- This is an auto-generated comment by CodeRabbit -->
|
|||||||
|
.get_result(&mut connection)
|
||||||
![]() Avoid using Using Replace **Avoid using `unwrap()` for database operations.**
Using `unwrap()` can lead to panics if the database operation fails. Consider handling the error with `map_err` or `expect` with a meaningful message.
Replace `unwrap()` with proper error handling to prevent potential panics.
<!-- This is an auto-generated comment by CodeRabbit -->
|
|||||||
|
.unwrap();
|
||||||
![]() Avoid using Using Replace **Avoid using `unwrap()` for database operations.**
Using `unwrap()` can lead to panics if the database operation fails. Consider handling the error with `map_err` or `expect` with a meaningful message.
Replace `unwrap()` with proper error handling to prevent potential panics.
<!-- This is an auto-generated comment by CodeRabbit -->
|
|||||||
|
|
||||||
![]() Avoid using Using Replace **Avoid using `unwrap()` for database operations.**
Using `unwrap()` can lead to panics if the database operation fails. Consider handling the error with `map_err` or `expect` with a meaningful message.
Replace `unwrap()` with proper error handling to prevent potential panics.
<!-- This is an auto-generated comment by CodeRabbit -->
|
|||||||
|
Ok(new_task)
|
||||||
![]() Avoid using Using Replace **Avoid using `unwrap()` for database operations.**
Using `unwrap()` can lead to panics if the database operation fails. Consider handling the error with `map_err` or `expect` with a meaningful message.
Replace `unwrap()` with proper error handling to prevent potential panics.
<!-- This is an auto-generated comment by CodeRabbit -->
|
|||||||
|
}
|
||||||
![]() Avoid using Using Replace **Avoid using `unwrap()` for database operations.**
Using `unwrap()` can lead to panics if the database operation fails. Consider handling the error with `map_err` or `expect` with a meaningful message.
Replace `unwrap()` with proper error handling to prevent potential panics.
<!-- This is an auto-generated comment by CodeRabbit -->
|
Avoid using
unwrap()
for database operations.Using
unwrap()
can lead to panics if the database operation fails. Consider handling the error withmap_err
orexpect
with a meaningful message.Replace
unwrap()
with proper error handling to prevent potential panics.Avoid using
unwrap()
for database operations.Using
unwrap()
can lead to panics if the database operation fails. Consider handling the error withmap_err
orexpect
with a meaningful message.Replace
unwrap()
with proper error handling to prevent potential panics.