-
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
Showing
25 changed files
with
177 additions
and
53 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
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,4 +1,12 @@ | ||
use error::Result; | ||
use store::objects::CryptoCurrencyView; | ||
|
||
#[async_trait] | ||
pub trait DbRepository{ | ||
pub trait DbRepositoryContract{ | ||
async fn get_cryptocurrencies(&self) -> Result<Vec<CryptoCurrencyView>>; | ||
} | ||
|
||
#[async_trait] | ||
pub trait CryptocurrenciesContract{ | ||
async fn get_cryptocurrencies(&self) -> Result<Vec<CryptoCurrencyView>>; | ||
} |
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,14 @@ | ||
use super::contract::{CryptocurrenciesContract, DbRepositoryContract}; | ||
use error::Result; | ||
use store::objects::CryptoCurrencyView; | ||
|
||
pub struct Cryptocurrencies<A: DbRepositoryContract> { | ||
pub(super) repository: A, | ||
} | ||
|
||
#[async_trait] | ||
impl<A: DbRepositoryContract + Send + Sync> CryptocurrenciesContract for Cryptocurrencies<A> { | ||
async fn get_cryptocurrencies(&self) -> Result<Vec<CryptoCurrencyView>> { | ||
self.repository.get_cryptocurrencies().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,11 @@ | ||
use actix_web::{web::Data, HttpResponse}; | ||
use error::Result; | ||
|
||
use crate::api::cryptocurrencies::contract::CryptocurrenciesContract; | ||
|
||
pub async fn get_cryptocurrencies<S: CryptocurrenciesContract>( | ||
service: Data<S>, | ||
) -> Result<HttpResponse> { | ||
let value = service.get_cryptocurrencies().await?; | ||
Ok(HttpResponse::Ok().json(value)) | ||
} |
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,2 @@ | ||
mod get; | ||
pub use get::get_cryptocurrencies; |
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,4 +1,24 @@ | ||
use std::sync::Arc; | ||
|
||
use actix_web::web::{self, resource, Data, ServiceConfig}; | ||
use sea_orm::DatabaseConnection; | ||
|
||
use self::{domain::Cryptocurrencies, handlers::*, repository::PgRepository}; | ||
|
||
mod contract; | ||
mod repository; | ||
mod domain; | ||
mod handlers; | ||
mod handlers; | ||
mod repository; | ||
|
||
pub fn setup(conn: Arc<DatabaseConnection>, config: &mut ServiceConfig) { | ||
let state = Cryptocurrencies { | ||
repository: PgRepository::new(conn), | ||
}; | ||
|
||
config.app_data(Data::new(state)); | ||
|
||
config.service( | ||
resource("/api/{version}/crypto") | ||
.route(web::get().to(get_cryptocurrencies::<Cryptocurrencies<PgRepository>>)), | ||
); | ||
} |
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 |
---|---|---|
@@ -1 +1,25 @@ | ||
mod cryptocurrencies; | ||
use std::sync::Arc; | ||
|
||
use actix_web::{dev::Server, web::ServiceConfig, App, HttpServer}; | ||
use sea_orm::DatabaseConnection; | ||
|
||
mod cryptocurrencies; | ||
|
||
pub fn create_api(conn: Arc<DatabaseConnection>) -> Server { | ||
let workers = match config::get_default("IS_DEV", "false").as_str() == "true" { | ||
true => 1, | ||
false => config::get_default("ACTIX_WORKERS", "8") | ||
.parse() | ||
.unwrap_or(8), | ||
}; | ||
|
||
HttpServer::new(move || App::new().configure(|config| configure_routes(conn.clone(), config))) | ||
.workers(workers) | ||
.bind(("localhost", 1111)) | ||
.expect("Unable to start sever") | ||
.run() | ||
} | ||
|
||
fn configure_routes(conn: Arc<DatabaseConnection>, config: &mut ServiceConfig) { | ||
cryptocurrencies::setup(conn, config); | ||
} |
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
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
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,10 @@ | ||
use actix_web::{HttpResponse, ResponseError}; | ||
|
||
use crate::Error; | ||
|
||
impl ResponseError for Error { | ||
fn error_response(&self) -> HttpResponse { | ||
println!("{}", self); | ||
HttpResponse::Ok().finish() | ||
} | ||
} |
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,5 +1,7 @@ | ||
use thiserror::Error; | ||
|
||
mod actix; | ||
|
||
pub type Result<T> = std::result::Result<T, Error>; | ||
|
||
#[derive(Error, Debug)] | ||
|
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 |
---|---|---|
|
@@ -7,3 +7,4 @@ edition = "2021" | |
|
||
[dependencies] | ||
sea-orm.workspace =true | ||
serde.workspace = true |
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,8 +1,6 @@ | ||
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.3 | ||
#[macro_use] extern crate serde; | ||
|
||
pub mod prelude; | ||
mod migrations; | ||
pub mod objects; | ||
|
||
pub mod cryptocurrencies; | ||
pub mod github_projects; | ||
pub mod github_repositories; | ||
pub mod issues; | ||
pub use migrations::*; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,8 @@ | ||
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.3 | ||
|
||
pub mod prelude; | ||
|
||
pub mod cryptocurrencies; | ||
pub mod github_projects; | ||
pub mod github_repositories; | ||
pub mod issues; |
File renamed without changes.
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 sea_orm::{prelude::Uuid, FromQueryResult}; | ||
|
||
#[derive(FromQueryResult, Serialize)] | ||
pub struct CryptoCurrencyView { | ||
pub id: Uuid, | ||
pub name: String, | ||
pub coingecko_id: String, | ||
pub github_id: Uuid, | ||
pub github: String, | ||
pub repositories: Vec<String>, | ||
pub issues: i64, | ||
} |
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,2 @@ | ||
mod cryptocurrencies; | ||
pub use cryptocurrencies::CryptoCurrencyView; |