Skip to main content

args_api/resource/
common.rs

1use chrono::{DateTime, Utc};
2use serde::{Deserialize, Serialize, de::DeserializeOwned};
3use uuid::Uuid;
4
5use crate::ApiResource;
6
7/// Shared response envelope for paginated list endpoints.
8///
9/// `next_cursor` is `None` (omitted from the JSON via `skip_serializing_if`)
10/// on the final page. Clients pass it back as `?cursor=...` to fetch the
11/// next page; the encoding is opaque.
12#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
13pub struct Page<T> {
14    pub data: Vec<T>,
15    #[serde(skip_serializing_if = "Option::is_none")]
16    pub next_cursor: Option<String>,
17}
18
19impl<T: ApiResource + DeserializeOwned> ApiResource for Page<T> {}
20
21/// Shared author projection returned across domains (bug, question, …).
22#[derive(ApiResource, Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
23pub struct AuthorResource {
24    pub id: Uuid,
25    pub name: String,
26    #[serde(default, skip_serializing_if = "Option::is_none")]
27    pub image_updated_at: Option<DateTime<Utc>>,
28}
29
30/// The capacity in which a user relates to a repository.
31#[derive(ApiResource, Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
32#[serde(rename_all = "snake_case")]
33pub enum RepositoryRole {
34    Maintainer,
35    User,
36}
37
38/// The capacity in which a user relates to an organization. `User` is the
39/// fallback for a viewer who is not a member (or is unauthenticated); members
40/// are only ever `Admin` or `Member`.
41#[derive(ApiResource, Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
42#[serde(rename_all = "lowercase")]
43pub enum OrganizationRole {
44    Admin,
45    Member,
46    User,
47}