Refactor to clean-up axum server implementation
This commit is contained in:
parent
09e538872d
commit
4b16f39b4d
10 changed files with 1308 additions and 57 deletions
|
|
@ -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!()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,3 @@
|
|||
use sqlx::PgPool;
|
||||
|
||||
use super::model::Vote;
|
||||
|
||||
pub struct VoteRepository {}
|
||||
|
||||
impl VoteRepository {
|
||||
pub fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue