feat: add repo importing

This commit is contained in:
2026-01-17 19:32:37 -08:00
parent 831259a6a6
commit fb62081ca8
28 changed files with 1823 additions and 116 deletions

View File

@@ -1,8 +1,8 @@
mod account;
mod auth;
mod endpoints;
mod error;
mod middleware;
mod user;
use std::env;
@@ -10,20 +10,24 @@ use actix_web::{
App, HttpServer,
middleware::from_fn,
rt::System,
web::{self, route},
web::{self},
};
use aws_config::BehaviorVersion;
use sqlx::PgPool;
use tracing::level_filters::LevelFilter;
use tracing_subscriber::{
EnvFilter, fmt::format::FmtSpan, layer::SubscriberExt, util::SubscriberInitExt,
};
use crate::auth::{Auth, JWT};
use crate::{
auth::{Auth, JWT},
user::UserRepository,
};
struct AppState {
reqwest_client: reqwest::Client,
pool: PgPool,
auth: Auth,
user: UserRepository,
}
async fn run() -> std::io::Result<()> {
@@ -35,14 +39,20 @@ async fn run() -> std::io::Result<()> {
))
.build()
.expect("failed to create reqwest client");
let config = aws_config::load_defaults(BehaviorVersion::v2026_01_12()).await;
let dynamodb_client = aws_sdk_dynamodb::Client::new(&config);
let app_data = web::Data::new(AppState {
reqwest_client: reqwest_client.clone(),
pool: PgPool::connect(
&env::var("DATABASE_URL").expect("DATABASE_URL environment variable must be set"),
)
.await
.expect("error connecting to db"),
auth: Auth::JWT(JWT::new(reqwest_client.clone())),
user: UserRepository::new(
PgPool::connect(
&env::var("DATABASE_URL").expect("DATABASE_URL environment variable must be set"),
)
.await
.expect("error connecting to db"),
dynamodb_client,
),
});
HttpServer::new(move || {
@@ -70,6 +80,8 @@ async fn run() -> std::io::Result<()> {
"/repos/search",
web::get().to(endpoints::search_repos::search_repos),
)
.wrap(from_fn(middleware::protected))
.route("/repo/add", web::post().to(endpoints::add_repo::add_repo))
.wrap(from_fn(middleware::protected)),
),
),
@@ -90,7 +102,8 @@ fn main() -> std::io::Result<()> {
.add_directive("reqwest=info".parse().unwrap())
.add_directive("hyper=info".parse().unwrap())
.add_directive("h2=info".parse().unwrap())
.add_directive("rustls=info".parse().unwrap());
.add_directive("rustls=info".parse().unwrap())
.add_directive("aws=info".parse().unwrap());
tracing_subscriber::registry()
.with(tracing_env_filter)