You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
1.8 KiB
Markdown
68 lines
1.8 KiB
Markdown
+++
|
|
title = "quotesdb/api: enforce submission lock on PUT /api/quotes"
|
|
priority = 6
|
|
status = "done"
|
|
ticket_type = "feature"
|
|
dependencies = ["69a2c5"]
|
|
+++
|
|
## Enforce submission lock on PUT /api/quotes
|
|
|
|
Modify the quote-creation handler to check the submissions lock before accepting a new quote. If locked, return `423 Locked` with a JSON error body.
|
|
|
|
Note: This ticket depends on ticket 35685a (GET /api/status) because that ticket adds `get_submissions_locked` to the `QuoteRepository` trait. Complete 35685a first.
|
|
|
|
---
|
|
|
|
## Files to modify
|
|
|
|
- `src/bin/api/handlers/mod.rs` — modify the `create_quote` handler (the handler for `PUT /api/quotes`) to add a lock pre-flight check
|
|
|
|
No new DB methods, routes, or types are needed.
|
|
|
|
---
|
|
|
|
## Change to create_quote handler
|
|
|
|
At the top of the handler body, before any other logic, add:
|
|
|
|
```rust
|
|
// Pre-flight: reject new submissions when locked.
|
|
match repo.get_submissions_locked().await {
|
|
Ok(true) => {
|
|
return (
|
|
StatusCode::LOCKED,
|
|
Json(json!({ "error": "submissions are closed" })),
|
|
).into_response();
|
|
}
|
|
Ok(false) => {}
|
|
Err(_) => return StatusCode::INTERNAL_SERVER_ERROR.into_response(),
|
|
}
|
|
```
|
|
|
|
HTTP 423 is `StatusCode::LOCKED` in axum/hyper.
|
|
|
|
---
|
|
|
|
## Tests
|
|
|
|
- `PUT /api/quotes` while `submissions_locked = false` → `201` (existing behaviour unchanged)
|
|
- `PUT /api/quotes` while `submissions_locked = true` → `423` with body `{ "error": "submissions are closed" }`
|
|
- After unlocking (`submissions_locked = false`), `PUT /api/quotes` succeeds again → `201`
|
|
|
|
Use the in-memory/mock repo already used by other handler tests; expose a method to toggle the lock state on the test double.
|
|
|
|
---
|
|
|
|
## Validation
|
|
|
|
```sh
|
|
cargo fmt && cargo check && cargo clippy && cargo test
|
|
```
|
|
|
|
---
|
|
|
|
## Commit
|
|
|
|
```
|
|
feat(quotesdb): enforce submission lock on PUT /api/quotes
|
|
``` |