summaryrefslogtreecommitdiff
path: root/server/src/api_model.rs
diff options
context:
space:
mode:
authorJoel Klinghed <the_jk@spawned.biz>2025-01-03 01:28:54 +0100
committerJoel Klinghed <the_jk@spawned.biz>2025-01-03 01:28:54 +0100
commit7494db93b9262c3d8330fd11631e711a1642b8fc (patch)
tree565534ddaa990a861c0ef8a9439f7656fce7f132 /server/src/api_model.rs
parent4b1f7fec1cf9d427234ff5bded79a6d18d5c88ce (diff)
Add initital tests
Also add /users endpoint.
Diffstat (limited to 'server/src/api_model.rs')
-rw-r--r--server/src/api_model.rs39
1 files changed, 28 insertions, 11 deletions
diff --git a/server/src/api_model.rs b/server/src/api_model.rs
index f3bb5cf..b08ad5c 100644
--- a/server/src/api_model.rs
+++ b/server/src/api_model.rs
@@ -1,7 +1,7 @@
use rocket::serde::{Deserialize, Serialize};
use utoipa::ToSchema;
-#[derive(Deserialize, Serialize, Copy, Clone, ToSchema)]
+#[derive(Copy, Clone, Deserialize, Serialize, ToSchema)]
pub enum ReviewState {
Draft,
Open,
@@ -9,14 +9,14 @@ pub enum ReviewState {
Closed,
}
-#[derive(Deserialize, Serialize, Copy, Clone, ToSchema)]
+#[derive(Copy, Clone, Debug, Deserialize, PartialEq, Serialize, ToSchema)]
pub enum UserReviewRole {
Reviewer,
Watcher,
None,
}
-#[derive(Serialize, ToSchema)]
+#[derive(Debug, Deserialize, Serialize, PartialEq, ToSchema)]
pub struct User {
#[schema(example = 1337u64)]
pub id: u64,
@@ -28,6 +28,19 @@ pub struct User {
pub active: bool,
}
+#[derive(Deserialize, Serialize, ToSchema)]
+pub struct Users {
+ #[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 users: Vec<User>,
+}
+
#[derive(Serialize, ToSchema)]
pub struct ReviewUserEntry {
pub user: User,
@@ -77,7 +90,7 @@ pub struct Reviews {
pub reviews: Vec<ReviewEntry>,
}
-#[derive(Serialize, ToSchema)]
+#[derive(Debug, Deserialize, PartialEq, Serialize, ToSchema)]
pub struct ProjectUserEntry {
pub user: User,
#[schema(example = UserReviewRole::Reviewer)]
@@ -86,7 +99,7 @@ pub struct ProjectUserEntry {
pub maintainer: bool,
}
-#[derive(Deserialize, ToSchema)]
+#[derive(Deserialize, Serialize, ToSchema)]
pub struct ProjectUserEntryData {
#[schema(example = UserReviewRole::Reviewer)]
pub default_role: Option<UserReviewRole>,
@@ -94,7 +107,7 @@ pub struct ProjectUserEntryData {
pub maintainer: Option<bool>,
}
-#[derive(Serialize, ToSchema)]
+#[derive(Debug, Deserialize, PartialEq, Serialize, ToSchema)]
pub struct Project {
#[schema(example = 1u64)]
pub id: u64,
@@ -105,7 +118,7 @@ pub struct Project {
pub users: Vec<ProjectUserEntry>,
}
-#[derive(Deserialize, ToSchema)]
+#[derive(Deserialize, Serialize, ToSchema)]
pub struct ProjectData<'r> {
#[schema(example = "FAKE: Features All Kids Erase")]
pub title: Option<&'r str>,
@@ -113,7 +126,7 @@ pub struct ProjectData<'r> {
pub description: Option<&'r str>,
}
-#[derive(Serialize, ToSchema)]
+#[derive(Deserialize, Serialize, ToSchema)]
pub struct ProjectEntry {
#[schema(example = 1u64)]
pub id: u64,
@@ -121,7 +134,7 @@ pub struct ProjectEntry {
pub title: String,
}
-#[derive(Serialize, ToSchema)]
+#[derive(Deserialize, Serialize, ToSchema)]
pub struct Projects {
#[schema(example = 0u32)]
pub offset: u32,
@@ -134,9 +147,13 @@ pub struct Projects {
pub projects: Vec<ProjectEntry>,
}
-#[derive(Serialize, ToSchema)]
+#[derive(Deserialize, Serialize, ToSchema)]
pub struct StatusResponse {
pub ok: bool,
- #[serde(skip_serializing_if = "Option::is_none")]
+ #[serde(
+ skip_serializing_if = "Option::is_none",
+ // &'static str is problematic for serde, only used in tests anyway.
+ skip_deserializing,
+ )]
pub error: Option<&'static str>,
}