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, AuthUser { claims }: AuthUser, Path((_, repo_id)): Path<(Uuid, Uuid)>, ) -> RepoResult> { 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, AuthUser { claims }: AuthUser, Path((_, repo_id)): Path<(Uuid, Uuid)>, ) -> RepoResult { 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, AuthUser { claims }: AuthUser, Path((_, repo_id)): Path<(Uuid, Uuid)>, ) -> RepoResult { svc.unwatch_repo(claims.sub, repo_id).await?; Ok(StatusCode::NO_CONTENT) }