use crate::{auth::User, error::Result, user::RepositoryDefinition, validate::validate_repo};
use actix_web::{HttpResponse, web};

use crate::AppState;

pub async fn add_repo(
    app_state: web::Data<AppState>,
    user: web::ReqData<User>,
    repo: web::Json<RepositoryDefinition>,
) -> Result<HttpResponse> {
    validate_repo(app_state.clone(), &repo, &user.id).await?;
    app_state
        .user
        .add_repository(&user.id, repo.into_inner())
        .await
}
