Remove unwraps

This commit is contained in:
Greg Shuflin 2025-02-02 21:07:22 -08:00
parent 202a7e5224
commit 3ca699b948
6 changed files with 139 additions and 12 deletions

View File

@ -0,0 +1,20 @@
{
"db_name": "SQLite",
"query": "SELECT url FROM feeds WHERE feed_id = ? AND user_id = ?",
"describe": {
"columns": [
{
"name": "url",
"ordinal": 0,
"type_info": "Text"
}
],
"parameters": {
"Right": 2
},
"nullable": [
false
]
},
"hash": "5ca2526f1ec4a055bc36898ef13a7d830df848285f4f6d66bb104935844b7f2d"
}

View File

@ -1,6 +1,6 @@
{ {
"db_name": "SQLite", "db_name": "SQLite",
"query": "\n SELECT \n feed_id as \"feed_id: String\",\n name,\n url,\n user_id as \"user_id: String\",\n added_time as \"added_time: chrono::DateTime<chrono::Utc>\",\n last_checked_time as \"last_checked_time: chrono::DateTime<chrono::Utc>\"\n FROM feeds\n WHERE user_id = ?\n ORDER BY added_time DESC\n ", "query": "\n SELECT \n feed_id as \"feed_id: String\",\n name,\n url,\n user_id as \"user_id: String\",\n added_time as \"added_time: chrono::DateTime<chrono::Utc>\",\n last_checked_time as \"last_checked_time: chrono::DateTime<chrono::Utc>\",\n categorization as \"categorization: JsonValue\"\n FROM feeds\n WHERE user_id = ?\n ORDER BY added_time DESC\n ",
"describe": { "describe": {
"columns": [ "columns": [
{ {
@ -32,6 +32,11 @@
"name": "last_checked_time: chrono::DateTime<chrono::Utc>", "name": "last_checked_time: chrono::DateTime<chrono::Utc>",
"ordinal": 5, "ordinal": 5,
"type_info": "Datetime" "type_info": "Datetime"
},
{
"name": "categorization: JsonValue",
"ordinal": 6,
"type_info": "Null"
} }
], ],
"parameters": { "parameters": {
@ -43,8 +48,9 @@
false, false,
false, false,
false, false,
false,
false false
] ]
}, },
"hash": "f2c677b85d02ab2698c88013a5f0450a54ba4b29712b21cadb47971d38db012b" "hash": "7fa0f8d0047afea873a0622bcc26d7a5f903e11d59158768c41125ad36fa4810"
} }

View File

@ -0,0 +1,56 @@
{
"db_name": "SQLite",
"query": "\n SELECT \n feed_id as \"feed_id: String\",\n name,\n url,\n user_id as \"user_id: String\",\n added_time as \"added_time: chrono::DateTime<chrono::Utc>\",\n last_checked_time as \"last_checked_time: chrono::DateTime<chrono::Utc>\",\n categorization as \"categorization: JsonValue\"\n FROM feeds\n WHERE feed_id = ? AND user_id = ?\n ",
"describe": {
"columns": [
{
"name": "feed_id: String",
"ordinal": 0,
"type_info": "Text"
},
{
"name": "name",
"ordinal": 1,
"type_info": "Text"
},
{
"name": "url",
"ordinal": 2,
"type_info": "Text"
},
{
"name": "user_id: String",
"ordinal": 3,
"type_info": "Text"
},
{
"name": "added_time: chrono::DateTime<chrono::Utc>",
"ordinal": 4,
"type_info": "Datetime"
},
{
"name": "last_checked_time: chrono::DateTime<chrono::Utc>",
"ordinal": 5,
"type_info": "Datetime"
},
{
"name": "categorization: JsonValue",
"ordinal": 6,
"type_info": "Null"
}
],
"parameters": {
"Right": 2
},
"nullable": [
false,
false,
false,
false,
false,
false,
false
]
},
"hash": "cdc67f9eab7ea164d2fdf95385ad33437f839c5f5b153bada97bc628bee87b51"
}

View File

@ -1,6 +1,6 @@
{ {
"db_name": "SQLite", "db_name": "SQLite",
"query": "\n SELECT \n id as \"id: String\",\n username,\n password_hash,\n email,\n display_name,\n created_at as \"created_at: chrono::DateTime<chrono::Utc>\"\n FROM users\n ", "query": "\n SELECT \n id as \"id: String\",\n username,\n password_hash,\n email,\n display_name,\n created_at as \"created_at: chrono::DateTime<chrono::Utc>\",\n admin as \"admin: bool\"\n FROM users\n ",
"describe": { "describe": {
"columns": [ "columns": [
{ {
@ -32,6 +32,11 @@
"name": "created_at: chrono::DateTime<chrono::Utc>", "name": "created_at: chrono::DateTime<chrono::Utc>",
"ordinal": 5, "ordinal": 5,
"type_info": "Text" "type_info": "Text"
},
{
"name": "admin: bool",
"ordinal": 6,
"type_info": "Bool"
} }
], ],
"parameters": { "parameters": {
@ -43,8 +48,9 @@
false, false,
true, true,
true, true,
false,
false false
] ]
}, },
"hash": "d04ca7e16ebbeb1213fc829a4ff1337427c6875e750c6d3570a314fe3136d36f" "hash": "f27285d2d332e5aafd319c3052c3f601c2a61b3b1ddd5e9fd65e43c70ed82c9c"
} }

View File

@ -0,0 +1,20 @@
{
"db_name": "SQLite",
"query": "SELECT COUNT(*) as count FROM users",
"describe": {
"columns": [
{
"name": "count",
"ordinal": 0,
"type_info": "Int"
}
],
"parameters": {
"Right": 0
},
"nullable": [
false
]
},
"hash": "fd64104d130b93dd5fc9414b8710ad5183b647eaaff90decbce15e10d83c7538"
}

View File

@ -62,10 +62,13 @@ pub async fn create_feed(
.map_err(|_| Status::UnprocessableEntity)?; .map_err(|_| Status::UnprocessableEntity)?;
// Use the feed title as the name, or URL if no title is available // Use the feed title as the name, or URL if no title is available
let name = feed_data let name = feed_data.title.map(|t| t.content).unwrap_or_else(|| {
.title new_feed
.map(|t| t.content) .url
.unwrap_or_else(|| new_feed.url.host_str().unwrap_or("<Unknown>").to_string()); .host_str()
.map(|s| s.to_string())
.unwrap_or_else(|| "<Unknown>".to_string())
});
let mut feed = Feed::new(name, new_feed.url, user.user_id); let mut feed = Feed::new(name, new_feed.url, user.user_id);
feed.categorization = new_feed.categorization; feed.categorization = new_feed.categorization;
@ -149,12 +152,20 @@ pub async fn list_feeds(
eprintln!("Failed to parse categorization: {}", e); eprintln!("Failed to parse categorization: {}", e);
Status::InternalServerError Status::InternalServerError
})?; })?;
let feed_id = Uuid::parse_str(&row.feed_id).map_err(|e| {
eprintln!("Failed to parse feed_id UUID: {}", e);
Status::InternalServerError
})?;
let user_id = Uuid::parse_str(&row.user_id).map_err(|e| {
eprintln!("Failed to parse user_id UUID: {}", e);
Status::InternalServerError
})?;
Ok(Feed { Ok(Feed {
feed_id: Uuid::parse_str(&row.feed_id).unwrap(),
name: row.name, name: row.name,
feed_id,
url, url,
user_id: Uuid::parse_str(&row.user_id).unwrap(), user_id,
added_time: row.added_time, added_time: row.added_time,
last_checked_time: row.last_checked_time, last_checked_time: row.last_checked_time,
categorization, categorization,
@ -240,12 +251,20 @@ pub async fn get_feed(
eprintln!("Failed to parse categorization: {}", e); eprintln!("Failed to parse categorization: {}", e);
Status::InternalServerError Status::InternalServerError
})?; })?;
let user_id = Uuid::parse_str(&row.user_id).map_err(|e| {
eprintln!("Failed to parse user_id UUID: {}", e);
Status::InternalServerError
})?;
let feed_id = Uuid::parse_str(&row.feed_id).map_err(|e| {
eprintln!("Failed to parse feed_id UUID: {}", e);
Status::InternalServerError
})?;
Ok(Json(Feed { Ok(Json(Feed {
feed_id: Uuid::parse_str(&row.feed_id).unwrap(), feed_id,
name: row.name, name: row.name,
url, url,
user_id: Uuid::parse_str(&row.user_id).unwrap(), user_id,
added_time: row.added_time, added_time: row.added_time,
last_checked_time: row.last_checked_time, last_checked_time: row.last_checked_time,
categorization, categorization,