From f1e5fd879356df808a7cdcff9cab280e08106b19 Mon Sep 17 00:00:00 2001 From: shay7sev Date: Wed, 15 Jul 2026 15:36:51 +0800 Subject: [PATCH] feat: establish Rust teaching feedback API Add the Axum and PostgreSQL service for profiles, defaults, and feedback records, including migrations, OpenAPI documentation, and development identity handling for version 0.1.0. --- .env.example | 9 + .gitignore | 10 + API.md | 88 + API_GUIDE.md | 119 ++ Cargo.lock | 2423 ++++++++++++++++++++++++++++ Cargo.toml | 23 + migrations/0001_initial_schema.sql | 45 + src/bin/migrate.rs | 17 + src/config.rs | 39 + src/error.rs | 93 ++ src/main.rs | 80 + src/routes.rs | 884 ++++++++++ 12 files changed, 3830 insertions(+) create mode 100644 .env.example create mode 100644 .gitignore create mode 100644 API.md create mode 100644 API_GUIDE.md create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 migrations/0001_initial_schema.sql create mode 100644 src/bin/migrate.rs create mode 100644 src/config.rs create mode 100644 src/error.rs create mode 100644 src/main.rs create mode 100644 src/routes.rs diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..92f9413 --- /dev/null +++ b/.env.example @@ -0,0 +1,9 @@ +# The API starts without this variable, but data endpoints return HTTP 503. +# DATABASE_URL=postgres://username:password@hostname:5432/teaching_feedback?sslmode=require + +HOST=127.0.0.1 +PORT=8080 +DATABASE_MAX_CONNECTIONS=5 + +# A single development origin. Leave unset to disable CORS middleware. +# CORS_ALLOWED_ORIGIN=https://servicewechat.com diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ad36eaf --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +# Rust build output +/target/ + +# Local configuration and secrets +.env +.env.* +!.env.example + +# Graphify generated knowledge graphs +/graphify-out/ diff --git a/API.md b/API.md new file mode 100644 index 0000000..c10caa6 --- /dev/null +++ b/API.md @@ -0,0 +1,88 @@ +# 教学反馈助手 API + +## 交互文档 + +服务启动后提供以下文档入口: + +- Scalar:`GET /scalar` +- OpenAPI JSON:`GET /openapi.json` +- 完整调用流程:[API_GUIDE.md](./API_GUIDE.md) + +Scalar 中的业务接口已预填开发用户 ID 和请求体示例。创建、列表、预设和健康检查可以直接发起请求;按 ID 操作时,应使用创建或列表接口返回的真实 ID。 + +## 启动和数据库策略 + +本服务不会创建或启动本地 PostgreSQL。 + +- 未设置 `DATABASE_URL` 时,`cargo run` 只启动 HTTP 服务;`GET /health` 返回成功,数据接口返回 `503`。 +- 获得远程 PostgreSQL 地址后,将其写入本地未提交的 `server/.env`,执行 `cargo run --bin migrate`,再执行 `cargo run`。 +- 迁移不会使用 PostgreSQL 扩展,UUID 由 Rust 服务生成。 + +```bash +cd server +cp .env.example .env +# 在 .env 中填写 DATABASE_URL +cargo run --bin migrate +cargo run +``` + +## 临时身份边界 + +目前所有业务接口都要求 `X-User-Id` 请求头,值为 UUID。例如: + +```text +X-User-Id: 5a4da7f0-d70c-465f-bcab-124c504aa9f0 +``` + +这是微信登录接入完成前的开发身份边界,用于确保每位教师只能访问自己的记录。接入微信登录后,后端会从登录凭据解析用户身份,客户端不再直接提供此请求头。 + +## 接口 + +| 方法 | 路径 | 说明 | +| --- | --- | --- | +| `GET` | `/health` | 服务状态及数据库是否已配置。 | +| `GET` | `/api/v1/profiles` | 列出学生档案;可选 `query`、`grade`、`subject` 参数。 | +| `POST` | `/api/v1/profiles` | 创建学生档案。 | +| `GET` | `/api/v1/profiles/{profile_id}` | 读取单个学生档案。 | +| `PUT` | `/api/v1/profiles/{profile_id}` | 更新学生档案。 | +| `DELETE` | `/api/v1/profiles/{profile_id}` | 删除学生档案。 | +| `GET` | `/api/v1/profile-defaults` | 读取学生档案预设;未配置时返回美术课默认值。 | +| `PUT` | `/api/v1/profile-defaults` | 写入年级、学科和上课时长预设。 | +| `GET` | `/api/v1/feedback-records` | 列出反馈记录;可选 `profile_id` 参数。 | +| `POST` | `/api/v1/feedback-records` | 创建反馈记录。 | +| `DELETE` | `/api/v1/feedback-records/{record_id}` | 删除反馈记录。 | + +### 创建学生档案 + +```json +{ + "name": "小谢", + "grade": "艺术类", + "subject": "美术", + "academic_year": 2026, + "term": "暑", + "guardian_title": "小谢妈妈", + "start_time": "18:00", + "end_time": "19:00" +} +``` + +### 保存默认预设 + +```json +{ + "grade": "艺术类", + "subject": "美术", + "lesson_duration_minutes": 60 +} +``` + +### 创建反馈记录 + +```json +{ + "profile_id": "5fa5af2c-cfc9-4bb8-b0b3-8715f080b167", + "feedback_date": "2026-07-14", + "content": "今天完成了色彩搭配练习,构图有明显进步。" +} +``` diff --git a/API_GUIDE.md b/API_GUIDE.md new file mode 100644 index 0000000..b1dbca9 --- /dev/null +++ b/API_GUIDE.md @@ -0,0 +1,119 @@ +# 教学反馈助手 API 使用指南 + +## 1. 启动服务 + +在 `server/.env` 中配置 `DATABASE_URL` 后执行: + +```bash +cd server +cargo run --bin migrate +cargo run +``` + +默认地址取决于 `.env` 中的 `HOST` 和 `PORT`。使用示例配置时,可访问: + +- Scalar 交互文档: +- OpenAPI JSON: +- 健康检查: + +如果未配置 `DATABASE_URL`,服务仍可启动并访问健康检查和 API 文档,但业务接口返回 `503`。 + +## 2. 在 Scalar 中直接测试 + +打开 `/scalar`,选择接口后点击 **Test Request**。业务接口已经预填以下开发用户 ID: + +```text +X-User-Id: 5a4da7f0-d70c-465f-bcab-124c504aa9f0 +``` + +请求体接口也已提供可发送的默认 JSON。建议按以下顺序测试: + +1. 执行 `GET /health`,确认 `database_configured` 为 `true`。 +2. 执行 `GET /api/v1/profile-defaults`,即使用户未保存过预设也会返回系统默认值。 +3. 执行 `PUT /api/v1/profile-defaults`,可直接发送预填的美术课预设。 +4. 执行 `POST /api/v1/profiles`,可直接发送预填档案;保存响应中的 `id`。 +5. 将真实档案 `id` 填入 `{profile_id}`,测试单条查询、更新或删除。 +6. 执行 `POST /api/v1/feedback-records`。默认 `profile_id` 为 `null`,无需档案即可直接创建。 +7. 如需关联档案,将第 4 步得到的 `id` 写入 `profile_id`。创建后保存反馈响应中的 `id`。 +8. 将真实反馈 `id` 填入 `{record_id}`,测试删除接口。 + +OpenAPI 中的 `11111111-...` 和 `22222222-...` 仅用于展示路径参数格式,并不是数据库预置记录。调用按 ID 查询、更新或删除的接口时,必须换成创建或列表接口返回的真实 ID。 + +## 3. 常用请求示例 + +### 健康检查 + +```bash +curl http://127.0.0.1:8080/health +``` + +### 创建学生档案 + +```bash +curl -X POST http://127.0.0.1:8080/api/v1/profiles \ + -H 'Content-Type: application/json' \ + -H 'X-User-Id: 5a4da7f0-d70c-465f-bcab-124c504aa9f0' \ + -d '{ + "name": "小谢", + "grade": "艺术类", + "subject": "美术", + "academic_year": 2026, + "term": "暑", + "guardian_title": "小谢妈妈", + "start_time": "18:00", + "end_time": "19:00" + }' +``` + +### 创建不关联档案的反馈 + +```bash +curl -X POST http://127.0.0.1:8080/api/v1/feedback-records \ + -H 'Content-Type: application/json' \ + -H 'X-User-Id: 5a4da7f0-d70c-465f-bcab-124c504aa9f0' \ + -d '{ + "profile_id": null, + "feedback_date": "2026-07-15", + "content": "今天完成了色彩搭配练习,构图有明显进步。" + }' +``` + +### 筛选反馈记录 + +```bash +curl 'http://127.0.0.1:8080/api/v1/feedback-records?profile_id=<真实档案ID>' \ + -H 'X-User-Id: 5a4da7f0-d70c-465f-bcab-124c504aa9f0' +``` + +## 4. 身份和数据隔离 + +当前尚未接入微信登录,所有业务接口临时使用 `X-User-Id` 标识用户。相同 UUID 可以访问自己创建的数据,不同 UUID 之间的数据互相不可见。 + +`X-User-Id` 缺失时返回 `401`,格式不是 UUID 时返回 `400`。接入微信登录后,应由后端根据登录凭据确定用户身份,客户端不再直接提交该请求头。 + +小程序开发客户端当前使用同一个测试 UUID,并默认连接 `http://127.0.0.1:8080`。可在小程序“我的”页面修改 API 地址并执行健康检查。真机或正式环境应使用已配置为微信 request 合法域名的 HTTPS 地址。 + +## 5. 响应状态码 + +| 状态码 | 含义 | +| --- | --- | +| `200` | 查询或更新成功 | +| `201` | 创建成功 | +| `204` | 删除成功,无响应体 | +| `400` | 参数格式或业务校验失败 | +| `401` | 缺少 `X-User-Id` | +| `404` | 记录不存在或不属于当前用户 | +| `500` | 数据库查询或服务内部错误 | +| `503` | 未配置数据库连接 | + +错误响应统一为: + +```json +{ + "error": "错误说明" +} +``` + +## 6. OpenAPI 维护方式 + +`/openapi.json` 在服务运行时由 `utoipa` 根据 Rust 路由注解生成,Scalar 使用同一份规范。新增或修改接口时,需要同时更新处理函数上的 `#[utoipa::path]`、请求/响应 schema 注释和示例;规范完整性测试会检查操作数量、接口说明和默认身份参数。 diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..6b5d333 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,2423 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "aho-corasick" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddd31a130427c27518df266943a5308ed92d4b226cc639f5a8f1002816174301" +dependencies = [ + "memchr", +] + +[[package]] +name = "allocator-api2" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + +[[package]] +name = "atoi" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f28d99ec8bfea296261ca1af174f24225171fea9664ba9003cbebee704810528" +dependencies = [ + "num-traits", +] + +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + +[[package]] +name = "autocfg" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53" + +[[package]] +name = "axum" +version = "0.8.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31b698c5f9a010f6573133b09e0de5408834d0c82f8d7475a89fc1867a71cd90" +dependencies = [ + "axum-core", + "axum-macros", + "bytes", + "form_urlencoded", + "futures-util", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-util", + "itoa", + "matchit", + "memchr", + "mime", + "percent-encoding", + "pin-project-lite", + "serde_core", + "serde_json", + "serde_path_to_error", + "serde_urlencoded", + "sync_wrapper", + "tokio", + "tower", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "axum-core" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08c78f31d7b1291f7ee735c1c6780ccde7785daae9a9206026862dab7d8792d1" +dependencies = [ + "bytes", + "futures-core", + "http", + "http-body", + "http-body-util", + "mime", + "pin-project-lite", + "sync_wrapper", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "axum-macros" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7aa268c23bfbbd2c4363b9cd302a4f504fb2a9dfe7e3451d66f35dd392e20aca" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "base64ct" +version = "1.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2af50177e190e07a26ab74f8b1efbfe2ef87da2116221318cb1c2e82baf7de06" + +[[package]] +name = "bitflags" +version = "2.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4388bee8683e3d04af747c73422af53102d2bd24d9eadb6cbc100baef4b43f8" +dependencies = [ + "serde_core", +] + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "bumpalo" +version = "3.20.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72f5acc6cb2ba439de613abc23857ec3d78374d8ed5ac84e9d11336e87da8649" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc652a48c352aef3ea3aed32080501cf3ef6ed5da78602a020c991775b0aff04" + +[[package]] +name = "cc" +version = "1.2.67" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e17dd265a7d0f31ef544e1b20e03add05d3b45b491b633b10d67145d2acc1a38" +dependencies = [ + "find-msvc-tools", + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" + +[[package]] +name = "chrono" +version = "0.4.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1aa79e62e7697b8e29b513a68abacf485adcd1fe8284a4316c5ae868e6633327" +dependencies = [ + "iana-time-zone", + "js-sys", + "num-traits", + "serde", + "wasm-bindgen", + "windows-link", +] + +[[package]] +name = "concurrent-queue" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ca0197aee26d1ae37445ee532fefce43251d24cc7c166799f4d46817f1d3973" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "const-oid" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "cpufeatures" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" +dependencies = [ + "libc", +] + +[[package]] +name = "crc" +version = "3.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5eb8a2a1cd12ab0d987a5d5e825195d372001a4094a0376319d5a0ad71c1ba0d" +dependencies = [ + "crc-catalog", +] + +[[package]] +name = "crc-catalog" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "217698eaf96b4a3f0bc4f3662aaa55bdf913cd54d7204591faa790070c6d0853" + +[[package]] +name = "crossbeam-queue" +version = "0.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "803d13fb3b09d88be9f4dbc29062c66b19bf7170867ceb746d2a8689bf6c7a26" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61803da095bee82a81bb1a452ecc25d3b2f1416d1897eb86430c6159ef717c17" + +[[package]] +name = "crypto-common" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "der" +version = "0.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7c1832837b905bbfb5101e07cc24c8deddf52f93225eee6ead5f4d63d53ddcb" +dependencies = [ + "const-oid", + "pem-rfc7468", + "zeroize", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "const-oid", + "crypto-common", + "subtle", +] + +[[package]] +name = "displaydoc" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ac70aa55017e108007fbaf5aa0f54b021c98f92ff8af59d42eda9da96e3dd4f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "dotenvy" +version = "0.15.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b" + +[[package]] +name = "either" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91622ff5e7162018101f2fea40d6ebf4a78bbe5a49736a2020649edf9693679e" +dependencies = [ + "serde", +] + +[[package]] +name = "equivalent" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" + +[[package]] +name = "errno" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" +dependencies = [ + "libc", + "windows-sys 0.61.2", +] + +[[package]] +name = "etcetera" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "136d1b5283a1ab77bd9257427ffd09d8667ced0570b6f938942bc7568ed5b943" +dependencies = [ + "cfg-if", + "home", + "windows-sys 0.48.0", +] + +[[package]] +name = "event-listener" +version = "5.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13b66accf52311f30a0db42147dadea9850cb48cd070028831ae5f5d4b856ab" +dependencies = [ + "concurrent-queue", + "parking", + "pin-project-lite", +] + +[[package]] +name = "find-msvc-tools" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582" + +[[package]] +name = "flume" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da0e4dd2a88388a1f4ccc7c9ce104604dab68d9f408dc34cd45823d5a9069095" +dependencies = [ + "futures-core", + "futures-sink", + "spin", +] + +[[package]] +name = "foldhash" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" + +[[package]] +name = "form_urlencoded" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futures-channel" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07bbe89c50d7a535e539b8c17bc0b49bdb77747034daa8087407d655f3f7cc1d" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e3450815272ef58cec6d564423f6e755e25379b217b0bc688e295ba24df6b1d" + +[[package]] +name = "futures-executor" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf29c38818342a3b26b5b923639e7b1f4a61fc5e76102d4b1981c6dc7a7579d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-intrusive" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d930c203dd0b6ff06e0201a4a2fe9149b43c684fd4420555b26d21b1a02956f" +dependencies = [ + "futures-core", + "lock_api", + "parking_lot", +] + +[[package]] +name = "futures-io" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cecba35d7ad927e23624b22ad55235f2239cfa44fd10428eecbeba6d6a717718" + +[[package]] +name = "futures-sink" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c39754e157331b013978ec91992bde1ac089843443c49cbc7f46150b0fad0893" + +[[package]] +name = "futures-task" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "037711b3d59c33004d3856fbdc83b99d4ff37a24768fa1be9ce3538a1cde4393" + +[[package]] +name = "futures-util" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "389ca41296e6190b48053de0321d02a77f32f8a5d2461dd38762c0593805c6d6" +dependencies = [ + "futures-core", + "futures-io", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "slab", +] + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "getrandom" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "300e883d756b2e4ec94e02791f39b04b522276138852cfc41d9fb7e904106099" +dependencies = [ + "cfg-if", + "libc", + "r-efi", +] + +[[package]] +name = "hashbrown" +version = "0.15.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" +dependencies = [ + "allocator-api2", + "equivalent", + "foldhash", +] + +[[package]] +name = "hashbrown" +version = "0.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a" + +[[package]] +name = "hashlink" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7382cf6263419f2d8df38c55d7da83da5c18aef87fc7a7fc1fb1e344edfe14c1" +dependencies = [ + "hashbrown 0.15.5", +] + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "hkdf" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b5f8eb2ad728638ea2c7d47a21db23b7b58a72ed6a38256b8a1849f15fbbdf7" +dependencies = [ + "hmac", +] + +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest", +] + +[[package]] +name = "home" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589533453244b0995c858700322199b2becb13b627df2851f64a2775d024abcf" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "http" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6970f50e31d6fc17d3fa27329444bfa74e196cf62e95052a3f6fee181dba6425" +dependencies = [ + "bytes", + "itoa", +] + +[[package]] +name = "http-body" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca2a8f2913ee65f60facd6a5905613afaa448497a0230cc41ce022d93290bc2c" +dependencies = [ + "bytes", + "http", +] + +[[package]] +name = "http-body-util" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9f41fd6a08e4d4ec69df65976da761afd5ad5e58a9d4acb46bd1c953a9e3ff2" +dependencies = [ + "bytes", + "futures-core", + "http", + "http-body", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" + +[[package]] +name = "httpdate" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" + +[[package]] +name = "hyper" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55281c53a1894c864990125767da440a4e630446785086f52523b20033b74498" +dependencies = [ + "atomic-waker", + "bytes", + "futures-channel", + "futures-core", + "http", + "http-body", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", +] + +[[package]] +name = "hyper-util" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96547c2556ec9d12fb1578c4eaf448b04993e7fb79cbaad930a656880a6bdfa0" +dependencies = [ + "bytes", + "http", + "http-body", + "hyper", + "pin-project-lite", + "tokio", + "tower-service", +] + +[[package]] +name = "iana-time-zone" +version = "0.1.65" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e31bc9ad994ba00e440a8aa5c9ef0ec67d5cb5e5cb0cc7f8b744a35b389cc470" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "log", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + +[[package]] +name = "icu_collections" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c6b649701667bbe825c3b7e6388cb521c23d88644678e83c0c4d0a621a34b43" +dependencies = [ + "displaydoc", + "potential_utf", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locale_core" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edba7861004dd3714265b4db54a3c390e880ab658fec5f7db895fae2046b5bb6" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_normalizer" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f6c8828b67bf8908d82127b2054ea1b4427ff0230ee9141c54251934ab1b599" +dependencies = [ + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7aedcccd01fc5fe81e6b489c15b247b8b0690feb23304303a9e560f37efc560a" + +[[package]] +name = "icu_properties" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "020bfc02fe870ec3a66d93e677ccca0562506e5872c650f893269e08615d74ec" +dependencies = [ + "icu_collections", + "icu_locale_core", + "icu_properties_data", + "icu_provider", + "zerotrie", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "616c294cf8d725c6afcd8f55abc17c56464ef6211f9ed59cccffe534129c77af" + +[[package]] +name = "icu_provider" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85962cf0ce02e1e0a629cc34e7ca3e373ce20dda4c4d7294bbd0bf1fdb59e614" +dependencies = [ + "displaydoc", + "icu_locale_core", + "writeable", + "yoke", + "zerofrom", + "zerotrie", + "zerovec", +] + +[[package]] +name = "idna" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b0875f23caa03898994f6ddc501886a45c7d3d62d04d2d90788d47be1b1e4de" +dependencies = [ + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3acae9609540aa318d1bc588455225fb2085b9ed0c4f6bd0d9d5bcd86f1a0344" +dependencies = [ + "icu_normalizer", + "icu_properties", +] + +[[package]] +name = "indexmap" +version = "2.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9" +dependencies = [ + "equivalent", + "hashbrown 0.17.1", + "serde", + "serde_core", +] + +[[package]] +name = "itoa" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" + +[[package]] +name = "js-sys" +version = "0.3.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53b44bfcdb3f8d5837a46dae1ca9660a837176eee74a28b229bc626816589102" +dependencies = [ + "cfg-if", + "futures-util", + "wasm-bindgen", +] + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" +dependencies = [ + "spin", +] + +[[package]] +name = "libc" +version = "0.2.186" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68ab91017fe16c622486840e4c83c9a37afeff978bd239b5293d61ece587de66" + +[[package]] +name = "libm" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6d2cec3eae94f9f509c767b45932f1ada8350c4bdb85af2fcab4a3c14807981" + +[[package]] +name = "libredox" +version = "0.1.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c943259e342f1e06ff2da7a83eabdfe7f92ce10262688dbf1895ff0b3e6e4652" +dependencies = [ + "bitflags", + "libc", + "plain", + "redox_syscall 0.9.0", +] + +[[package]] +name = "libsqlite3-sys" +version = "0.30.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e99fb7a497b1e3339bc746195567ed8d3e24945ecd636e3619d20b9de9e9149" +dependencies = [ + "pkg-config", + "vcpkg", +] + +[[package]] +name = "litemap" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92daf443525c4cce67b150400bc2316076100ce0b3686209eb8cf3c31612e6f0" + +[[package]] +name = "lock_api" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965" +dependencies = [ + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ceec5bc11778974d1bcb055b18002eba7f4b3518b6a0081b3af5f21666da9ad" + +[[package]] +name = "matchers" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1525a2a28c7f4fa0fc98bb91ae755d1e2d1505079e05539e35bc876b5d65ae9" +dependencies = [ + "regex-automata", +] + +[[package]] +name = "matchit" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47e1ffaa40ddd1f3ed91f717a33c8c0ee23fff369e3aa8772b9605cc1d22f4c3" + +[[package]] +name = "md-5" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d89e7ee0cfbedfc4da3340218492196241d89eefb6dab27de5df917a6d2e78cf" +dependencies = [ + "cfg-if", + "digest", +] + +[[package]] +name = "memchr" +version = "2.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "mio" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30d65c71f1ce40ab09135ce117d742b9f8a19ff91a41a8b57ed50bc2de59c427" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.61.2", +] + +[[package]] +name = "nu-ansi-term" +version = "0.50.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "num-bigint-dig" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e661dda6640fad38e827a6d4a310ff4763082116fe217f279885c97f511bb0b7" +dependencies = [ + "lazy_static", + "libm", + "num-integer", + "num-iter", + "num-traits", + "rand", + "smallvec", + "zeroize", +] + +[[package]] +name = "num-integer" +version = "0.1.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-iter" +version = "0.1.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c92800bd69a1eac91786bcfe9da64a897eb72911b8dc3095decbd07429e8048b" +dependencies = [ + "num-integer", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", + "libm", +] + +[[package]] +name = "once_cell" +version = "1.21.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" + +[[package]] +name = "parking" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f38d5652c16fde515bb1ecef450ab0f6a219d619a7274976324d5e377f7dceba" + +[[package]] +name = "parking_lot" +version = "0.12.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93857453250e3077bd71ff98b6a65ea6621a19bb0f559a85248955ac12c45a1a" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall 0.5.18", + "smallvec", + "windows-link", +] + +[[package]] +name = "paste" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" + +[[package]] +name = "pem-rfc7468" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88b39c9bfcfc231068454382784bb460aae594343fb030d46e9f50a645418412" +dependencies = [ + "base64ct", +] + +[[package]] +name = "percent-encoding" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" + +[[package]] +name = "pin-project-lite" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" + +[[package]] +name = "pkcs1" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8ffb9f10fa047879315e6625af03c164b16962a5368d724ed16323b68ace47f" +dependencies = [ + "der", + "pkcs8", + "spki", +] + +[[package]] +name = "pkcs8" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" +dependencies = [ + "der", + "spki", +] + +[[package]] +name = "pkg-config" +version = "0.3.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19f132c84eca552bf34cab8ec81f1c1dcc229b811638f9d283dceabe58c5569e" + +[[package]] +name = "plain" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" + +[[package]] +name = "potential_utf" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0103b1cef7ec0cf76490e969665504990193874ea05c85ff9bab8b911d0a0564" +dependencies = [ + "zerovec", +] + +[[package]] +name = "ppv-lite86" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "proc-macro2" +version = "1.0.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfbc457d0c7a0759a614551b11a6409e5951f6c7537be1f1b7682b9ae9230368" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "r-efi" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" + +[[package]] +name = "rand" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22f6172bdec972074665ed81ed53b71da00bfc44b65a753cfde883ec4c702a1a" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom 0.2.17", +] + +[[package]] +name = "redox_syscall" +version = "0.5.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d" +dependencies = [ + "bitflags", +] + +[[package]] +name = "redox_syscall" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c5102a6aaa05aa011a238e178e6bca86d2cb56fc9f586d37cb80f5bca6e07759" +dependencies = [ + "bitflags", +] + +[[package]] +name = "regex-automata" +version = "0.4.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f388202e4b80542a0921078cc23b6333bcf1409c1e3f86404cae4766a6131db" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6f6ff9a378485b298a5286656da665ba74413d36db0979633275d2e708145d4" + +[[package]] +name = "ring" +version = "0.17.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7" +dependencies = [ + "cc", + "cfg-if", + "getrandom 0.2.17", + "libc", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rsa" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8573f03f5883dcaebdfcf4725caa1ecb9c15b2ef50c43a07b816e06799bb12d" +dependencies = [ + "const-oid", + "digest", + "num-bigint-dig", + "num-integer", + "num-traits", + "pkcs1", + "pkcs8", + "rand_core", + "signature", + "spki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls" +version = "0.23.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c54fcab019b409d04215d3a17cb438fd7fbf192ee61461f20f4fe18704bc138" +dependencies = [ + "once_cell", + "ring", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pki-types" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "764899a24af3980067ee14bc143654f297b22eaebfe3c7b6b211920a5a59b046" +dependencies = [ + "zeroize", +] + +[[package]] +name = "rustls-webpki" +version = "0.103.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61c429a8649f110dddef65e2a5ad240f747e85f7758a6bccc7e5777bd33f756e" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "rustversion" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f" + +[[package]] +name = "ryu" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "serde" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.150" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8014e44b4736ed0538adeecded0fce2a272f22dc9578a7eb6b2d9993c74cfb9" +dependencies = [ + "itoa", + "memchr", + "serde", + "serde_core", + "zmij", +] + +[[package]] +name = "serde_path_to_error" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10a9ff822e371bb5403e391ecd83e182e0e77ba7f6fe0160b795797109d1b457" +dependencies = [ + "itoa", + "serde", + "serde_core", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sha1" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a978451301f4db1d02937a4ab3ccce137717b81826e79b7d49ffe3244a13c3b8" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "sha2" +version = "0.10.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "sharded-slab" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "shlex" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba" + +[[package]] +name = "signal-hook-registry" +version = "1.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4db69cba1110affc0e9f7bcd48bbf87b3f4fc7c61fc9155afd4c469eb3d6c1b" +dependencies = [ + "errno", + "libc", +] + +[[package]] +name = "signature" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" +dependencies = [ + "digest", + "rand_core", +] + +[[package]] +name = "slab" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" + +[[package]] +name = "smallvec" +version = "1.15.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ed6a63f02c8539c91a8685a86f4099661ba3da017932f6ebbea6de3f0fa7c90" +dependencies = [ + "serde", +] + +[[package]] +name = "socket2" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3d1e2c7f27f8d4cb10542a02c49005dbd6e93095799d6f3be745fae9f8fedd4" +dependencies = [ + "libc", + "windows-sys 0.61.2", +] + +[[package]] +name = "spin" +version = "0.9.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3763264f6b73151db08c50ff20d7d8a0b8796e021cdea7ceedad07b80155fa0e" +dependencies = [ + "lock_api", +] + +[[package]] +name = "spki" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" +dependencies = [ + "base64ct", + "der", +] + +[[package]] +name = "sqlx" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fefb893899429669dcdd979aff487bd78f4064e5e7907e4269081e0ef7d97dc" +dependencies = [ + "sqlx-core", + "sqlx-macros", + "sqlx-mysql", + "sqlx-postgres", + "sqlx-sqlite", +] + +[[package]] +name = "sqlx-core" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee6798b1838b6a0f69c007c133b8df5866302197e404e8b6ee8ed3e3a5e68dc6" +dependencies = [ + "base64", + "bytes", + "chrono", + "crc", + "crossbeam-queue", + "either", + "event-listener", + "futures-core", + "futures-intrusive", + "futures-io", + "futures-util", + "hashbrown 0.15.5", + "hashlink", + "indexmap", + "log", + "memchr", + "once_cell", + "percent-encoding", + "rustls", + "serde", + "serde_json", + "sha2", + "smallvec", + "thiserror", + "tokio", + "tokio-stream", + "tracing", + "url", + "uuid", + "webpki-roots 0.26.11", +] + +[[package]] +name = "sqlx-macros" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2d452988ccaacfbf5e0bdbc348fb91d7c8af5bee192173ac3636b5fb6e6715d" +dependencies = [ + "proc-macro2", + "quote", + "sqlx-core", + "sqlx-macros-core", + "syn", +] + +[[package]] +name = "sqlx-macros-core" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19a9c1841124ac5a61741f96e1d9e2ec77424bf323962dd894bdb93f37d5219b" +dependencies = [ + "dotenvy", + "either", + "heck", + "hex", + "once_cell", + "proc-macro2", + "quote", + "serde", + "serde_json", + "sha2", + "sqlx-core", + "sqlx-mysql", + "sqlx-postgres", + "sqlx-sqlite", + "syn", + "tokio", + "url", +] + +[[package]] +name = "sqlx-mysql" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa003f0038df784eb8fecbbac13affe3da23b45194bd57dba231c8f48199c526" +dependencies = [ + "atoi", + "base64", + "bitflags", + "byteorder", + "bytes", + "chrono", + "crc", + "digest", + "dotenvy", + "either", + "futures-channel", + "futures-core", + "futures-io", + "futures-util", + "generic-array", + "hex", + "hkdf", + "hmac", + "itoa", + "log", + "md-5", + "memchr", + "once_cell", + "percent-encoding", + "rand", + "rsa", + "serde", + "sha1", + "sha2", + "smallvec", + "sqlx-core", + "stringprep", + "thiserror", + "tracing", + "uuid", + "whoami", +] + +[[package]] +name = "sqlx-postgres" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db58fcd5a53cf07c184b154801ff91347e4c30d17a3562a635ff028ad5deda46" +dependencies = [ + "atoi", + "base64", + "bitflags", + "byteorder", + "chrono", + "crc", + "dotenvy", + "etcetera", + "futures-channel", + "futures-core", + "futures-util", + "hex", + "hkdf", + "hmac", + "home", + "itoa", + "log", + "md-5", + "memchr", + "once_cell", + "rand", + "serde", + "serde_json", + "sha2", + "smallvec", + "sqlx-core", + "stringprep", + "thiserror", + "tracing", + "uuid", + "whoami", +] + +[[package]] +name = "sqlx-sqlite" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2d12fe70b2c1b4401038055f90f151b78208de1f9f89a7dbfd41587a10c3eea" +dependencies = [ + "atoi", + "chrono", + "flume", + "futures-channel", + "futures-core", + "futures-executor", + "futures-intrusive", + "futures-util", + "libsqlite3-sys", + "log", + "percent-encoding", + "serde", + "serde_urlencoded", + "sqlx-core", + "thiserror", + "tracing", + "url", + "uuid", +] + +[[package]] +name = "stable_deref_trait" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" + +[[package]] +name = "stringprep" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b4df3d392d81bd458a8a621b8bffbd2302a12ffe288a9d931670948749463b1" +dependencies = [ + "unicode-bidi", + "unicode-normalization", + "unicode-properties", +] + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.118" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9ae57f904213ebb649ce6895b8a66c66f0203b9319718f69a5612a065b1422" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263" + +[[package]] +name = "synstructure" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "teaching-feedback-api" +version = "0.1.0" +dependencies = [ + "axum", + "chrono", + "dotenvy", + "serde", + "serde_json", + "sqlx", + "thiserror", + "tokio", + "tower-http", + "tracing", + "tracing-subscriber", + "utoipa", + "utoipa-axum", + "utoipa-scalar", + "uuid", +] + +[[package]] +name = "thiserror" +version = "2.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "thread_local" +version = "1.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ad99c4c6d32803332c548b1af0540b357b3f5fc0be8f6c6bfe8b2e6ae784070" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "tinystr" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8323304221c2a851516f22236c5722a72eaa19749016521d6dff0824447d96d" +dependencies = [ + "displaydoc", + "zerovec", +] + +[[package]] +name = "tinyvec" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb4ebadaa0af04fab11ae01eb5f9fdb5f9c5b875506e210e71c07873528baa7f" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.52.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fc7f01b389ac15039e4dc9531aa973a135d7a4135281b12d7c1bc79fd57fffe" +dependencies = [ + "bytes", + "libc", + "mio", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys 0.61.2", +] + +[[package]] +name = "tokio-macros" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "385a6cb71ab9ab790c5fe8d67f1645e6c450a7ce006a33de03daa956cf70a496" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tokio-stream" +version = "0.1.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32da49809aab5c3bc678af03902d4ccddea2a87d028d86392a4b1560c6906c70" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tower" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebe5ef63511595f1344e2d5cfa636d973292adc0eec1f0ad45fae9f0851ab1d4" +dependencies = [ + "futures-core", + "futures-util", + "pin-project-lite", + "sync_wrapper", + "tokio", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "tower-http" +version = "0.6.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cfcf7e2740e6fc6d4d688b4ef00650406bb94adf4731e43c096c3a19fe40840" +dependencies = [ + "bitflags", + "bytes", + "http", + "http-body", + "pin-project-lite", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "tower-layer" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100" +dependencies = [ + "log", + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tracing-core" +version = "0.1.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a" +dependencies = [ + "once_cell", + "valuable", +] + +[[package]] +name = "tracing-log" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" +dependencies = [ + "log", + "once_cell", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb7f578e5945fb242538965c2d0b04418d38ec25c79d160cd279bf0731c8d319" +dependencies = [ + "matchers", + "nu-ansi-term", + "once_cell", + "regex-automata", + "sharded-slab", + "smallvec", + "thread_local", + "tracing", + "tracing-core", + "tracing-log", +] + +[[package]] +name = "typenum" +version = "1.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20" + +[[package]] +name = "unicode-bidi" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c1cb5db39152898a79168971543b1cb5020dff7fe43c8dc468b0885f5e29df5" + +[[package]] +name = "unicode-ident" +version = "1.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" + +[[package]] +name = "unicode-normalization" +version = "0.1.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fd4f6878c9cb28d874b009da9e8d183b5abc80117c40bbd187a1fde336be6e8" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-properties" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7df058c713841ad818f1dc5d3fd88063241cc61f49f5fbea4b951e8cf5a8d71d" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff67a8a4397373c3ef660812acab3268222035010ab8680ec4215f38ba3d0eed" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", + "serde", +] + +[[package]] +name = "utf8_iter" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" + +[[package]] +name = "utoipa" +version = "5.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bde15df68e80b16c7d16b9616e80770ad158988daa56a27dccd1e55558b0160" +dependencies = [ + "indexmap", + "serde", + "serde_json", + "utoipa-gen", +] + +[[package]] +name = "utoipa-axum" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c25bae5bccc842449ec0c5ddc5cbb6a3a1eaeac4503895dc105a1138f8234a0" +dependencies = [ + "axum", + "paste", + "tower-layer", + "tower-service", + "utoipa", +] + +[[package]] +name = "utoipa-gen" +version = "5.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ba0b99ee52df3028635d93840c797102da61f8a7bb3cf751032455895b52ef8" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "uuid", +] + +[[package]] +name = "utoipa-scalar" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59559e1509172f6b26c1cdbc7247c4ddd1ac6560fe94b584f81ee489b141f719" +dependencies = [ + "axum", + "serde", + "serde_json", + "utoipa", +] + +[[package]] +name = "uuid" +version = "1.23.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea5fab0d6c3c01ae70085a09cb03d4c7a1d6314e2b3e075392783396d724ca0a" +dependencies = [ + "getrandom 0.4.3", + "js-sys", + "serde_core", + "wasm-bindgen", +] + +[[package]] +name = "valuable" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "wasi" +version = "0.11.1+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" + +[[package]] +name = "wasite" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8dad83b4f25e74f184f64c43b150b91efe7647395b42289f38e50566d82855b" + +[[package]] +name = "wasm-bindgen" +version = "0.2.126" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b067c0c11094aef6b7a801c1e34a26affafdf3d051dba08456b868789aaf9a4" +dependencies = [ + "cfg-if", + "once_cell", + "rustversion", + "wasm-bindgen-macro", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.126" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "167ce5e579f6bcf889c4f7175a8a5a585de84e8ff93976ce393efa5f2837aab1" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.126" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3997c7839262f4ef12cf90b818d6340c18e80f263f1a94bf157d0ec4420380e" +dependencies = [ + "bumpalo", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.126" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc1b4cb0cc549fcf58d7dfc081778139b3d283a081644e833e84682ad71cea24" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "webpki-roots" +version = "0.26.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "521bc38abb08001b01866da9f51eb7c5d647a19260e00054a8c7fd5f9e57f7a9" +dependencies = [ + "webpki-roots 1.0.8", +] + +[[package]] +name = "webpki-roots" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf85cb06032201fa7c6f829d7db5a7e5aa45bcc0655327713065f6f0576731bf" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "whoami" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d4a4db5077702ca3015d3d02d74974948aba2ad9e12ab7df718ee64ccd7e97d" +dependencies = [ + "libredox", + "wasite", +] + +[[package]] +name = "windows-core" +version = "0.62.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-link", + "windows-result", + "windows-strings", +] + +[[package]] +name = "windows-implement" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-interface" +version = "0.59.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-link" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" + +[[package]] +name = "windows-result" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-strings" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.61.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "writeable" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ffae5123b2d3fc086436f8834ae3ab053a283cfac8fe0a0b8eaae044768a4c4" + +[[package]] +name = "yoke" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "709fe23a0424b6a435d82152b1bd3fdfb0833487d5fa90d05d42762a9891fef5" +dependencies = [ + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de844c262c8848816172cef550288e7dc6c7b7814b4ee56b3e1553f275f1858e" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + +[[package]] +name = "zerocopy" +version = "0.8.54" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7cbbc0a705a0fd05cc3676525980d2bf5a9bc4adac6d6475209a7887cf59d19" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.8.54" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2e817b7b52d0c7358d3246da9d69935ebb18116b2b102b4230dac079b4862f5" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zerofrom" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ec05a11813ea801ff6d75110ad09cd0824ddba17dfe17128ea0d5f68e6c5272" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11532158c46691caf0f2593ea8358fed6bbf68a0315e80aae9bd41fbade684a1" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + +[[package]] +name = "zeroize" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13c156562582aa81c60cb29407084cdb54c4164760106ab78e6c5b0858cf64e" + +[[package]] +name = "zerotrie" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f9152d31db0792fa83f70fb2f83148effb5c1f5b8c7686c3459e361d9bc20bf" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", +] + +[[package]] +name = "zerovec" +version = "0.11.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90f911cbc359ab6af17377d242225f4d75119aec87ea711a880987b18cd7b239" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "625dc425cab0dca6dc3c3319506e6593dcb08a9f387ea3b284dbd52a92c40555" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zmij" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..b540799 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,23 @@ +[package] +name = "teaching-feedback-api" +version = "0.1.0" +edition = "2024" +rust-version = "1.85" +default-run = "teaching-feedback-api" + +[dependencies] +axum = { version = "0.8", features = ["macros"] } +chrono = { version = "0.4", features = ["serde"] } +dotenvy = "0.15" +serde = { version = "1", features = ["derive"] } +serde_json = "1" +sqlx = { version = "0.8", default-features = false, features = ["runtime-tokio-rustls", "postgres", "chrono", "uuid", "migrate", "macros"] } +thiserror = "2" +tokio = { version = "1", features = ["macros", "rt-multi-thread", "net", "signal"] } +tower-http = { version = "0.6", features = ["cors", "trace"] } +tracing = "0.1" +tracing-subscriber = { version = "0.3", features = ["env-filter"] } +utoipa = { version = "5.5", features = ["chrono", "uuid"] } +utoipa-axum = "0.2" +utoipa-scalar = { version = "0.3", features = ["axum"] } +uuid = { version = "1", features = ["serde", "v4"] } diff --git a/migrations/0001_initial_schema.sql b/migrations/0001_initial_schema.sql new file mode 100644 index 0000000..0bafb6f --- /dev/null +++ b/migrations/0001_initial_schema.sql @@ -0,0 +1,45 @@ +CREATE TABLE student_profiles ( + id UUID PRIMARY KEY, + owner_id UUID NOT NULL, + name VARCHAR(20) NOT NULL CHECK (char_length(btrim(name)) BETWEEN 1 AND 20), + grade VARCHAR(40) NOT NULL CHECK (char_length(btrim(grade)) > 0), + subject VARCHAR(40) NOT NULL CHECK (char_length(btrim(subject)) > 0), + academic_year SMALLINT NOT NULL CHECK (academic_year BETWEEN 2000 AND 2200), + term VARCHAR(1) NOT NULL CHECK (term IN ('春', '暑', '秋', '寒')), + guardian_title VARCHAR(24) NOT NULL CHECK (char_length(btrim(guardian_title)) BETWEEN 1 AND 24), + start_time CHAR(5) NOT NULL, + end_time CHAR(5) NOT NULL, + created_at TIMESTAMPTZ NOT NULL DEFAULT now(), + updated_at TIMESTAMPTZ NOT NULL DEFAULT now() +); + +CREATE INDEX student_profiles_owner_updated_idx + ON student_profiles (owner_id, updated_at DESC); + +CREATE INDEX student_profiles_owner_grade_subject_idx + ON student_profiles (owner_id, grade, subject); + +CREATE TABLE student_profile_defaults ( + owner_id UUID PRIMARY KEY, + grade VARCHAR(40) NOT NULL CHECK (char_length(btrim(grade)) > 0), + subject VARCHAR(40) NOT NULL CHECK (char_length(btrim(subject)) > 0), + lesson_duration_minutes SMALLINT NOT NULL + CHECK (lesson_duration_minutes BETWEEN 15 AND 360 AND lesson_duration_minutes % 15 = 0), + updated_at TIMESTAMPTZ NOT NULL DEFAULT now() +); + +CREATE TABLE feedback_records ( + id UUID PRIMARY KEY, + owner_id UUID NOT NULL, + profile_id UUID REFERENCES student_profiles(id) ON DELETE SET NULL, + feedback_date DATE NOT NULL, + content TEXT NOT NULL CHECK (char_length(btrim(content)) > 0), + created_at TIMESTAMPTZ NOT NULL DEFAULT now(), + updated_at TIMESTAMPTZ NOT NULL DEFAULT now() +); + +CREATE INDEX feedback_records_owner_date_idx + ON feedback_records (owner_id, feedback_date DESC, updated_at DESC); + +CREATE INDEX feedback_records_owner_profile_idx + ON feedback_records (owner_id, profile_id); diff --git a/src/bin/migrate.rs b/src/bin/migrate.rs new file mode 100644 index 0000000..0bad08b --- /dev/null +++ b/src/bin/migrate.rs @@ -0,0 +1,17 @@ +use sqlx::{migrate::Migrator, postgres::PgPoolOptions}; + +static MIGRATOR: Migrator = sqlx::migrate!("./migrations"); + +#[tokio::main] +async fn main() -> Result<(), Box> { + dotenvy::dotenv().ok(); + let database_url = std::env::var("DATABASE_URL") + .map_err(|_| "DATABASE_URL is required before running migrations")?; + let pool = PgPoolOptions::new() + .max_connections(1) + .connect(&database_url) + .await?; + MIGRATOR.run(&pool).await?; + println!("PostgreSQL migrations completed"); + Ok(()) +} diff --git a/src/config.rs b/src/config.rs new file mode 100644 index 0000000..7e34ed0 --- /dev/null +++ b/src/config.rs @@ -0,0 +1,39 @@ +use std::{env, net::IpAddr}; + +#[derive(Debug, Clone)] +pub struct Config { + pub host: IpAddr, + pub port: u16, + pub database_url: Option, + pub database_max_connections: u32, + pub cors_allowed_origin: Option, +} + +impl Config { + pub fn from_env() -> Result { + let host = env::var("HOST") + .unwrap_or_else(|_| "127.0.0.1".to_owned()) + .parse() + .map_err(|_| "HOST must be a valid IP address".to_owned())?; + let port = env::var("PORT") + .unwrap_or_else(|_| "8080".to_owned()) + .parse() + .map_err(|_| "PORT must be a valid u16 value".to_owned())?; + let database_max_connections = env::var("DATABASE_MAX_CONNECTIONS") + .unwrap_or_else(|_| "5".to_owned()) + .parse() + .map_err(|_| "DATABASE_MAX_CONNECTIONS must be a valid u32 value".to_owned())?; + + Ok(Self { + host, + port, + database_url: env::var("DATABASE_URL") + .ok() + .filter(|value| !value.trim().is_empty()), + database_max_connections, + cors_allowed_origin: env::var("CORS_ALLOWED_ORIGIN") + .ok() + .filter(|value| !value.trim().is_empty()), + }) + } +} diff --git a/src/error.rs b/src/error.rs new file mode 100644 index 0000000..2ec8e8d --- /dev/null +++ b/src/error.rs @@ -0,0 +1,93 @@ +use axum::{ + Json, + http::StatusCode, + response::{IntoResponse, Response}, +}; +use serde::Serialize; +use utoipa::{IntoResponses, ToSchema}; + +#[derive(Debug, thiserror::Error)] +pub enum ApiError { + #[error("{0}")] + BadRequest(String), + #[error("authentication is required")] + Unauthorized, + #[error("resource not found")] + NotFound, + #[error("database has not been configured")] + DatabaseUnavailable, + #[error("internal server error")] + Internal, +} + +/// API 错误响应。 +#[derive(Serialize, ToSchema)] +#[schema(example = json!({"error": "resource not found"}))] +pub struct ErrorBody { + /// 面向调用方的错误信息。 + pub error: String, +} + +/// 所有需要数据库和临时用户身份的业务接口都可能返回的公共错误。 +#[allow(dead_code)] +#[derive(IntoResponses)] +pub enum CommonApiErrors { + /// 参数格式或业务校验失败。 + #[response( + status = 400, + description = "请求参数无效", + example = json!({"error": "X-User-Id must be a UUID"}) + )] + BadRequest(ErrorBody), + /// 缺少 `X-User-Id` 请求头。 + #[response( + status = 401, + description = "缺少开发阶段身份请求头", + example = json!({"error": "authentication is required"}) + )] + Unauthorized(ErrorBody), + /// 服务未配置数据库连接。 + #[response( + status = 503, + description = "未配置 DATABASE_URL", + example = json!({"error": "database has not been configured"}) + )] + DatabaseUnavailable(ErrorBody), + /// 数据库查询或服务内部处理失败。 + #[response( + status = 500, + description = "服务内部错误", + example = json!({"error": "internal server error"}) + )] + Internal(ErrorBody), +} + +impl IntoResponse for ApiError { + fn into_response(self) -> Response { + let (status, message) = match self { + Self::BadRequest(message) => (StatusCode::BAD_REQUEST, message), + Self::Unauthorized => ( + StatusCode::UNAUTHORIZED, + "authentication is required".to_owned(), + ), + Self::NotFound => (StatusCode::NOT_FOUND, "resource not found".to_owned()), + Self::DatabaseUnavailable => ( + StatusCode::SERVICE_UNAVAILABLE, + "database has not been configured".to_owned(), + ), + Self::Internal => ( + StatusCode::INTERNAL_SERVER_ERROR, + "internal server error".to_owned(), + ), + }; + + (status, Json(ErrorBody { error: message })).into_response() + } +} + +impl From for ApiError { + fn from(error: sqlx::Error) -> Self { + tracing::error!(?error, "database query failed"); + Self::Internal + } +} diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..6149602 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,80 @@ +mod config; +mod error; +mod routes; + +use std::sync::Arc; + +use axum::{Json, Router, http::HeaderValue, routing::get}; +use config::Config; +use sqlx::{PgPool, postgres::PgPoolOptions}; +use tower_http::{cors::CorsLayer, trace::TraceLayer}; +use tracing_subscriber::EnvFilter; +use utoipa_scalar::{Scalar, Servable}; + +#[derive(Clone)] +pub struct AppState { + pub pool: Option, +} + +#[tokio::main] +async fn main() -> Result<(), Box> { + dotenvy::dotenv().ok(); + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::try_from_default_env().unwrap_or_else(|_| "info".into())) + .init(); + + let config = Config::from_env().map_err(std::io::Error::other)?; + let pool = connect_database(&config).await?; + let app = build_app(AppState { pool }, config.cors_allowed_origin.as_deref())?; + let address = std::net::SocketAddr::from((config.host, config.port)); + let listener = tokio::net::TcpListener::bind(address).await?; + + tracing::info!(%address, scalar = %format!("http://{address}/scalar"), "API server is listening"); + axum::serve(listener, app) + .with_graceful_shutdown(shutdown_signal()) + .await?; + Ok(()) +} + +pub fn build_app(state: AppState, cors_allowed_origin: Option<&str>) -> Result { + let (api_router, openapi) = routes::router(); + let openapi_json = openapi.clone(); + let mut app = api_router + .route( + "/openapi.json", + get(move || { + let openapi = openapi_json.clone(); + async move { Json(openapi) } + }), + ) + .merge(Scalar::with_url("/scalar", openapi)) + .with_state(Arc::new(state)) + .layer(TraceLayer::new_for_http()); + + if let Some(origin) = cors_allowed_origin { + let allowed_origin = HeaderValue::from_str(origin) + .map_err(|_| "CORS_ALLOWED_ORIGIN must be a valid HTTP header value".to_owned())?; + app = app.layer(CorsLayer::new().allow_origin(allowed_origin)); + } + + Ok(app) +} + +async fn connect_database(config: &Config) -> Result, sqlx::Error> { + let Some(database_url) = &config.database_url else { + tracing::warn!("DATABASE_URL is not set; data endpoints will return HTTP 503"); + return Ok(None); + }; + + let pool = PgPoolOptions::new() + .max_connections(config.database_max_connections) + .connect(database_url) + .await?; + tracing::info!("connected to PostgreSQL"); + Ok(Some(pool)) +} + +async fn shutdown_signal() { + let _ = tokio::signal::ctrl_c().await; + tracing::info!("shutdown signal received"); +} diff --git a/src/routes.rs b/src/routes.rs new file mode 100644 index 0000000..4fec9c5 --- /dev/null +++ b/src/routes.rs @@ -0,0 +1,884 @@ +use std::sync::Arc; + +use axum::{ + Json, Router, + extract::{Path, Query, State}, + http::HeaderMap, +}; +use chrono::{DateTime, NaiveDate, NaiveTime, Utc}; +use serde::{Deserialize, Serialize}; +use sqlx::{FromRow, PgPool, Postgres, QueryBuilder, postgres::PgQueryResult}; +use utoipa::{ + ToSchema, + openapi::{Info, OpenApi, Server, Tag}, +}; +use utoipa_axum::{router::OpenApiRouter, routes}; +use uuid::Uuid; + +use crate::{ + AppState, + error::{ApiError, CommonApiErrors, ErrorBody}, +}; + +type SharedState = Arc; + +const DEFAULT_GRADE: &str = "艺术类"; +const DEFAULT_SUBJECT: &str = "美术"; +const DEFAULT_DURATION_MINUTES: i16 = 60; + +pub fn router() -> (Router, OpenApi) { + let (router, mut openapi) = OpenApiRouter::new() + .routes(routes!(health)) + .routes(routes!(list_profiles, create_profile)) + .routes(routes!(get_profile, update_profile, delete_profile)) + .routes(routes!(get_defaults, update_defaults)) + .routes(routes!(list_feedback_records, create_feedback_record)) + .routes(routes!(delete_feedback_record)) + .split_for_parts(); + + let mut info = Info::new("教学反馈助手 API", env!("CARGO_PKG_VERSION")); + info.description = Some( + "学生档案、档案预设和教学反馈记录 API。\n\n\ + 业务接口使用 `X-User-Id` 作为开发阶段身份边界;Scalar 已预填测试 UUID 和请求体示例。" + .to_owned(), + ); + openapi.info = info; + openapi.servers = Some(vec![Server::new("/")]); + openapi.tags = Some(vec![ + api_tag("健康检查", "检查 HTTP 服务状态和数据库是否已配置。"), + api_tag("学生档案", "创建、查询、更新和删除当前用户的学生档案。"), + api_tag("档案预设", "读取或保存当前用户新建档案时使用的默认值。"), + api_tag("反馈记录", "创建、查询和删除当前用户的教学反馈记录。"), + ]); + + (router, openapi) +} + +fn api_tag(name: &str, description: &str) -> Tag { + let mut tag = Tag::new(name); + tag.description = Some(description.to_owned()); + tag +} + +/// 健康检查响应。 +#[derive(Serialize, ToSchema)] +#[schema(example = json!({"status": "ok", "database_configured": true}))] +struct HealthResponse { + /// HTTP 服务状态;正常时固定为 `ok`。 + status: &'static str, + /// 是否已经通过 `DATABASE_URL` 配置数据库连接。 + database_configured: bool, +} + +/// 检查服务状态。 +#[utoipa::path( + get, + path = "/health", + tag = "健康检查", + summary = "健康检查", + description = "不需要身份请求头。返回 HTTP 服务状态,并标记数据库连接是否已配置。", + responses( + (status = 200, description = "服务正在运行", body = HealthResponse) + ) +)] +async fn health(State(state): State) -> Json { + Json(HealthResponse { + status: "ok", + database_configured: state.pool.is_some(), + }) +} + +/// 学生档案。 +#[derive(Debug, Serialize, FromRow, ToSchema)] +#[schema(example = json!({ + "id": "11111111-1111-4111-8111-111111111111", + "name": "小谢", + "grade": "艺术类", + "subject": "美术", + "academic_year": 2026, + "term": "暑", + "guardian_title": "小谢妈妈", + "start_time": "18:00", + "end_time": "19:00", + "created_at": "2026-07-15T10:00:00Z", + "updated_at": "2026-07-15T10:00:00Z" +}))] +struct StudentProfile { + /// 档案 ID。 + id: Uuid, + /// 学生姓名,1 到 20 个字符。 + name: String, + /// 年级或学生类别。 + grade: String, + /// 授课学科。 + subject: String, + /// 学年,范围为 2000 到 2200。 + academic_year: i16, + /// 学期,可选值为春、暑、秋、寒。 + term: String, + /// 家长称呼,1 到 24 个字符。 + guardian_title: String, + /// 上课开始时间,格式为 `HH:MM`。 + start_time: String, + /// 上课结束时间,格式为 `HH:MM`。 + end_time: String, + /// 创建时间,UTC。 + created_at: DateTime, + /// 最近更新时间,UTC。 + updated_at: DateTime, +} + +/// 创建或完整更新学生档案的请求体。 +#[derive(Debug, Deserialize, ToSchema)] +#[schema(example = json!({ + "name": "小谢", + "grade": "艺术类", + "subject": "美术", + "academic_year": 2026, + "term": "暑", + "guardian_title": "小谢妈妈", + "start_time": "18:00", + "end_time": "19:00" +}))] +struct ProfileInput { + /// 学生姓名,1 到 20 个字符。 + name: String, + /// 年级或学生类别,不可为空。 + grade: String, + /// 授课学科,不可为空。 + subject: String, + /// 学年,范围为 2000 到 2200。 + academic_year: i16, + /// 学期,可选值为春、暑、秋、寒。 + term: String, + /// 家长称呼,1 到 24 个字符。 + guardian_title: String, + /// 上课开始时间,格式为 `HH:MM`。 + start_time: String, + /// 上课结束时间,格式为 `HH:MM`。 + end_time: String, +} + +#[derive(Debug, Deserialize)] +struct ProfileQuery { + query: Option, + grade: Option, + subject: Option, +} + +/// 列出当前用户的学生档案。 +#[utoipa::path( + get, + path = "/api/v1/profiles", + tag = "学生档案", + summary = "列出学生档案", + description = "按最近更新时间倒序返回当前用户的档案。三个查询条件均可省略,也可以组合使用。", + params( + ("X-User-Id" = Uuid, Header, description = "开发阶段用户 ID;Scalar 已预填测试值", example = json!("5a4da7f0-d70c-465f-bcab-124c504aa9f0")), + ("query" = Option, Query, description = "模糊匹配姓名、年级、学科或家长称呼", example = "小谢"), + ("grade" = Option, Query, description = "精确匹配年级或学生类别", example = "艺术类"), + ("subject" = Option, Query, description = "精确匹配学科", example = "美术") + ), + responses( + (status = 200, description = "学生档案列表", body = [StudentProfile]), + CommonApiErrors + ) +)] +async fn list_profiles( + State(state): State, + headers: HeaderMap, + Query(query): Query, +) -> Result>, ApiError> { + let owner_id = current_user(&headers)?; + let pool = pool(&state)?; + let mut statement = QueryBuilder::::new( + "SELECT id, name, grade, subject, academic_year, term, guardian_title, start_time, end_time, created_at, updated_at \ + FROM student_profiles WHERE owner_id = ", + ); + statement.push_bind(owner_id); + + if let Some(grade) = query.grade.filter(|value| !value.trim().is_empty()) { + statement.push(" AND grade = "); + statement.push_bind(grade.trim().to_owned()); + } + if let Some(subject) = query.subject.filter(|value| !value.trim().is_empty()) { + statement.push(" AND subject = "); + statement.push_bind(subject.trim().to_owned()); + } + if let Some(keyword) = query.query.filter(|value| !value.trim().is_empty()) { + let pattern = format!("%{}%", keyword.trim()); + statement.push(" AND (name ILIKE "); + statement.push_bind(pattern.clone()); + statement.push(" OR grade ILIKE "); + statement.push_bind(pattern.clone()); + statement.push(" OR subject ILIKE "); + statement.push_bind(pattern.clone()); + statement.push(" OR guardian_title ILIKE "); + statement.push_bind(pattern); + statement.push(")"); + } + + statement.push(" ORDER BY updated_at DESC"); + let profiles = statement + .build_query_as::() + .fetch_all(pool) + .await?; + Ok(Json(profiles)) +} + +/// 读取当前用户的单个学生档案。 +#[utoipa::path( + get, + path = "/api/v1/profiles/{profile_id}", + tag = "学生档案", + summary = "读取学生档案", + description = "只允许读取属于当前 `X-User-Id` 的档案。请先从创建或列表接口复制真实的档案 ID。", + params( + ("X-User-Id" = Uuid, Header, description = "开发阶段用户 ID;必须与档案所属用户一致", example = json!("5a4da7f0-d70c-465f-bcab-124c504aa9f0")), + ("profile_id" = Uuid, Path, description = "学生档案 ID;将示例值替换为创建接口返回的 ID", example = json!("11111111-1111-4111-8111-111111111111")) + ), + responses( + (status = 200, description = "学生档案", body = StudentProfile), + (status = 404, description = "档案不存在或不属于当前用户", body = ErrorBody, example = json!({"error": "resource not found"})), + CommonApiErrors + ) +)] +async fn get_profile( + State(state): State, + headers: HeaderMap, + Path(profile_id): Path, +) -> Result, ApiError> { + let owner_id = current_user(&headers)?; + let profile = sqlx::query_as::<_, StudentProfile>( + "SELECT id, name, grade, subject, academic_year, term, guardian_title, start_time, end_time, created_at, updated_at \ + FROM student_profiles WHERE id = $1 AND owner_id = $2", + ) + .bind(profile_id) + .bind(owner_id) + .fetch_optional(pool(&state)?) + .await? + .ok_or(ApiError::NotFound)?; + Ok(Json(profile)) +} + +/// 创建学生档案。 +#[utoipa::path( + post, + path = "/api/v1/profiles", + tag = "学生档案", + summary = "创建学生档案", + description = "使用请求头中的用户 ID 创建档案。Scalar 已预填完整请求体,可以直接执行测试。", + params( + ("X-User-Id" = Uuid, Header, description = "开发阶段用户 ID;Scalar 已预填测试值", example = json!("5a4da7f0-d70c-465f-bcab-124c504aa9f0")) + ), + request_body( + content = ProfileInput, + description = "学生档案内容", + content_type = "application/json", + example = json!({ + "name": "小谢", + "grade": "艺术类", + "subject": "美术", + "academic_year": 2026, + "term": "暑", + "guardian_title": "小谢妈妈", + "start_time": "18:00", + "end_time": "19:00" + }) + ), + responses( + (status = 201, description = "档案创建成功", body = StudentProfile), + CommonApiErrors + ) +)] +async fn create_profile( + State(state): State, + headers: HeaderMap, + Json(input): Json, +) -> Result<(axum::http::StatusCode, Json), ApiError> { + validate_profile(&input)?; + let owner_id = current_user(&headers)?; + let profile = sqlx::query_as::<_, StudentProfile>( + "INSERT INTO student_profiles \ + (id, owner_id, name, grade, subject, academic_year, term, guardian_title, start_time, end_time) \ + VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) \ + RETURNING id, name, grade, subject, academic_year, term, guardian_title, start_time, end_time, created_at, updated_at", + ) + .bind(Uuid::new_v4()) + .bind(owner_id) + .bind(input.name.trim()) + .bind(input.grade.trim()) + .bind(input.subject.trim()) + .bind(input.academic_year) + .bind(input.term.trim()) + .bind(input.guardian_title.trim()) + .bind(input.start_time.trim()) + .bind(input.end_time.trim()) + .fetch_one(pool(&state)?) + .await?; + Ok((axum::http::StatusCode::CREATED, Json(profile))) +} + +/// 完整更新学生档案。 +#[utoipa::path( + put, + path = "/api/v1/profiles/{profile_id}", + tag = "学生档案", + summary = "更新学生档案", + description = "完整替换指定档案的可编辑字段。请先从创建或列表接口复制真实的档案 ID。", + params( + ("X-User-Id" = Uuid, Header, description = "开发阶段用户 ID;必须与档案所属用户一致", example = json!("5a4da7f0-d70c-465f-bcab-124c504aa9f0")), + ("profile_id" = Uuid, Path, description = "学生档案 ID;将示例值替换为创建接口返回的 ID", example = json!("11111111-1111-4111-8111-111111111111")) + ), + request_body( + content = ProfileInput, + description = "更新后的完整档案内容", + content_type = "application/json", + example = json!({ + "name": "小谢", + "grade": "艺术类", + "subject": "美术", + "academic_year": 2026, + "term": "暑", + "guardian_title": "小谢妈妈", + "start_time": "18:00", + "end_time": "19:00" + }) + ), + responses( + (status = 200, description = "更新后的学生档案", body = StudentProfile), + (status = 404, description = "档案不存在或不属于当前用户", body = ErrorBody, example = json!({"error": "resource not found"})), + CommonApiErrors + ) +)] +async fn update_profile( + State(state): State, + headers: HeaderMap, + Path(profile_id): Path, + Json(input): Json, +) -> Result, ApiError> { + validate_profile(&input)?; + let owner_id = current_user(&headers)?; + let profile = sqlx::query_as::<_, StudentProfile>( + "UPDATE student_profiles \ + SET name = $1, grade = $2, subject = $3, academic_year = $4, term = $5, guardian_title = $6, \ + start_time = $7, end_time = $8, updated_at = now() \ + WHERE id = $9 AND owner_id = $10 \ + RETURNING id, name, grade, subject, academic_year, term, guardian_title, start_time, end_time, created_at, updated_at", + ) + .bind(input.name.trim()) + .bind(input.grade.trim()) + .bind(input.subject.trim()) + .bind(input.academic_year) + .bind(input.term.trim()) + .bind(input.guardian_title.trim()) + .bind(input.start_time.trim()) + .bind(input.end_time.trim()) + .bind(profile_id) + .bind(owner_id) + .fetch_optional(pool(&state)?) + .await? + .ok_or(ApiError::NotFound)?; + Ok(Json(profile)) +} + +/// 删除学生档案。 +#[utoipa::path( + delete, + path = "/api/v1/profiles/{profile_id}", + tag = "学生档案", + summary = "删除学生档案", + description = "删除属于当前用户的档案。关联反馈记录不会被删除,其 `profile_id` 会被置空。", + params( + ("X-User-Id" = Uuid, Header, description = "开发阶段用户 ID;必须与档案所属用户一致", example = json!("5a4da7f0-d70c-465f-bcab-124c504aa9f0")), + ("profile_id" = Uuid, Path, description = "学生档案 ID;将示例值替换为创建接口返回的 ID", example = json!("11111111-1111-4111-8111-111111111111")) + ), + responses( + (status = 204, description = "档案已删除"), + (status = 404, description = "档案不存在或不属于当前用户", body = ErrorBody, example = json!({"error": "resource not found"})), + CommonApiErrors + ) +)] +async fn delete_profile( + State(state): State, + headers: HeaderMap, + Path(profile_id): Path, +) -> Result { + let owner_id = current_user(&headers)?; + let result = sqlx::query("DELETE FROM student_profiles WHERE id = $1 AND owner_id = $2") + .bind(profile_id) + .bind(owner_id) + .execute(pool(&state)?) + .await?; + affected_or_not_found(result)?; + Ok(axum::http::StatusCode::NO_CONTENT) +} + +/// 当前用户的新建档案预设。 +#[derive(Debug, Serialize, FromRow, ToSchema)] +#[schema(example = json!({ + "grade": "艺术类", + "subject": "美术", + "lesson_duration_minutes": 60, + "updated_at": "2026-07-15T10:00:00Z" +}))] +struct ProfileDefaults { + /// 默认年级或学生类别。 + grade: String, + /// 默认授课学科。 + subject: String, + /// 默认课程时长,必须为 15 到 360 之间的 15 的倍数。 + lesson_duration_minutes: i16, + /// 最近更新时间,UTC;未保存过预设时为本次请求时间。 + updated_at: DateTime, +} + +/// 保存档案预设的请求体。 +#[derive(Debug, Deserialize, ToSchema)] +#[schema(example = json!({ + "grade": "艺术类", + "subject": "美术", + "lesson_duration_minutes": 60 +}))] +struct ProfileDefaultsInput { + /// 默认年级或学生类别,不可为空。 + grade: String, + /// 默认授课学科,不可为空。 + subject: String, + /// 默认课程时长,必须为 15 到 360 之间的 15 的倍数。 + lesson_duration_minutes: i16, +} + +/// 读取当前用户的新建档案预设。 +#[utoipa::path( + get, + path = "/api/v1/profile-defaults", + tag = "档案预设", + summary = "读取档案预设", + description = "读取当前用户的预设;尚未保存时直接返回艺术类、美术、60 分钟的系统默认值。", + params( + ("X-User-Id" = Uuid, Header, description = "开发阶段用户 ID;Scalar 已预填测试值", example = json!("5a4da7f0-d70c-465f-bcab-124c504aa9f0")) + ), + responses( + (status = 200, description = "当前档案预设", body = ProfileDefaults), + CommonApiErrors + ) +)] +async fn get_defaults( + State(state): State, + headers: HeaderMap, +) -> Result, ApiError> { + let owner_id = current_user(&headers)?; + let defaults = sqlx::query_as::<_, ProfileDefaults>( + "SELECT grade, subject, lesson_duration_minutes, updated_at \ + FROM student_profile_defaults WHERE owner_id = $1", + ) + .bind(owner_id) + .fetch_optional(pool(&state)?) + .await?; + + Ok(Json(defaults.unwrap_or_else(default_profile_defaults))) +} + +/// 保存当前用户的新建档案预设。 +#[utoipa::path( + put, + path = "/api/v1/profile-defaults", + tag = "档案预设", + summary = "保存档案预设", + description = "新增或覆盖当前用户的档案预设。Scalar 已预填完整请求体,可以直接执行测试。", + params( + ("X-User-Id" = Uuid, Header, description = "开发阶段用户 ID;Scalar 已预填测试值", example = json!("5a4da7f0-d70c-465f-bcab-124c504aa9f0")) + ), + request_body( + content = ProfileDefaultsInput, + description = "要保存的档案预设", + content_type = "application/json", + example = json!({ + "grade": "艺术类", + "subject": "美术", + "lesson_duration_minutes": 60 + }) + ), + responses( + (status = 200, description = "保存后的档案预设", body = ProfileDefaults), + CommonApiErrors + ) +)] +async fn update_defaults( + State(state): State, + headers: HeaderMap, + Json(input): Json, +) -> Result, ApiError> { + validate_defaults(&input)?; + let owner_id = current_user(&headers)?; + let defaults = sqlx::query_as::<_, ProfileDefaults>( + "INSERT INTO student_profile_defaults (owner_id, grade, subject, lesson_duration_minutes) \ + VALUES ($1, $2, $3, $4) \ + ON CONFLICT (owner_id) DO UPDATE SET \ + grade = EXCLUDED.grade, \ + subject = EXCLUDED.subject, \ + lesson_duration_minutes = EXCLUDED.lesson_duration_minutes, \ + updated_at = now() \ + RETURNING grade, subject, lesson_duration_minutes, updated_at", + ) + .bind(owner_id) + .bind(input.grade.trim()) + .bind(input.subject.trim()) + .bind(input.lesson_duration_minutes) + .fetch_one(pool(&state)?) + .await?; + Ok(Json(defaults)) +} + +/// 教学反馈记录。 +#[derive(Debug, Serialize, FromRow, ToSchema)] +#[schema(example = json!({ + "id": "22222222-2222-4222-8222-222222222222", + "profile_id": null, + "feedback_date": "2026-07-15", + "content": "今天完成了色彩搭配练习,构图有明显进步。", + "created_at": "2026-07-15T10:00:00Z", + "updated_at": "2026-07-15T10:00:00Z" +}))] +struct FeedbackRecord { + /// 反馈记录 ID。 + id: Uuid, + /// 关联的学生档案 ID;可以为空。 + profile_id: Option, + /// 反馈对应日期,格式为 `YYYY-MM-DD`。 + feedback_date: NaiveDate, + /// 教学反馈正文。 + content: String, + /// 创建时间,UTC。 + created_at: DateTime, + /// 最近更新时间,UTC。 + updated_at: DateTime, +} + +/// 创建教学反馈记录的请求体。 +#[derive(Debug, Deserialize, ToSchema)] +#[schema(example = json!({ + "profile_id": null, + "feedback_date": "2026-07-15", + "content": "今天完成了色彩搭配练习,构图有明显进步。" +}))] +struct FeedbackRecordInput { + /// 可选的学生档案 ID;如填写,必须属于当前用户。Scalar 默认留空以便直接测试。 + profile_id: Option, + /// 反馈对应日期,格式为 `YYYY-MM-DD`。 + feedback_date: NaiveDate, + /// 教学反馈正文,不可为空。 + content: String, +} + +#[derive(Debug, Deserialize)] +struct FeedbackRecordQuery { + profile_id: Option, +} + +/// 列出当前用户的教学反馈记录。 +#[utoipa::path( + get, + path = "/api/v1/feedback-records", + tag = "反馈记录", + summary = "列出反馈记录", + description = "按反馈日期和更新时间倒序返回当前用户的记录;可按学生档案 ID 筛选。", + params( + ("X-User-Id" = Uuid, Header, description = "开发阶段用户 ID;Scalar 已预填测试值", example = json!("5a4da7f0-d70c-465f-bcab-124c504aa9f0")), + ("profile_id" = Option, Query, description = "只返回关联到指定档案的记录;直接测试时可留空", example = json!("11111111-1111-4111-8111-111111111111")) + ), + responses( + (status = 200, description = "教学反馈记录列表", body = [FeedbackRecord]), + CommonApiErrors + ) +)] +async fn list_feedback_records( + State(state): State, + headers: HeaderMap, + Query(query): Query, +) -> Result>, ApiError> { + let owner_id = current_user(&headers)?; + let pool = pool(&state)?; + let mut statement = QueryBuilder::::new( + "SELECT id, profile_id, feedback_date, content, created_at, updated_at \ + FROM feedback_records WHERE owner_id = ", + ); + statement.push_bind(owner_id); + if let Some(profile_id) = query.profile_id { + statement.push(" AND profile_id = "); + statement.push_bind(profile_id); + } + statement.push(" ORDER BY feedback_date DESC, updated_at DESC"); + let records = statement + .build_query_as::() + .fetch_all(pool) + .await?; + Ok(Json(records)) +} + +/// 创建教学反馈记录。 +#[utoipa::path( + post, + path = "/api/v1/feedback-records", + tag = "反馈记录", + summary = "创建反馈记录", + description = "创建一条教学反馈。Scalar 默认将 `profile_id` 设为 null,因此无需先创建档案即可直接测试。", + params( + ("X-User-Id" = Uuid, Header, description = "开发阶段用户 ID;Scalar 已预填测试值", example = json!("5a4da7f0-d70c-465f-bcab-124c504aa9f0")) + ), + request_body( + content = FeedbackRecordInput, + description = "教学反馈内容", + content_type = "application/json", + example = json!({ + "profile_id": null, + "feedback_date": "2026-07-15", + "content": "今天完成了色彩搭配练习,构图有明显进步。" + }) + ), + responses( + (status = 201, description = "反馈记录创建成功", body = FeedbackRecord), + (status = 404, description = "指定的学生档案不存在或不属于当前用户", body = ErrorBody, example = json!({"error": "resource not found"})), + CommonApiErrors + ) +)] +async fn create_feedback_record( + State(state): State, + headers: HeaderMap, + Json(input): Json, +) -> Result<(axum::http::StatusCode, Json), ApiError> { + if input.content.trim().is_empty() { + return Err(ApiError::BadRequest("content cannot be empty".to_owned())); + } + let owner_id = current_user(&headers)?; + if let Some(profile_id) = input.profile_id { + assert_profile_owner(pool(&state)?, owner_id, profile_id).await?; + } + let record = sqlx::query_as::<_, FeedbackRecord>( + "INSERT INTO feedback_records (id, owner_id, profile_id, feedback_date, content) \ + VALUES ($1, $2, $3, $4, $5) \ + RETURNING id, profile_id, feedback_date, content, created_at, updated_at", + ) + .bind(Uuid::new_v4()) + .bind(owner_id) + .bind(input.profile_id) + .bind(input.feedback_date) + .bind(input.content.trim()) + .fetch_one(pool(&state)?) + .await?; + Ok((axum::http::StatusCode::CREATED, Json(record))) +} + +/// 删除教学反馈记录。 +#[utoipa::path( + delete, + path = "/api/v1/feedback-records/{record_id}", + tag = "反馈记录", + summary = "删除反馈记录", + description = "删除属于当前用户的反馈记录。请先从创建或列表接口复制真实的记录 ID。", + params( + ("X-User-Id" = Uuid, Header, description = "开发阶段用户 ID;必须与记录所属用户一致", example = json!("5a4da7f0-d70c-465f-bcab-124c504aa9f0")), + ("record_id" = Uuid, Path, description = "反馈记录 ID;将示例值替换为创建接口返回的 ID", example = json!("22222222-2222-4222-8222-222222222222")) + ), + responses( + (status = 204, description = "反馈记录已删除"), + (status = 404, description = "记录不存在或不属于当前用户", body = ErrorBody, example = json!({"error": "resource not found"})), + CommonApiErrors + ) +)] +async fn delete_feedback_record( + State(state): State, + headers: HeaderMap, + Path(record_id): Path, +) -> Result { + let owner_id = current_user(&headers)?; + let result = sqlx::query("DELETE FROM feedback_records WHERE id = $1 AND owner_id = $2") + .bind(record_id) + .bind(owner_id) + .execute(pool(&state)?) + .await?; + affected_or_not_found(result)?; + Ok(axum::http::StatusCode::NO_CONTENT) +} + +fn current_user(headers: &HeaderMap) -> Result { + let value = headers + .get("x-user-id") + .and_then(|header| header.to_str().ok()) + .ok_or(ApiError::Unauthorized)?; + Uuid::parse_str(value).map_err(|_| ApiError::BadRequest("X-User-Id must be a UUID".to_owned())) +} + +fn pool(state: &AppState) -> Result<&PgPool, ApiError> { + state.pool.as_ref().ok_or(ApiError::DatabaseUnavailable) +} + +fn validate_profile(input: &ProfileInput) -> Result<(), ApiError> { + if input.name.trim().is_empty() || input.name.trim().chars().count() > 20 { + return Err(ApiError::BadRequest( + "name must contain 1 to 20 characters".to_owned(), + )); + } + if input.grade.trim().is_empty() || input.subject.trim().is_empty() { + return Err(ApiError::BadRequest( + "grade and subject are required".to_owned(), + )); + } + if !(2000..=2200).contains(&input.academic_year) { + return Err(ApiError::BadRequest( + "academic_year must be between 2000 and 2200".to_owned(), + )); + } + if !matches!(input.term.as_str(), "春" | "暑" | "秋" | "寒") { + return Err(ApiError::BadRequest( + "term must be 春, 暑, 秋, or 寒".to_owned(), + )); + } + if input.guardian_title.trim().is_empty() || input.guardian_title.trim().chars().count() > 24 { + return Err(ApiError::BadRequest( + "guardian_title must contain 1 to 24 characters".to_owned(), + )); + } + validate_time(&input.start_time, "start_time")?; + validate_time(&input.end_time, "end_time") +} + +fn validate_defaults(input: &ProfileDefaultsInput) -> Result<(), ApiError> { + if input.grade.trim().is_empty() || input.subject.trim().is_empty() { + return Err(ApiError::BadRequest( + "grade and subject are required".to_owned(), + )); + } + if !(15..=360).contains(&input.lesson_duration_minutes) + || input.lesson_duration_minutes % 15 != 0 + { + return Err(ApiError::BadRequest( + "lesson_duration_minutes must be a multiple of 15 between 15 and 360".to_owned(), + )); + } + Ok(()) +} + +fn validate_time(value: &str, field: &str) -> Result<(), ApiError> { + NaiveTime::parse_from_str(value, "%H:%M") + .map(|_| ()) + .map_err(|_| ApiError::BadRequest(format!("{field} must use HH:MM format"))) +} + +fn default_profile_defaults() -> ProfileDefaults { + ProfileDefaults { + grade: DEFAULT_GRADE.to_owned(), + subject: DEFAULT_SUBJECT.to_owned(), + lesson_duration_minutes: DEFAULT_DURATION_MINUTES, + updated_at: Utc::now(), + } +} + +fn affected_or_not_found(result: PgQueryResult) -> Result<(), ApiError> { + if result.rows_affected() == 0 { + return Err(ApiError::NotFound); + } + Ok(()) +} + +async fn assert_profile_owner( + pool: &PgPool, + owner_id: Uuid, + profile_id: Uuid, +) -> Result<(), ApiError> { + let exists = sqlx::query_scalar::<_, bool>( + "SELECT EXISTS(SELECT 1 FROM student_profiles WHERE id = $1 AND owner_id = $2)", + ) + .bind(profile_id) + .bind(owner_id) + .fetch_one(pool) + .await?; + if exists { + Ok(()) + } else { + Err(ApiError::NotFound) + } +} + +#[cfg(test)] +mod tests { + use serde_json::Value; + + use super::router; + + const TEST_USER_ID: &str = "5a4da7f0-d70c-465f-bcab-124c504aa9f0"; + + #[test] + fn openapi_documents_all_routes_and_default_test_data() { + let (_, openapi) = router(); + let document = serde_json::to_value(openapi).expect("OpenAPI should serialize"); + let paths = document["paths"] + .as_object() + .expect("OpenAPI should contain paths"); + + let operations = paths + .values() + .flat_map(|path| { + path.as_object() + .expect("path item should be an object") + .values() + }) + .filter(|operation| operation.get("responses").is_some()) + .collect::>(); + + assert_eq!(operations.len(), 11); + for operation in &operations { + assert_non_empty(operation, "summary"); + assert_non_empty(operation, "description"); + } + + let request_examples = operations + .iter() + .filter_map(|operation| { + operation.pointer("/requestBody/content/application~1json/example") + }) + .collect::>(); + assert_eq!(request_examples.len(), 4); + assert!(request_examples.iter().all(|example| example.is_object())); + + let business_operations = paths + .iter() + .filter(|(path, _)| path.starts_with("/api/v1/")) + .flat_map(|(_, path)| { + path.as_object() + .expect("path item should be an object") + .values() + }) + .filter(|operation| operation.get("responses").is_some()); + + for operation in business_operations { + let user_header = operation["parameters"] + .as_array() + .expect("business operation should have parameters") + .iter() + .find(|parameter| parameter["name"] == "X-User-Id" && parameter["in"] == "header") + .expect("business operation should document X-User-Id"); + assert_eq!(user_header["example"], TEST_USER_ID); + } + + assert_eq!(document["servers"][0]["url"], "/"); + assert!(document["info"].get("contact").is_none()); + assert!(document["info"].get("license").is_none()); + assert!(document["components"]["schemas"]["ProfileInput"]["example"].is_object()); + assert!(document["components"]["schemas"]["ProfileDefaultsInput"]["example"].is_object()); + assert!( + document["components"]["schemas"]["FeedbackRecordInput"]["example"]["profile_id"] + .is_null() + ); + } + + fn assert_non_empty(operation: &Value, field: &str) { + assert!( + operation[field] + .as_str() + .is_some_and(|value| !value.trim().is_empty()), + "operation should have a non-empty {field}" + ); + } +}