···99 list_repos_by_collection::{ListReposByCollectionOutput, ListReposByCollectionRequest, Repo},
1010};
1111use jacquard_axum::ExtractXrpc;
1212-use jacquard_common::types::string::Did;
1212+use jacquard_common::{CowStr, types::string::Did};
13131414-use crate::storage::DbRef;
1414+use crate::storage::{DbRef, repo::AccountStatus};
15151616/// Handler for `GET /xrpc/com.atproto.sync.listReposByCollection`.
1717///
···66666767/// Handler for `GET /xrpc/com.atproto.sync.getRepoStatus`.
6868///
6969-/// Looks up the per-repo state from `db::repo::get` and returns whether the
7070-/// repo is active. Returns a `RepoNotFound` XRPC error (404) if the DID has
7171-/// never been indexed.
6969+/// Returns the active/status of the given repo. Returns 404 (XRPC RepoNotFound)
7070+/// if the DID has never been indexed.
7171+///
7272+/// `active` reflects whether the account is usable. `status` carries the
7373+/// reason when inactive ("takendown", "suspended", "deactivated", "deleted").
7474+/// `rev` is currently omitted (TODO: store latest rev in RepoRecord).
7575+///
7676+/// TODO: 400 xrpc-compatible error instead of 404
7777+/// jacquard-axum seems slightly limiting here atm
7278pub async fn get_repo_status(
7373- State(_db): State<DbRef>,
7474- ExtractXrpc(_req): ExtractXrpc<GetRepoStatusRequest>,
7979+ State(db): State<DbRef>,
8080+ ExtractXrpc(req): ExtractXrpc<GetRepoStatusRequest>,
7581) -> Result<Json<GetRepoStatusOutput<'static>>, StatusCode> {
7676- // req.did — Did<'static>
7777- todo!("look up RepoRecord in db and return active/status")
8282+ let record = crate::storage::repo::get(&db, &req.did)
8383+ .map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?
8484+ .ok_or(StatusCode::NOT_FOUND)?;
8585+8686+ let active = matches!(record.status, AccountStatus::Active);
8787+ let status: Option<CowStr<'static>> = match record.status {
8888+ AccountStatus::Active => None,
8989+ s => Some(s.as_str().to_owned().into()),
9090+ };
9191+9292+ Ok(Json(GetRepoStatusOutput {
9393+ active,
9494+ did: req.did,
9595+ rev: None, // TODO: store and return the latest rev from RepoRecord
9696+ status,
9797+ extra_data: None,
9898+ }))
7899}