-
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
9 changed files
with
91 additions
and
4 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
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 organization; |
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,16 @@ | ||
#[derive(Debug, Clone)] | ||
pub struct Organization { | ||
name: String, | ||
} | ||
|
||
impl Organization { | ||
pub fn new(name: &str) -> Self { | ||
Self { | ||
name: name.to_string(), | ||
} | ||
} | ||
|
||
pub fn name(&self) -> &str { | ||
&self.name | ||
} | ||
} |
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,9 @@ | ||
use crate::github::organization::Organization; | ||
|
||
pub async fn get_organizations() -> Vec<Organization> { | ||
let organizations = vec![ | ||
Organization::new("rust-lang"), | ||
Organization::new("rust-lang-nursery"), | ||
]; | ||
organizations | ||
} |
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,42 @@ | ||
use std::sync::Arc; | ||
|
||
use rocket::tokio::sync::RwLock; | ||
use rocket::{Build, Rocket}; | ||
|
||
use crate::{github::organization::Organization, remote}; | ||
|
||
pub struct GithubState { | ||
organizations: Vec<Organization>, | ||
} | ||
|
||
impl GithubState { | ||
pub async fn fetch_organizations(&mut self) -> Vec<Organization> { | ||
let orgs = remote::get_organizations().await; | ||
self.organizations = orgs; | ||
self.organizations.clone() | ||
} | ||
} | ||
|
||
pub struct AppState { | ||
pub github: Arc<RwLock<GithubState>>, | ||
} | ||
|
||
impl AppState { | ||
pub fn new() -> Self { | ||
Self { | ||
github: Arc::new(RwLock::new(GithubState { | ||
organizations: vec![], | ||
})), | ||
} | ||
} | ||
|
||
pub async fn fetch_organizations(&self) -> Vec<Organization> { | ||
self.github.write().await.fetch_organizations().await | ||
} | ||
} | ||
|
||
pub fn mount_state(rocket: Rocket<Build>) -> Rocket<Build> { | ||
let state = AppState::new(); | ||
|
||
rocket.manage(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
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