Skip to content

Commit ca12b14

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

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

src/file_manager/handlers.rs

Lines changed: 16 additions & 16 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 (
@@ -42,20 +42,20 @@ pub async fn upload_file(
4242
.join(problem_id.to_string())
4343
.join(&category);
4444

45-
let file_path = upload_dir.join(&file_name);
45+
let file_path = upload_dir.join(&filename);
4646

4747
if file_exists(&file_path).await {
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 '{filename}' already exists in this category")
5252
})),
5353
)
5454
.into_response();
5555
}
5656

5757
let now = Utc::now();
58-
let language = match Language::from_filename(&file_name) {
58+
let language = match Language::from_filename(&filename) {
5959
Ok(lang) => lang,
6060
Err(e) => {
6161
return (
@@ -80,7 +80,7 @@ pub async fn upload_file(
8080

8181
let metadata = FileMetadata {
8282
id: file_id,
83-
filename: file_name,
83+
filename: filename,
8484
language: language,
8585
category: category,
8686
size: data.len() as u64,
@@ -112,14 +112,14 @@ 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?;
121121

122-
Ok((file_name, data))
122+
Ok((filename, data))
123123
}
124124

125125
pub async fn get_file(
@@ -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)