Skip to content

Commit b63a3df

Browse files
OsefOsef
authored andcommitted
fix
1 parent a9fa2a3 commit b63a3df

File tree

5 files changed

+16
-17
lines changed

5 files changed

+16
-17
lines changed

Cargo.lock

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,7 @@ The crate depends on `tracing` and `tracing-subscriber`, but does not initialize
117117

118118
```rust
119119
fn main(){
120-
tracing_subscriber::fmt()
121-
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
122-
.init();
120+
tracing_subscriber::fmt().with_env_filter(tracing_subscriber::EnvFilter::from_default_env()).init();
123121
}
124122
```
125123

src/models/beatmaps/beatmap/types.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
use super::validators::{validate_ar, validate_od_hp_cs, validate_status};
1+
use super::validators::{validate_ar, validate_od_hp_cs};
2+
use crate::utils::BEATMAP_STATUS_REGEX;
23
use bigdecimal::BigDecimal;
34
use chrono::NaiveDateTime;
45
use serde_json::Value;
@@ -80,7 +81,7 @@ pub struct BeatmapRow {
8081

8182
/// Status of the beatmap.
8283
/// Must be one of: 'pending', 'ranked', 'qualified', 'loved', 'graveyard'.
83-
#[validate(custom(function = "validate_status"))]
84+
#[validate(regex(path = *BEATMAP_STATUS_REGEX))]
8485
pub status: String,
8586

8687
/// Timestamp when the beatmap was created.

src/models/beatmaps/beatmap/validators.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
use bigdecimal::{BigDecimal, FromPrimitive};
22
use validator::ValidationError;
33

4-
pub fn validate_status(status: &str) -> Result<(), ValidationError> {
5-
match status {
6-
"pending" | "ranked" | "qualified" | "loved" | "graveyard" => Ok(()),
7-
_ => Err(validator::ValidationError::new("invalid_status")),
8-
}
9-
}
4+
105

116
pub fn validate_od_hp_cs(value: &BigDecimal) -> Result<(), ValidationError> {
127
if value < &BigDecimal::from_f64(0.0).unwrap() || value > &BigDecimal::from_f64(10.0).unwrap() {

src/utils.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
use once_cell::sync::Lazy;
22
use regex::Regex;
33

4-
/// Regex pour valider les hash alphanumériques
4+
/// Regex for Hash alphanumerical
55
pub static HASH_REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r"^[a-zA-Z0-9]+$").unwrap());
6-
/// Regex pour valider les emails
6+
/// Regex for Email
77
pub static EMAIL_REGEX: Lazy<Regex> =
88
Lazy::new(|| Regex::new(r"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$").unwrap());
99

10-
/// Regex pour valider les noms d'utilisateur (alphanumériques + underscore)
10+
/// Regex for Username (alphanumerical + underscore)
1111
pub static USERNAME_REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r"^[a-zA-Z0-9_]+$").unwrap());
1212

13-
/// Regex pour valider les UUIDs
13+
/// Regex for UUIDs
1414
pub static UUID_REGEX: Lazy<Regex> = Lazy::new(|| {
1515
Regex::new(r"^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$").unwrap()
1616
});
1717

18-
/// Regex pour valider les types de rating (etterna, osu, quaver, malody)
18+
/// Regex for Rating types (etterna, osu, quaver, malody)
1919
pub static RATING_TYPE_REGEX: Lazy<Regex> =
2020
Lazy::new(|| Regex::new(r"^(etterna|osu|quaver|malody)$").unwrap());
2121

@@ -24,3 +24,7 @@ pub static RANK_REGEX: Lazy<Regex> =
2424

2525
pub static SCORE_STATUS_REGEX: Lazy<Regex> =
2626
Lazy::new(|| Regex::new(r"^(pending|processing|validated|cheated|unsubmitted)$").unwrap());
27+
28+
/// Regex for Beatmap status (pending, ranked, qualified, loved, graveyard)
29+
pub static BEATMAP_STATUS_REGEX: Lazy<Regex> =
30+
Lazy::new(|| Regex::new(r"^(pending|ranked|qualified|loved|graveyard)$").unwrap());

0 commit comments

Comments
 (0)