-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a9d2396
commit 3cd10c9
Showing
13 changed files
with
186 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,5 @@ pub mod router; | |
|
||
mod controller; | ||
mod repository; | ||
mod service; | ||
mod types; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1 @@ | ||
use std::sync::Arc; | ||
|
||
use axum::async_trait; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
pub mod sample; | ||
|
||
pub type DynLinksRepo = Arc<dyn LinksRepo + Send + Sync>; | ||
type RepoResult<T> = std::result::Result<T, Box<dyn std::error::Error>>; | ||
|
||
#[async_trait] | ||
pub trait LinksRepo { | ||
async fn list(&self) -> RepoResult<Vec<ListItem>> { | ||
Err("Not implemented".into()) | ||
} | ||
|
||
async fn post(&self) -> RepoResult<ListItem> { | ||
Err("Not implemented".into()) | ||
} | ||
|
||
async fn get(&self, _id: &str) -> RepoResult<ListItem> { | ||
Err("Not implemented".into()) | ||
} | ||
|
||
async fn put(&self, _id: &str) -> RepoResult<ListItem> { | ||
Err("Not implemented".into()) | ||
} | ||
|
||
async fn delete(&self, _id: &str) -> RepoResult<()> { | ||
Err("Not implemented".into()) | ||
} | ||
} | ||
|
||
#[derive(Debug, Default, Serialize, Deserialize)] | ||
pub struct ListItem { | ||
id: String, | ||
owner: String, | ||
url: String, | ||
title: String, | ||
description: String, | ||
created_at: String, | ||
updated_at: String, | ||
} | ||
pub mod links; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
use axum::async_trait; | ||
|
||
use crate::types::{ | ||
links::LinkItem, | ||
repository::{Links, Result}, | ||
}; | ||
|
||
pub struct Repository {} | ||
|
||
#[async_trait] | ||
impl Links for Repository { | ||
async fn list(&self) -> Result<Vec<LinkItem>> { | ||
Ok(vec![]) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,16 @@ | ||
use std::sync::Arc; | ||
|
||
use axum::Router; | ||
use crate::{ | ||
controller, repository, service, | ||
types::{repository::DynLinks as DynLinksRepo, service::DynLinks as DynLinksService, state}, | ||
}; | ||
|
||
use crate::controller::links; | ||
use crate::repository::{sample, DynLinksRepo}; | ||
pub fn new() -> axum::Router { | ||
let links_repo = Arc::new(repository::links::Repository {}) as DynLinksRepo; | ||
let links_service = Arc::new(service::links::Service {}) as DynLinksService; | ||
|
||
pub fn new() -> Router { | ||
let list_repo = Arc::new(sample::Repo {}) as DynLinksRepo; | ||
Router::new().merge(links::router()).with_state(list_repo) | ||
let state = state::Router::new(links_repo, links_service); | ||
axum::Router::new() | ||
.merge(controller::links::router()) | ||
.with_state(state) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod links; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use axum::async_trait; | ||
|
||
use crate::types::{ | ||
links::LinkItem, | ||
service::{Links, Result}, | ||
state, | ||
}; | ||
|
||
pub struct Service {} | ||
|
||
#[async_trait] | ||
impl Links for Service { | ||
async fn list<'a>(&self, app_state: &'a state::Router) -> Result<Vec<LinkItem>> { | ||
let links_repo = app_state.get_links_repo(); | ||
links_repo.list().await | ||
} | ||
|
||
async fn post<'a>(&self, app_state: &'a state::Router) -> Result<LinkItem> { | ||
let links_repo = app_state.get_links_repo(); | ||
links_repo.post().await | ||
} | ||
|
||
async fn get<'a>(&self, id: &str, app_state: &'a state::Router) -> Result<LinkItem> { | ||
let links_repo = app_state.get_links_repo(); | ||
links_repo.get(id).await | ||
} | ||
|
||
async fn put<'a>(&self, id: &str, app_state: &'a state::Router) -> Result<LinkItem> { | ||
let links_repo = app_state.get_links_repo(); | ||
links_repo.put(id).await | ||
} | ||
|
||
async fn delete<'a>(&self, id: &str, app_state: &'a state::Router) -> Result<()> { | ||
let links_repo = app_state.get_links_repo(); | ||
links_repo.delete(id).await | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
pub mod links; | ||
pub mod repository; | ||
pub mod service; | ||
pub mod state; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Debug, Default, Serialize, Deserialize)] | ||
pub struct LinkItem { | ||
id: String, | ||
owner: String, | ||
url: String, | ||
title: String, | ||
description: String, | ||
created_at: String, | ||
updated_at: String, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use std::sync::Arc; | ||
|
||
use axum::async_trait; | ||
|
||
use super::links::LinkItem; | ||
|
||
pub type DynLinks = Arc<dyn Links + Send + Sync>; | ||
pub type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>; | ||
|
||
#[async_trait] | ||
pub trait Links { | ||
async fn list(&self) -> Result<Vec<LinkItem>> { | ||
Err("Not implemented".into()) | ||
} | ||
|
||
async fn post(&self) -> Result<LinkItem> { | ||
Err("Not implemented".into()) | ||
} | ||
|
||
async fn get(&self, _id: &str) -> Result<LinkItem> { | ||
Err("Not implemented".into()) | ||
} | ||
|
||
async fn put(&self, _id: &str) -> Result<LinkItem> { | ||
Err("Not implemented".into()) | ||
} | ||
|
||
async fn delete(&self, _id: &str) -> Result<()> { | ||
Err("Not implemented".into()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use std::sync::Arc; | ||
|
||
use axum::async_trait; | ||
|
||
use super::{links::LinkItem, state}; | ||
|
||
pub type DynLinks = Arc<dyn Links + Send + Sync>; | ||
pub type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>; | ||
|
||
#[async_trait] | ||
pub trait Links { | ||
async fn list<'a>(&self, _app_state: &'a state::Router) -> Result<Vec<LinkItem>> { | ||
Err("Not implemented".into()) | ||
} | ||
|
||
async fn post<'a>(&self, _app_state: &'a state::Router) -> Result<LinkItem> { | ||
Err("Not implemented".into()) | ||
} | ||
|
||
async fn get<'a>(&self, _id: &str, _app_state: &'a state::Router) -> Result<LinkItem> { | ||
Err("Not implemented".into()) | ||
} | ||
|
||
async fn put<'a>(&self, _id: &str, _app_state: &'a state::Router) -> Result<LinkItem> { | ||
Err("Not implemented".into()) | ||
} | ||
|
||
async fn delete<'a>(&self, _id: &str, _app_state: &'a state::Router) -> Result<()> { | ||
Err("Not implemented".into()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use super::{repository::DynLinks as DynLinksRepo, service::DynLinks as DynLinksService}; | ||
|
||
#[derive(Clone)] | ||
pub struct Router { | ||
links_repo: DynLinksRepo, | ||
links_service: DynLinksService, | ||
} | ||
|
||
impl Router { | ||
pub fn new(links_repo: DynLinksRepo, links_service: DynLinksService) -> Self { | ||
Self { | ||
links_repo, | ||
links_service, | ||
} | ||
} | ||
|
||
pub fn get_links_repo(&self) -> &DynLinksRepo { | ||
&self.links_repo | ||
} | ||
|
||
pub fn get_links_service(&self) -> &DynLinksService { | ||
&self.links_service | ||
} | ||
} |