Refactor to clean-up axum server implementation

This commit is contained in:
Alex Selimov 2026-03-17 10:53:57 -04:00
parent 09e538872d
commit 4b16f39b4d
10 changed files with 1308 additions and 57 deletions

View file

@ -1,29 +1,13 @@
use std::sync::Arc;
use axum::{
Router,
extract::{Path, State},
routing::{get, post},
};
use super::{dto::CreateVoteRequest, service::VoteService};
use crate::state::AppState;
pub fn router(service: Arc<VoteService>) -> Router {
use super::dto::CreateVoteRequest;
pub fn router() -> Router<AppState> {
Router::new()
.route("/votes", get(list))
.route("/votes/{id}", get(get_by_id))
.route("/votes", post(create))
.with_state(service)
}
async fn list(State(service): State<Arc<VoteService>>) {
todo!()
}
async fn get_by_id(State(service): State<Arc<VoteService>>, Path(id): Path<u64>) {
todo!()
}
async fn create(State(service): State<Arc<VoteService>>, body: axum::Json<CreateVoteRequest>) {
todo!()
}

View file

@ -1,9 +1,3 @@
use sqlx::PgPool;
use super::model::Vote;
pub struct VoteRepository {}
impl VoteRepository {
pub fn new() -> Self {
Self {}
}
}

View file

@ -1,14 +1,3 @@
use super::{
dto::{CreateVoteRequest, VoteResponse},
repository::VoteRepository,
};
use crate::state::AppState;
pub struct VoteService {
repository: VoteRepository,
}
impl VoteService {
pub fn new(repository: VoteRepository) -> Self {
Self { repository }
}
}
use super::dto::{CreateVoteRequest, VoteResponse};