Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement /post/game route #10

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

Implement /post/game route #10

wants to merge 8 commits into from

Conversation

Comeza
Copy link
Member

@Comeza Comeza commented Aug 27, 2022

This would have the benefit of adding games while the server is running.
But it would slow down initial building of the stats.

@Comeza Comeza added the enhancement New feature or request label Aug 27, 2022
@Comeza Comeza self-assigned this Aug 27, 2022
#[post("/post/game")]
async fn post_game(data: Data<RwLock<AppData>>, game: Json<GameStats>) -> impl Responder {
let res = {
let mut data = data.write().unwrap(); // Needs better error handling -- esp. with if the RwLock is poisoned
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let mut data = data.write().unwrap(); // Needs better error handling -- esp. with if the RwLock is poisoned
let mut data = data.write().unwrap(); // Needs better error handling -- esp. with if the RwLock is poisoned

We could use parking_lot, which has an RwLock without poisoning.

Comment on lines +116 to +117
data.stats.merge(stats);
data.games.push(game);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to check if the game is already present (by checking the round_date)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should check if the game already exists (by comparing the round date) and return an appropriate response (an error or something like an empty JSON) in that case.

ns2-stat-api/src/main.rs Outdated Show resolved Hide resolved
ns2-stat-api/src/main.rs Outdated Show resolved Hide resolved
ns2-stat/src/lib.rs Outdated Show resolved Hide resolved
ns2-stat/src/lib.rs Outdated Show resolved Hide resolved
ns2-stat/src/lib.rs Outdated Show resolved Hide resolved
ns2-stat/src/lib.rs Outdated Show resolved Hide resolved
ns2-stat/src/lib.rs Outdated Show resolved Hide resolved
ns2-stat/src/lib.rs Outdated Show resolved Hide resolved
ns2-stat/src/lib.rs Outdated Show resolved Hide resolved
ns2-stat/src/lib.rs Outdated Show resolved Hide resolved
@Comeza Comeza marked this pull request as ready for review March 9, 2023 18:31
ns2-stat-api/src/main.rs Outdated Show resolved Hide resolved
serde_repr = "0.1"
serde_repr = "0.1"
Copy link
Contributor

@konsumlamm konsumlamm Mar 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you readd the trailing newline?

Comment on lines +120 to +136
impl<T> Merge for Option<T>
where
T: Merge,
{
fn merge(&mut self, other: Self) {
match (self, other) {
// (Some, Some)
(Some(v), Some(other)) => v.merge(other),

// (None, Some)
(s, Some(other)) => *s = Some(other),

// (None, None) or (Some, None)
_ => (),
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this used for?

@@ -1,2911 +1,4114 @@
{
"KillFeed":[{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you undo this reformat?

Co-authored-by: konsumlamm <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants