|
| 1 | +use super::validators::{validate_ar, validate_od_hp_cs, validate_status}; |
| 2 | +use bigdecimal::BigDecimal; |
| 3 | +use chrono::NaiveDateTime; |
| 4 | +use serde_json::Value; |
| 5 | +use validator::Validate; |
| 6 | + |
| 7 | +#[derive(Debug, Clone, sqlx::FromRow, Validate)] |
| 8 | +pub struct BeatmapRow { |
| 9 | + /// Unique identifier for the beatmap record. |
| 10 | + /// Must be a positive integer (≥ 1). |
| 11 | + #[validate(range(min = 1, message = "ID must be positive"))] |
| 12 | + pub id: i32, |
| 13 | + |
| 14 | + /// Osu beatmap ID from the official osu! API. |
| 15 | + /// Must be a positive integer (≥ 1). |
| 16 | + #[validate(range(min = 1, message = "Osu ID must be positive"))] |
| 17 | + pub osu_id: Option<i32>, |
| 18 | + |
| 19 | + /// Reference to the beatmapset this beatmap belongs to. |
| 20 | + /// Optional field, can be None. |
| 21 | + pub beatmapset_id: Option<i32>, |
| 22 | + |
| 23 | + /// Difficulty name of the beatmap. |
| 24 | + /// Must be between 1 and 255 characters. |
| 25 | + #[validate(length( |
| 26 | + min = 1, |
| 27 | + max = 255, |
| 28 | + message = "Difficulty must be between 1 and 255 characters" |
| 29 | + ))] |
| 30 | + pub difficulty: String, |
| 31 | + |
| 32 | + /// Number of circles in the beatmap. |
| 33 | + /// Must be a non-negative integer (≥ 0). |
| 34 | + #[validate(range(min = 0, message = "Count circles must be non-negative"))] |
| 35 | + pub count_circles: i32, |
| 36 | + |
| 37 | + /// Number of sliders in the beatmap. |
| 38 | + /// Must be a non-negative integer (≥ 0). |
| 39 | + #[validate(range(min = 0, message = "Count sliders must be non-negative"))] |
| 40 | + pub count_sliders: i32, |
| 41 | + |
| 42 | + /// Number of spinners in the beatmap. |
| 43 | + /// Must be a non-negative integer (≥ 0). |
| 44 | + #[validate(range(min = 0, message = "Count spinners must be non-negative"))] |
| 45 | + pub count_spinners: i32, |
| 46 | + |
| 47 | + /// Maximum combo possible in the beatmap. |
| 48 | + /// Must be a non-negative integer (≥ 0). |
| 49 | + #[validate(range(min = 0, message = "Max combo must be non-negative"))] |
| 50 | + pub max_combo: i32, |
| 51 | + |
| 52 | + /// Main pattern data stored as JSON. |
| 53 | + /// Must not be null. |
| 54 | + pub main_pattern: Value, |
| 55 | + |
| 56 | + /// Circle Size (CS) value. |
| 57 | + /// Must be between 0.0 and 10.0. |
| 58 | + #[validate(custom(function = "validate_od_hp_cs"))] |
| 59 | + pub cs: BigDecimal, |
| 60 | + |
| 61 | + /// Approach Rate (AR) value. |
| 62 | + /// Must be between 0.0 and 10.0. |
| 63 | + #[validate(custom(function = "validate_ar"))] |
| 64 | + pub ar: BigDecimal, |
| 65 | + |
| 66 | + /// Overall Difficulty (OD) value. |
| 67 | + /// Must be between 0.0 and 10.0. |
| 68 | + #[validate(custom(function = "validate_od_hp_cs"))] |
| 69 | + pub od: BigDecimal, |
| 70 | + |
| 71 | + /// HP Drain (HP) value. |
| 72 | + /// Must be between 0.0 and 10.0. |
| 73 | + #[validate(custom(function = "validate_od_hp_cs"))] |
| 74 | + pub hp: BigDecimal, |
| 75 | + |
| 76 | + /// Game mode (0=osu!, 1=Taiko, 2=Catch, 3=Mania). |
| 77 | + /// Must be between 0 and 3. |
| 78 | + #[validate(range(min = 0, max = 3, message = "Mode must be between 0 and 3"))] |
| 79 | + pub mode: i32, |
| 80 | + |
| 81 | + /// Status of the beatmap. |
| 82 | + /// Must be one of: 'pending', 'ranked', 'qualified', 'loved', 'graveyard'. |
| 83 | + #[validate(custom(function = "validate_status"))] |
| 84 | + pub status: String, |
| 85 | + |
| 86 | + /// Timestamp when the beatmap was created. |
| 87 | + pub created_at: Option<NaiveDateTime>, |
| 88 | + |
| 89 | + /// Timestamp when the beatmap was last updated. |
| 90 | + pub updated_at: Option<NaiveDateTime>, |
| 91 | +} |
0 commit comments