feat: implemented the /backup/preset/{id} [GET] endpoint
This commit is contained in:
parent
1a6466fdfb
commit
0727faae09
|
@ -55,3 +55,26 @@ async fn backup_preset_get(data: web::Data<State>, auth: BearerAuth) -> impl Res
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[get("/backup/preset/{id}")]
|
||||||
|
async fn backup_preset_id_get(
|
||||||
|
data: web::Data<State>,
|
||||||
|
auth: BearerAuth,
|
||||||
|
path: web::Path<String>,
|
||||||
|
) -> impl Responder {
|
||||||
|
if auth.token() != data.token {
|
||||||
|
return HttpResponse::Unauthorized().finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
let id = &path.into_inner();
|
||||||
|
match handlers::backup_preset_id_get(&data.pool, id).await {
|
||||||
|
Ok(resp) => match resp {
|
||||||
|
BackupPresetIdGetResponse::Success(b) => HttpResponse::Ok().json(&b),
|
||||||
|
BackupPresetIdGetResponse::NotFound => HttpResponse::NotFound().finish(),
|
||||||
|
},
|
||||||
|
Err(e) => {
|
||||||
|
error!("While handling /backup/preset/{id} [GET] request: {e}",);
|
||||||
|
HttpResponse::InternalServerError().finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -40,3 +40,9 @@ pub enum BackupPresetPostResponse {
|
||||||
pub struct BackupPresetGetResponse {
|
pub struct BackupPresetGetResponse {
|
||||||
pub presets: Vec<BackupPreset>,
|
pub presets: Vec<BackupPreset>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
pub enum BackupPresetIdGetResponse {
|
||||||
|
Success(BackupPreset),
|
||||||
|
NotFound,
|
||||||
|
}
|
||||||
|
|
|
@ -39,3 +39,16 @@ pub async fn backup_preset_get(pool: &SqlitePool) -> Result<BackupPresetGetRespo
|
||||||
.collect(),
|
.collect(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn backup_preset_id_get(
|
||||||
|
pool: &SqlitePool,
|
||||||
|
id: &str,
|
||||||
|
) -> Result<BackupPresetIdGetResponse> {
|
||||||
|
match backup::preset::Preset::load(pool, id).await? {
|
||||||
|
Some(preset) => Ok(BackupPresetIdGetResponse::Success(preset.into())),
|
||||||
|
None => {
|
||||||
|
warn!("Failed to fetch Backup Preset '{id}'");
|
||||||
|
Ok(BackupPresetIdGetResponse::NotFound)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@ pub async fn start(port: u16, pool: SqlitePool, token: String) -> Result<()> {
|
||||||
// .service(calls::backup_create)
|
// .service(calls::backup_create)
|
||||||
.service(calls::backup_preset_post)
|
.service(calls::backup_preset_post)
|
||||||
.service(calls::backup_preset_get)
|
.service(calls::backup_preset_get)
|
||||||
|
.service(calls::backup_preset_id_get)
|
||||||
.app_data(web::Data::new(State {
|
.app_data(web::Data::new(State {
|
||||||
pool: pool.clone(),
|
pool: pool.clone(),
|
||||||
token: token.to_owned(),
|
token: token.to_owned(),
|
||||||
|
|
|
@ -24,7 +24,7 @@ async fn main() -> Result<()> {
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
backend::prepare(&pool).await?;
|
backend::prepare(&pool).await?;
|
||||||
api::start(6969, pool, token.to_string()).await?;
|
api::start(6969, pool, token.to_owned()).await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue