Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "qb_api"
version = "1.1.0"
version = "1.1.1"
edition = "2021"

[dependencies]
Expand Down
4 changes: 2 additions & 2 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ Bot 账号不会自动生成;管理员创建或轮换 bot 账号时,接口
- "非 used" 指 `status != 'used'` 的题目
- "被分配的" 指在 `question_reviews` 表中被 leader 分配为审阅人的题目(user 和 leader 均可被分配)
- reviewer 进行任意操作时,自动将其 display_name 加入 `questions.reviewers` 数组(去重)
- 替换文件时,后端自动重置 difficulty(清空)、status(`none`)、author(创建者 display_name)、reviewers(`[]`)
- 替换文件时,后端仅更新题目文件、`source_tex_path`、从 TeX 提取出的 `score`、以及 `updated_at`
- 上传时,后端自动设置 difficulty 为空、status 为 `none`、author 为上传者 display_name、reviewers 为 `[]`
- 后端自动维护 `created_by`、`created_at`、`updated_at`
- 题目创建者(`created_by`)始终可修改自己题目的 description、category、tags 和 file,不受 status 限制
Expand Down Expand Up @@ -582,7 +582,7 @@ Bot 账号不会自动生成;管理员创建或轮换 bot 账号时,接口
- **Content-Type**:`multipart/form-data`
- **字段**:`file`(binary zip)

**自动重置**:`difficulty`(清空所有条目)、`status` → `"none"`、`author` → 创建者当前 display_name、`reviewers` → `[]`。
**后端行为**:仅替换题目文件,并更新 `source_tex_path`、从 TeX 提取出的 `score`、以及 `updated_at`;不会改动 `status`、`author`、`reviewers`、`difficulty`。

**成功响应** `200`:`{ "question_id", "file_name", "source_tex_path", "imported_assets", "status": "replaced" }`

Expand Down
4 changes: 2 additions & 2 deletions src/api/questions/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
- "非 used" 指 `status != 'used'` 的题目
- "被分配的" 指在 `question_reviews` 表中被 leader 分配为审阅人的题目(user 和 leader 均可被分配)
- reviewer 进行任意操作时,自动将其 display_name 加入 `questions.reviewers` 数组(去重)
- 替换文件时,后端自动重置 difficulty(清空)、status(`none`)、author(创建者 display_name)、reviewers(`[]`)
- 替换文件时,后端仅更新题目文件、`source_tex_path`、从 TeX 提取出的 `score`、以及 `updated_at`
- 上传时,后端自动设置 difficulty 为空、status 为 `none`、author 为上传者 display_name、reviewers 为 `[]`
- 后端自动维护 `created_by`、`created_at`、`updated_at`
- 题目创建者(`created_by`)始终可修改自己题目的 description、category、tags 和 file,不受 status 限制
Expand Down Expand Up @@ -200,7 +200,7 @@
- **Content-Type**:`multipart/form-data`
- **字段**:`file`(binary zip)

**自动重置**:`difficulty`(清空所有条目)、`status` → `"none"`、`author` → 创建者当前 display_name、`reviewers` → `[]`。
**后端行为**:仅替换题目文件,并更新 `source_tex_path`、从 TeX 提取出的 `score`、以及 `updated_at`;不会改动 `status`、`author`、`reviewers`、`difficulty`。

**成功响应** `200`:`{ "question_id", "file_name", "source_tex_path", "imported_assets", "status": "replaced" }`

Expand Down
17 changes: 0 additions & 17 deletions src/api/questions/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,27 +225,12 @@ pub(crate) async fn replace_question_file(
let (file_name, bytes) = read_uploaded_file(&mut multipart).await?;
validate_upload_size(&bytes, MAX_UPLOAD_BYTES)?;

// Look up the creator's current display_name for resetting the author field.
let creator_display_name = if let Some(ref created_by) = access.created_by {
query("SELECT display_name FROM users WHERE user_id = $1::uuid")
.bind(created_by)
.fetch_optional(&state.pool)
.await
.context("look up creator display_name failed")
.map_err(ApiError::from)?
.map(|r| r.get::<String, _>("display_name"))
.unwrap_or_default()
} else {
String::new()
};

Ok(Json(
replace_question_zip(
&state.pool,
&question_id,
file_name.as_deref(),
bytes,
&creator_display_name,
)
.await
.map_err(ApiError::from)?,
Expand Down Expand Up @@ -790,7 +775,6 @@ async fn fetch_question_detail(
struct QuestionAccessInfo {
#[allow(dead_code)]
status: String,
created_by: Option<String>,
is_admin_or_bot: bool,
is_leader: bool,
is_owner: bool,
Expand Down Expand Up @@ -838,7 +822,6 @@ async fn load_question_access(

Ok(QuestionAccessInfo {
status,
created_by,
is_admin_or_bot,
is_leader,
is_owner,
Expand Down
13 changes: 1 addition & 12 deletions src/api/questions/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ pub(crate) async fn replace_question_zip(
question_id: &str,
file_name: Option<&str>,
zip_bytes: Vec<u8>,
creator_display_name: &str,
) -> Result<QuestionFileReplaceResponse> {
if zip_bytes.is_empty() {
return Err(ValidationError("uploaded file is empty".into()).into());
Expand Down Expand Up @@ -132,22 +131,12 @@ pub(crate) async fn replace_question_zip(

replace_question_files_tx(&mut tx, question_id, &loaded).await?;

// Reset difficulty, status, author, reviewers to creation state.
query("DELETE FROM question_difficulties WHERE question_id = $1::uuid")
.bind(question_id)
.execute(&mut *tx)
.await
.context("clear question difficulties on file replace failed")?;

let empty_reviewers: Vec<String> = vec![];
query(
"UPDATE questions SET source_tex_path = $2, score = $3, status = 'none', author = $4, reviewers = $5, updated_at = NOW() WHERE question_id = $1::uuid",
"UPDATE questions SET source_tex_path = $2, score = $3, updated_at = NOW() WHERE question_id = $1::uuid",
)
.bind(question_id)
.bind(&loaded.tex_file.path)
.bind(loaded.score)
.bind(creator_display_name)
.bind(&empty_reviewers)
.execute(&mut *tx)
.await
.context("update question on file replace failed")?;
Expand Down
Loading