Skip to main content

swarmhive_api_types/
release.rs

1use chrono::{DateTime, Utc};
2use serde::{Deserialize, Serialize};
3use utoipa::ToSchema;
4use uuid::Uuid;
5
6/// Lifecycle state of a release. `draft` is created at upload time; `published`
7/// is servable and promotable; `yanked` is withdrawn (channels are not
8/// auto-reverted — that is rollback's job).
9#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, ToSchema)]
10#[serde(rename_all = "snake_case")]
11pub enum ReleaseStatus {
12    Draft,
13    Published,
14    Yanked,
15}
16
17/// A versioned release of an app. `version` is unique within the app and is the
18/// canonical display string; `android_version_code` carries the monotonic int
19/// RN Android compares against (NULL for Tauri).
20#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, ToSchema)]
21pub struct Release {
22    pub id: Uuid,
23    pub app_id: Uuid,
24    pub version: String,
25    pub android_version_code: Option<i64>,
26    /// RN Android 强制更新下限(整数 versionCode);None = 无下限。与 semver `min_version` 正交。
27    pub android_min_version_code: Option<i64>,
28    pub status: ReleaseStatus,
29    pub release_notes: Option<String>,
30    pub published_at: Option<DateTime<Utc>>,
31    /// 强制更新下限(semver);None = 无下限。
32    pub min_version: Option<String>,
33    /// 灰度放量百分比 1-100;None = 视作 100 全量。
34    pub rollout_percent: Option<i16>,
35    pub created_at: DateTime<Utc>,
36    pub updated_at: DateTime<Utc>,
37}
38
39#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
40pub struct CreateReleaseRequest {
41    pub version: String,
42    #[serde(default)]
43    pub android_version_code: Option<i64>,
44    #[serde(default)]
45    pub android_min_version_code: Option<i64>,
46    #[serde(default)]
47    pub release_notes: Option<String>,
48}
49
50#[derive(Debug, Clone, Default, Serialize, Deserialize, ToSchema)]
51pub struct UpdateReleaseRequest {
52    #[serde(default)]
53    pub android_version_code: Option<i64>,
54    /// RN 强更下限(整数 versionCode)。Some 设值,absent/null 不改。调高即 kill switch。
55    #[serde(default)]
56    pub android_min_version_code: Option<i64>,
57    #[serde(default)]
58    pub release_notes: Option<String>,
59    /// 强制更新下限(semver)。Some 设值,absent/null 不改;不支持回 NULL(清空走 "0.0.0")。
60    #[serde(default)]
61    pub min_version: Option<String>,
62    /// 灰度百分比 1-100。Some 设值(越界 422),absent/null 不改;不支持回 NULL(清空走 100)。
63    #[serde(default)]
64    pub rollout_percent: Option<i16>,
65}
66
67/// Body for `POST .../channels/:name/promote` — the published version to point
68/// the channel at.
69#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
70pub struct PromoteRequest {
71    pub version: String,
72}
73
74/// Body for `POST .../channels/:name/rollback`. `version` absent → revert to the
75/// channel's previous distinct release in history.
76#[derive(Debug, Clone, Default, Serialize, Deserialize, ToSchema)]
77pub struct RollbackRequest {
78    #[serde(default)]
79    pub version: Option<String>,
80}