feat(server): add me endpoint (#1954)

This commit is contained in:
Ellie Huxtable 2024-04-16 15:59:11 +01:00 committed by GitHub
parent a0231a7095
commit 19f70cdc91
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 26 additions and 2 deletions

View File

@ -115,3 +115,8 @@ pub struct DeleteHistoryRequest {
pub struct MessageResponse {
pub message: String,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct MeResponse {
pub username: String,
}

View File

@ -0,0 +1,16 @@
use axum::Json;
use tracing::instrument;
use crate::handlers::ErrorResponseStatus;
use crate::router::UserAuth;
use atuin_common::api::*;
#[instrument(skip_all, fields(user.id = user.id))]
pub async fn get(
UserAuth(user): UserAuth,
) -> Result<Json<MeResponse>, ErrorResponseStatus<'static>> {
Ok(Json(MeResponse {
username: user.username,
}))
}

View File

@ -1,2 +1,3 @@
pub(crate) mod me;
pub(crate) mod record;
pub(crate) mod store;

View File

@ -125,6 +125,7 @@ pub fn router<DB: Database>(database: DB, settings: Settings<DB::Settings>) -> R
.route("/record", post(handlers::record::post::<DB>))
.route("/record", get(handlers::record::index::<DB>))
.route("/record/next", get(handlers::record::next))
.route("/api/v0/me", get(handlers::v0::me::get))
.route("/api/v0/record", post(handlers::v0::record::post))
.route("/api/v0/record", get(handlers::v0::record::index))
.route("/api/v0/record/next", get(handlers::v0::record::next))

View File

@ -23,8 +23,6 @@ pub async fn run(settings: &Settings, db: &impl Database) -> Result<()> {
let status = client.status().await?;
let last_sync = Settings::last_sync()?;
let local_count = db.history_count(false).await?;
let deleted_count = db.history_count(true).await? - local_count;
println!("Atuin v{VERSION} - Build rev {SHA}\n");
@ -36,6 +34,9 @@ pub async fn run(settings: &Settings, db: &impl Database) -> Result<()> {
}
if !settings.sync.records {
let local_count = db.history_count(false).await?;
let deleted_count = db.history_count(true).await? - local_count;
println!("History count: {local_count}");
println!("Deleted history count: {deleted_count}\n");
}