Skip to content
Clone
a06673b
61 lines 1.7 KB Rust
use axum::Json;
use axum::extract::{Path, State};
use axum::http::StatusCode;
use jwt::extractor::AuthUser;
use uuid::Uuid;
use crate::error::RepoResult;
use crate::features::RepoService;
use crate::features::extras::Subscription;
#[utoipa::path(
get,
path = "/repo/{channel_id}/{repo_id}/subscription",
tag = "repo",
responses((status = 200, description = "Get current user's subscription", body = Subscription)),
security(("bearer_auth" = []))
)]
pub(crate) async fn get_handler(
State(_svc): State<RepoService>,
AuthUser { claims }: AuthUser,
Path((_, repo_id)): Path<(Uuid, Uuid)>,
) -> RepoResult<Json<Subscription>> {
Ok(Json(Subscription {
user_id: claims.sub,
repo_id,
mode: "watch".to_string(),
created_at: String::new(),
}))
}
#[utoipa::path(
put,
path = "/repo/{channel_id}/{repo_id}/subscription",
tag = "repo",
responses((status = 204, description = "Watch the repo")),
security(("bearer_auth" = []))
)]
pub(crate) async fn put_handler(
State(svc): State<RepoService>,
AuthUser { claims }: AuthUser,
Path((_, repo_id)): Path<(Uuid, Uuid)>,
) -> RepoResult<StatusCode> {
svc.watch_repo(claims.sub, repo_id).await?;
Ok(StatusCode::NO_CONTENT)
}
#[utoipa::path(
delete,
path = "/repo/{channel_id}/{repo_id}/subscription",
tag = "repo",
responses((status = 204, description = "Unwatch the repo")),
security(("bearer_auth" = []))
)]
pub(crate) async fn delete_handler(
State(svc): State<RepoService>,
AuthUser { claims }: AuthUser,
Path((_, repo_id)): Path<(Uuid, Uuid)>,
) -> RepoResult<StatusCode> {
svc.unwatch_repo(claims.sub, repo_id).await?;
Ok(StatusCode::NO_CONTENT)
}