diff options
| author | Joel Klinghed <the_jk@spawned.biz> | 2025-06-12 09:11:18 +0200 |
|---|---|---|
| committer | Joel Klinghed <the_jk@spawned.biz> | 2025-06-19 00:19:37 +0200 |
| commit | 2b54f5c51ff9a26d4077037631ed39d62ed2b3fb (patch) | |
| tree | 8544278dba24645a063472a3005a3021879a4bf1 /server/api/src | |
| parent | baa7c85ff3db2366d67ac875fca48ad6dcabf212 (diff) | |
Initial support for translation reviews
Diffstat (limited to 'server/api/src')
| -rw-r--r-- | server/api/src/api_model.rs | 120 |
1 files changed, 116 insertions, 4 deletions
diff --git a/server/api/src/api_model.rs b/server/api/src/api_model.rs index 7dd2a20..1c0572f 100644 --- a/server/api/src/api_model.rs +++ b/server/api/src/api_model.rs @@ -1,7 +1,7 @@ use serde::{Deserialize, Serialize}; use utoipa::ToSchema; -#[derive(Copy, Clone, Deserialize, Serialize, ToSchema)] +#[derive(Copy, Clone, Debug, Deserialize, PartialEq, Serialize, ToSchema)] pub enum ReviewState { Draft, Open, @@ -73,6 +73,42 @@ impl From<UserReviewRole> for u8 { } } +#[derive(Copy, Clone, Debug, Deserialize, PartialEq, Serialize, ToSchema)] +pub enum TranslationState { + Unreviewed, + Unchanged, + Approved, + Revert, + Fix, +} + +impl TryFrom<u8> for TranslationState { + type Error = &'static str; + + fn try_from(value: u8) -> Result<Self, Self::Error> { + match value { + 0 => Ok(TranslationState::Unreviewed), + 1 => Ok(TranslationState::Unchanged), + 2 => Ok(TranslationState::Approved), + 3 => Ok(TranslationState::Revert), + 4 => Ok(TranslationState::Fix), + _ => Err("Invalid translation state"), + } + } +} + +impl From<TranslationState> for u8 { + fn from(value: TranslationState) -> u8 { + match value { + TranslationState::Unreviewed => 0, + TranslationState::Unchanged => 1, + TranslationState::Approved => 2, + TranslationState::Revert => 3, + TranslationState::Fix => 4, + } + } +} + #[derive(Debug, Deserialize, Serialize, PartialEq, ToSchema)] pub struct User { #[schema(example = "jsmith")] @@ -96,7 +132,7 @@ pub struct Users { pub users: Vec<User>, } -#[derive(Serialize, ToSchema)] +#[derive(Debug, Deserialize, PartialEq, Serialize, ToSchema)] pub struct ReviewUserEntry { pub user: User, #[schema(example = UserReviewRole::Reviewer)] @@ -280,8 +316,6 @@ pub struct LocalizationString { pub source: String, pub placeholders: Vec<LocalizationPlaceholder>, pub placeholder_offset: Vec<usize>, - #[schema(example = "123456")] - pub translation_id: i64, pub translations: Vec<TranslationString>, } @@ -302,4 +336,82 @@ pub struct TranslationString { #[schema(example = "Hej!")] pub translation: String, pub placeholder_offset: Vec<usize>, + pub state: TranslationState, + pub comment: String, + pub reviewer: Option<User>, +} + +#[derive(Debug, Deserialize, PartialEq, Serialize, ToSchema)] +pub struct TranslationReview { + #[schema(example = 1u64)] + pub id: u64, + #[schema(example = "FAKE-512: Update translations")] + pub title: String, + #[schema(example = "New translations")] + pub description: String, + pub owner: User, + pub users: Vec<ReviewUserEntry>, + #[schema(example = ReviewState::Open)] + pub state: ReviewState, + #[schema(example = 37.5)] + pub progress: f32, + #[schema(example = false)] + pub archived: bool, + #[schema(example = "d7c502b9c6b833060576a0c4da0287933d603011")] + pub base: String, + #[schema(example = "2cecdec660a30bf3964cee645d9cee03640ef8dc")] + pub head: String, +} + +#[derive(Deserialize, Serialize, ToSchema)] +pub struct TranslationReviewData<'r> { + #[schema(example = "FAKE-512: Update translations")] + pub title: String, + #[schema(example = "New translations")] + pub description: String, + #[schema(example = "d7c502b9c6b833060576a0c4da0287933d603011")] + pub base: Option<&'r str>, +} + +#[derive(Debug, Deserialize, PartialEq, Serialize, ToSchema)] +pub struct TranslationReviewEntry { + #[schema(example = 1u64)] + pub id: u64, + #[schema(example = "FAKE-512: Update translations")] + pub title: String, + pub owner: User, + #[schema(example = ReviewState::Open)] + pub state: ReviewState, + #[schema(example = 37.5)] + pub progress: f32, + #[schema(example = "d7c502b9c6b833060576a0c4da0287933d603011")] + pub base: String, + #[schema(example = "2cecdec660a30bf3964cee645d9cee03640ef8dc")] + pub head: String, +} + +#[derive(Deserialize, Serialize, ToSchema)] +pub struct TranslationReviews { + #[schema(example = 0u32)] + pub offset: u32, + #[schema(example = 10u32)] + pub limit: u32, + #[schema(example = 42u32)] + pub total_count: u32, + #[schema(example = true)] + pub more: bool, + pub reviews: Vec<TranslationReviewEntry>, +} + +#[derive(Deserialize, Serialize, ToSchema)] +pub struct LocalizationStrings { + #[schema(example = 0u32)] + pub offset: u32, + #[schema(example = 10u32)] + pub limit: u32, + #[schema(example = 42u32)] + pub total_count: u32, + #[schema(example = true)] + pub more: bool, + pub strings: Vec<LocalizationString>, } |
