pub async fn create_list(list: ListDTO, owner_username: String, db: PostgresDbConn) -> ResponseWithStatus {
    db.run(move |conn| {
        if let Some(user) = User::find_user_by_username(&owner_username, conn) {
            if let Some(result_list) = List::create_list(list, conn) {
                if UserList::associate_list(result_list, user, true, conn) {
                    ResponseWithStatus {
                        status_code: Status::Ok.code,
                        response: Response {
                            message: String::from(constants::MESSAGE_CREATE_LIST_SUCCESS),
                            data: serde_json::to_value("").unwrap(),
                        },
                    }
                } else {
                    ResponseWithStatus {
                        status_code: Status::BadRequest.code,
                        response: Response {
                            message: String::from(constants::MESSAGE_CREATE_LIST_ASSOCIATE_FAIL),
                            data: serde_json::to_value("").unwrap(),
                        },
                    }
                }
            } else {
                ResponseWithStatus {
                    status_code: Status::BadRequest.code,
                    response: Response {
                        message: String::from(constants::MESSAGE_CREATE_LIST_FAILED),
                        data: serde_json::to_value("").unwrap(),
                    },
                }
            }
        } else {
            ResponseWithStatus {
                status_code: Status::BadRequest.code,
                response: Response {
                    message: String::from(constants::MESSAGE_USER_NOT_FOUND),
                    data: serde_json::to_value("").unwrap(),
                },
            }
        }
    }).await
}
/// Attempts to create the list with the specified information and associate it with its owner.
/// Responds with the appropriate status.
Attempts to create the list with the specified information and associate it with its owner.
Responds with the appropriate status.
Attempts to create the list with the specified information and associate it with its owner . Responds with the appropriate status .
pub async fn create_list(list: ListDTO, owner_username: String, db: PostgresDbConn) -> ResponseWithStatus {
    db.run(move |conn| {
        if let Some(user) = User::find_user_by_username(&owner_username, conn) {
            if let Some(result_list) = List::create_list(list, conn) {
                if UserList::associate_list(result_list, user, true, conn) {
                    ResponseWithStatus {
                        status_code: Status::Ok.code,
                        response: Response {
                            message: String::from(constants::MESSAGE_CREATE_LIST_SUCCESS),
                            data: serde_json::to_value("").unwrap(),
                        },
                    }
                } else {
                    ResponseWithStatus {
                        status_code: Status::BadRequest.code,
                        response: Response {
                            message: String::from(constants::MESSAGE_CREATE_LIST_ASSOCIATE_FAIL),
                            data: serde_json::to_value("").unwrap(),
                        },
                    }
                }
            } else {
                ResponseWithStatus {
                    status_code: Status::BadRequest.code,
                    response: Response {
                        message: String::from(constants::MESSAGE_CREATE_LIST_FAILED),
                        data: serde_json::to_value("").unwrap(),
                    },
                }
            }
        } else {
            ResponseWithStatus {
                status_code: Status::BadRequest.code,
                response: Response {
                    message: String::from(constants::MESSAGE_USER_NOT_FOUND),
                    data: serde_json::to_value("").unwrap(),
                },
            }
        }
    }).await
}
pub async fn create_list ( list : ListDTO , owner_username : String , db : PostgresDbConn ) -> ResponseWithStatus { db . run ( move | conn | { if let Some ( user ) = User :: find_user_by_username ( & owner_username , conn ) { if let Some ( result_list ) = List :: create_list ( list , conn ) { if UserList :: associate_list ( result_list , user , true , conn ) { ResponseWithStatus { status_code : Status :: Ok . code , response : Response { message : String :: from ( constants :: MESSAGE_CREATE_LIST_SUCCESS ) , data : serde_json :: to_value ( " " ) . unwrap ( ) , } , } } else { ResponseWithStatus { status_code : Status :: BadRequest . code , response : Response { message : String :: from ( constants :: MESSAGE_CREATE_LIST_ASSOCIATE_FAIL ) , data : serde_json :: to_value ( " " ) . unwrap ( ) , } , } } } else { ResponseWithStatus { status_code : Status :: BadRequest . code , response : Response { message : String :: from ( constants :: MESSAGE_CREATE_LIST_FAILED ) , data : serde_json :: to_value ( " " ) . unwrap ( ) , } , } } } else { ResponseWithStatus { status_code : Status :: BadRequest . code , response : Response { message : String :: from ( constants :: MESSAGE_USER_NOT_FOUND ) , data : serde_json :: to_value ( " " ) . unwrap ( ) , } , } } } ) . await }
Attempts to create the list with the specified information and associate it with its owner.
Attempts to create the list with the specified information and associate it with its owner .
list
ListDTO
owner_username
String
db
PostgresDbConn
list
ListDTO
owner_username
String
db
PostgresDbConn