Initial commit with Claude created service skeleton
This commit is contained in:
commit
09e538872d
13 changed files with 848 additions and 0 deletions
9
src/lib.rs
Normal file
9
src/lib.rs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
pub mod routes;
|
||||
pub mod votes;
|
||||
|
||||
use axum::Router;
|
||||
use tower_http::trace::TraceLayer;
|
||||
|
||||
pub fn app() -> Router {
|
||||
routes::router().layer(TraceLayer::new_for_http())
|
||||
}
|
||||
17
src/main.rs
Normal file
17
src/main.rs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
tracing_subscriber::registry()
|
||||
.with(
|
||||
tracing_subscriber::EnvFilter::try_from_default_env().unwrap_or_else(|_| {
|
||||
format!("{}=debug,tower_http=debug", env!("CARGO_PKG_NAME")).into()
|
||||
}),
|
||||
)
|
||||
.with(tracing_subscriber::fmt::layer())
|
||||
.init();
|
||||
|
||||
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
|
||||
tracing::info!("listening on {}", listener.local_addr().unwrap());
|
||||
axum::serve(listener, uprs::app()).await.unwrap();
|
||||
}
|
||||
17
src/routes.rs
Normal file
17
src/routes.rs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use axum::{Router, routing::get};
|
||||
|
||||
use crate::votes::{repository::VoteRepository, service::VoteService};
|
||||
|
||||
pub fn router() -> Router {
|
||||
let vote_service = Arc::new(VoteService::new(VoteRepository::new()));
|
||||
|
||||
Router::new()
|
||||
.route("/health", get(health))
|
||||
.merge(crate::votes::handlers::router(vote_service))
|
||||
}
|
||||
|
||||
async fn health() -> &'static str {
|
||||
"ok"
|
||||
}
|
||||
7
src/votes/dto.rs
Normal file
7
src/votes/dto.rs
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct CreateVoteRequest {}
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct VoteResponse {}
|
||||
29
src/votes/handlers.rs
Normal file
29
src/votes/handlers.rs
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use axum::{
|
||||
Router,
|
||||
extract::{Path, State},
|
||||
routing::{get, post},
|
||||
};
|
||||
|
||||
use super::{dto::CreateVoteRequest, service::VoteService};
|
||||
|
||||
pub fn router(service: Arc<VoteService>) -> Router {
|
||||
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!()
|
||||
}
|
||||
5
src/votes/mod.rs
Normal file
5
src/votes/mod.rs
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
pub mod dto;
|
||||
pub mod handlers;
|
||||
pub mod model;
|
||||
pub mod repository;
|
||||
pub mod service;
|
||||
1
src/votes/model.rs
Normal file
1
src/votes/model.rs
Normal file
|
|
@ -0,0 +1 @@
|
|||
pub struct Vote {}
|
||||
9
src/votes/repository.rs
Normal file
9
src/votes/repository.rs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
use super::model::Vote;
|
||||
|
||||
pub struct VoteRepository {}
|
||||
|
||||
impl VoteRepository {
|
||||
pub fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
}
|
||||
14
src/votes/service.rs
Normal file
14
src/votes/service.rs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
use super::{
|
||||
dto::{CreateVoteRequest, VoteResponse},
|
||||
repository::VoteRepository,
|
||||
};
|
||||
|
||||
pub struct VoteService {
|
||||
repository: VoteRepository,
|
||||
}
|
||||
|
||||
impl VoteService {
|
||||
pub fn new(repository: VoteRepository) -> Self {
|
||||
Self { repository }
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue