feat(api): implement user authentication and registration endpoints
- Add main application logic in `api/src/main.rs` to initialize server, database, and services. - Create authentication routes in `api/src/routes/auth.rs` for login, register, logout, and user info retrieval. - Implement configuration route in `api/src/routes/config.rs` to expose application settings. - Define application state management in `api/src/state.rs` to share user service and configuration. - Set up Docker Compose configuration in `compose.yml` for backend, worker, and database services. - Establish domain logic in `domain` crate with user entities, repositories, and services. - Implement SQLite user repository in `infra/src/user_repository.rs` for user data persistence. - Create database migration handling in `infra/src/db.rs` and session store in `infra/src/session_store.rs`. - Add necessary dependencies and features in `Cargo.toml` files for both `domain` and `infra` crates.
This commit is contained in:
36
api/src/state.rs
Normal file
36
api/src/state.rs
Normal file
@@ -0,0 +1,36 @@
|
||||
//! Application State
|
||||
//!
|
||||
//! Holds shared state for the application.
|
||||
|
||||
use axum::extract::FromRef;
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::config::Config;
|
||||
use domain::UserService;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct AppState {
|
||||
pub user_service: Arc<UserService>,
|
||||
pub config: Arc<Config>,
|
||||
}
|
||||
|
||||
impl AppState {
|
||||
pub fn new(user_service: UserService, config: Config) -> Self {
|
||||
Self {
|
||||
user_service: Arc::new(user_service),
|
||||
config: Arc::new(config),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl FromRef<AppState> for Arc<UserService> {
|
||||
fn from_ref(input: &AppState) -> Self {
|
||||
input.user_service.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl FromRef<AppState> for Arc<Config> {
|
||||
fn from_ref(input: &AppState) -> Self {
|
||||
input.config.clone()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user