Skip to content

Commit db93094

Browse files
fix: Modify variable names and error messages
Co-authored-by: Chris Ohk <[email protected]>
1 parent 3c14ecc commit db93094

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

src/file_manager/handlers.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub async fn upload_file(
2424
Path((problem_id, category)): Path<(u32, String)>,
2525
multipart: Multipart,
2626
) -> impl IntoResponse {
27-
let (file_name, data) = match extract_multipart_data(multipart).await {
27+
let (filename, data) = match extract_multipart_data(multipart).await {
2828
Ok(data) => data,
2929
Err(e) => {
3030
return (
@@ -48,7 +48,7 @@ pub async fn upload_file(
4848
return (
4949
StatusCode::CONFLICT,
5050
Json(serde_json::json!({
51-
"error": format!("File '{}' already exists in this category", file_name)
51+
"error": format!("File '{file_name}' already exists in this category")
5252
})),
5353
)
5454
.into_response();
@@ -112,9 +112,9 @@ async fn extract_multipart_data(mut multipart: Multipart) -> Result<(String, axu
112112
.await?
113113
.ok_or_else(|| anyhow!("Missing multipart field"))?;
114114

115-
let file_name = field
115+
let filename = field
116116
.file_name()
117-
.ok_or_else(|| anyhow!("Missing file name in multipart field"))?
117+
.ok_or_else(|| anyhow!("Missing filename in multipart field"))?
118118
.to_string();
119119

120120
let data = field.bytes().await?;
@@ -134,7 +134,7 @@ pub async fn get_file(
134134
return (
135135
StatusCode::NOT_FOUND,
136136
Json(serde_json::json!({
137-
"error": format!("File '{}' not found in category '{}'", filename, category)
137+
"error": format!("File '{filename}' not found in category '{category}'")
138138
})),
139139
)
140140
.into_response();
@@ -172,7 +172,7 @@ pub async fn get_files_by_category(
172172
return (
173173
StatusCode::NOT_FOUND,
174174
Json(serde_json::json!({
175-
"error": format!("Category '{}' not found for problem {}", category, problem_id)
175+
"error": format!("Category '{category}' not found for problem {problem_id}")
176176
})),
177177
)
178178
.into_response();
@@ -217,7 +217,7 @@ pub async fn delete_file(
217217
return (
218218
StatusCode::NOT_FOUND,
219219
Json(serde_json::json!({
220-
"error": format!("File '{}' not found in category '{}'", filename, category)
220+
"error": format!("File '{filename}' not found in category '{category}'")
221221
})),
222222
)
223223
.into_response();
@@ -227,7 +227,7 @@ pub async fn delete_file(
227227
Ok(_) => (
228228
StatusCode::OK,
229229
Json(serde_json::json!({
230-
"message": format!("File '{}' deleted successfully", filename)
230+
"message": format!("File '{filename}' deleted successfully")
231231
})),
232232
)
233233
.into_response(),
@@ -254,7 +254,7 @@ pub async fn update_file_content(
254254
return (
255255
StatusCode::NOT_FOUND,
256256
Json(serde_json::json!({
257-
"error": format!("File '{}' not found in category '{}'", filename, category)
257+
"error": format!("File '{filename}' not found in category '{category}'")
258258
})),
259259
)
260260
.into_response();
@@ -264,7 +264,7 @@ pub async fn update_file_content(
264264
Ok(_) => (
265265
StatusCode::OK,
266266
Json(serde_json::json!({
267-
"message": format!("File '{}' updated successfully", filename)
267+
"message": format!("File '{filename}' updated successfully")
268268
})),
269269
)
270270
.into_response(),
@@ -292,8 +292,8 @@ pub async fn update_filename(
292292
StatusCode::NOT_FOUND,
293293
Json(serde_json::json!({
294294
"error": format!(
295-
"File '{}' not found in category '{}'",
296-
update_request.old_filename, category
295+
"File '{}' not found in category '{category}'",
296+
update_request.old_filename
297297
)
298298
})),
299299
)

src/file_manager/models.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl std::fmt::Display for LanguageError {
3333
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3434
match self {
3535
LanguageError::UnsupportedExtension(extension) => {
36-
write!(f, "Unsupported file extension: {}", extension)
36+
write!(f, "Unsupported file extension: {extension}")
3737
}
3838
LanguageError::InvalidFilename => write!(f, "Invalid filename"),
3939
}

0 commit comments

Comments
 (0)