feat: init
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
use crate::models::common::{Priority, State, Visibility};
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, sqlx::FromRow)]
|
||||
pub struct Issue {
|
||||
pub id: Uuid,
|
||||
pub workspace_id: Uuid,
|
||||
pub author_id: Uuid,
|
||||
pub number: i64,
|
||||
pub title: String,
|
||||
pub body: Option<String>,
|
||||
pub state: State,
|
||||
pub priority: Priority,
|
||||
pub visibility: Visibility,
|
||||
pub locked: bool,
|
||||
pub milestone_id: Option<Uuid>,
|
||||
pub closed_by: Option<Uuid>,
|
||||
pub closed_at: Option<DateTime<Utc>>,
|
||||
pub due_at: Option<DateTime<Utc>>,
|
||||
pub created_at: DateTime<Utc>,
|
||||
pub updated_at: DateTime<Utc>,
|
||||
pub deleted_at: Option<DateTime<Utc>>,
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, sqlx::FromRow)]
|
||||
pub struct IssueAssignee {
|
||||
pub id: Uuid,
|
||||
pub issue_id: Uuid,
|
||||
pub assignee_id: Uuid,
|
||||
pub assigned_by: Option<Uuid>,
|
||||
pub created_at: DateTime<Utc>,
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, sqlx::FromRow)]
|
||||
pub struct IssueComment {
|
||||
pub id: Uuid,
|
||||
pub issue_id: Uuid,
|
||||
pub author_id: Uuid,
|
||||
pub body: String,
|
||||
pub reply_to_comment_id: Option<Uuid>,
|
||||
pub edited_at: Option<DateTime<Utc>>,
|
||||
pub deleted_at: Option<DateTime<Utc>>,
|
||||
pub created_at: DateTime<Utc>,
|
||||
pub updated_at: DateTime<Utc>,
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
use crate::models::common::RelationType;
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, sqlx::FromRow)]
|
||||
pub struct IssueCommitRelation {
|
||||
pub id: Uuid,
|
||||
pub issue_id: Uuid,
|
||||
pub repo_id: Uuid,
|
||||
pub push_commit_id: Option<Uuid>,
|
||||
pub commit_sha: String,
|
||||
pub relation_type: RelationType,
|
||||
pub created_by: Option<Uuid>,
|
||||
pub created_at: DateTime<Utc>,
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
use crate::models::common::{EventType, JsonValue};
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, sqlx::FromRow)]
|
||||
pub struct IssueEvent {
|
||||
pub id: Uuid,
|
||||
pub issue_id: Uuid,
|
||||
pub actor_id: Option<Uuid>,
|
||||
pub event_type: EventType,
|
||||
pub old_value: Option<JsonValue>,
|
||||
pub new_value: Option<JsonValue>,
|
||||
pub metadata: Option<JsonValue>,
|
||||
pub created_at: DateTime<Utc>,
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, sqlx::FromRow)]
|
||||
pub struct IssueLabelRelation {
|
||||
pub id: Uuid,
|
||||
pub issue_id: Uuid,
|
||||
pub label_id: Uuid,
|
||||
pub created_by: Option<Uuid>,
|
||||
pub created_at: DateTime<Utc>,
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, sqlx::FromRow)]
|
||||
pub struct IssueLabel {
|
||||
pub id: Uuid,
|
||||
pub repo_id: Uuid,
|
||||
pub name: String,
|
||||
pub color: String,
|
||||
pub description: Option<String>,
|
||||
pub created_by: Option<Uuid>,
|
||||
pub created_at: DateTime<Utc>,
|
||||
pub updated_at: DateTime<Utc>,
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
use crate::models::common::State;
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, sqlx::FromRow)]
|
||||
pub struct IssueMilestone {
|
||||
pub id: Uuid,
|
||||
pub repo_id: Uuid,
|
||||
pub title: String,
|
||||
pub description: Option<String>,
|
||||
pub state: State,
|
||||
pub due_at: Option<DateTime<Utc>>,
|
||||
pub closed_at: Option<DateTime<Utc>>,
|
||||
pub created_by: Uuid,
|
||||
pub created_at: DateTime<Utc>,
|
||||
pub updated_at: DateTime<Utc>,
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
use crate::models::common::RelationType;
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, sqlx::FromRow)]
|
||||
pub struct IssuePrRelation {
|
||||
pub id: Uuid,
|
||||
pub issue_id: Uuid,
|
||||
pub pull_request_id: Uuid,
|
||||
pub relation_type: RelationType,
|
||||
pub created_by: Option<Uuid>,
|
||||
pub created_at: DateTime<Utc>,
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
use sqlx::PgPool;
|
||||
use uuid::Uuid;
|
||||
|
||||
use super::issue::Issue;
|
||||
|
||||
impl Issue {
|
||||
pub async fn find_by_id(pool: &PgPool, id: Uuid) -> Result<Option<Self>, sqlx::Error> {
|
||||
sqlx::query_as::<_, Issue>(
|
||||
"SELECT id, workspace_id, author_id, number, title, body, state, priority, visibility, \
|
||||
locked, milestone_id, closed_by, closed_at, due_at, created_at, updated_at, deleted_at \
|
||||
FROM issue WHERE id = $1 AND deleted_at IS NULL",
|
||||
)
|
||||
.bind(id)
|
||||
.fetch_optional(pool)
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn find_by_number(
|
||||
pool: &PgPool,
|
||||
workspace_id: Uuid,
|
||||
number: i64,
|
||||
) -> Result<Option<Self>, sqlx::Error> {
|
||||
sqlx::query_as::<_, Issue>(
|
||||
"SELECT id, workspace_id, author_id, number, title, body, state, priority, visibility, \
|
||||
locked, milestone_id, closed_by, closed_at, due_at, created_at, updated_at, deleted_at \
|
||||
FROM issue WHERE workspace_id = $1 AND number = $2 AND deleted_at IS NULL",
|
||||
)
|
||||
.bind(workspace_id)
|
||||
.bind(number)
|
||||
.fetch_optional(pool)
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn next_number<'e, E>(executor: E, workspace_id: Uuid) -> Result<i64, sqlx::Error>
|
||||
where
|
||||
E: sqlx::PgExecutor<'e>,
|
||||
{
|
||||
sqlx::query_scalar("SELECT COALESCE(MAX(number), 0) + 1 FROM issue WHERE workspace_id = $1")
|
||||
.bind(workspace_id)
|
||||
.fetch_one(executor)
|
||||
.await
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
use crate::models::common::TargetType;
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, sqlx::FromRow)]
|
||||
pub struct IssueReaction {
|
||||
pub id: Uuid,
|
||||
pub issue_id: Uuid,
|
||||
pub user_id: Uuid,
|
||||
pub content: String,
|
||||
pub target_type: TargetType,
|
||||
pub target_id: Option<Uuid>,
|
||||
pub created_at: DateTime<Utc>,
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, sqlx::FromRow)]
|
||||
pub struct IssueReminder {
|
||||
pub id: Uuid,
|
||||
pub issue_id: Uuid,
|
||||
pub user_id: Uuid,
|
||||
pub remind_at: DateTime<Utc>,
|
||||
pub message: Option<String>,
|
||||
pub sent_at: Option<DateTime<Utc>>,
|
||||
pub canceled_at: Option<DateTime<Utc>>,
|
||||
pub created_at: DateTime<Utc>,
|
||||
pub updated_at: DateTime<Utc>,
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
use crate::models::common::RelationType;
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, sqlx::FromRow)]
|
||||
pub struct IssueRepoRelation {
|
||||
pub id: Uuid,
|
||||
pub issue_id: Uuid,
|
||||
pub repo_id: Uuid,
|
||||
pub relation_type: RelationType,
|
||||
pub created_by: Option<Uuid>,
|
||||
pub created_at: DateTime<Utc>,
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, sqlx::FromRow)]
|
||||
pub struct IssueStats {
|
||||
pub issue_id: Uuid,
|
||||
pub comments_count: i64,
|
||||
pub reactions_count: i64,
|
||||
pub assignees_count: i64,
|
||||
pub labels_count: i64,
|
||||
pub subscribers_count: i64,
|
||||
pub last_commented_at: Option<DateTime<Utc>>,
|
||||
pub updated_at: DateTime<Utc>,
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, sqlx::FromRow)]
|
||||
pub struct IssueSubscriber {
|
||||
pub id: Uuid,
|
||||
pub issue_id: Uuid,
|
||||
pub user_id: Uuid,
|
||||
pub reason: String,
|
||||
pub muted: bool,
|
||||
pub created_at: DateTime<Utc>,
|
||||
pub updated_at: DateTime<Utc>,
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, sqlx::FromRow)]
|
||||
pub struct IssueTemplate {
|
||||
pub id: Uuid,
|
||||
pub repo_id: Uuid,
|
||||
pub name: String,
|
||||
pub description: Option<String>,
|
||||
pub title_template: Option<String>,
|
||||
pub body_template: String,
|
||||
pub labels: Vec<String>,
|
||||
pub active: bool,
|
||||
pub created_by: Uuid,
|
||||
pub created_at: DateTime<Utc>,
|
||||
pub updated_at: DateTime<Utc>,
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
pub mod issue;
|
||||
pub mod issue_assignees;
|
||||
pub mod issue_comments;
|
||||
pub mod issue_commit_relations;
|
||||
pub mod issue_events;
|
||||
pub mod issue_label_relations;
|
||||
pub mod issue_labels;
|
||||
pub mod issue_milestones;
|
||||
pub mod issue_pr_relations;
|
||||
pub mod issue_queries;
|
||||
pub mod issue_reaction;
|
||||
pub mod issue_reminder;
|
||||
pub mod issue_repo_relations;
|
||||
pub mod issue_stats;
|
||||
pub mod issue_subscribers;
|
||||
pub mod issue_templates;
|
||||
|
||||
pub use issue::Issue;
|
||||
pub use issue_assignees::IssueAssignee;
|
||||
pub use issue_comments::IssueComment;
|
||||
pub use issue_commit_relations::IssueCommitRelation;
|
||||
pub use issue_events::IssueEvent;
|
||||
pub use issue_label_relations::IssueLabelRelation;
|
||||
pub use issue_labels::IssueLabel;
|
||||
pub use issue_milestones::IssueMilestone;
|
||||
pub use issue_pr_relations::IssuePrRelation;
|
||||
pub use issue_reaction::IssueReaction;
|
||||
pub use issue_reminder::IssueReminder;
|
||||
pub use issue_repo_relations::IssueRepoRelation;
|
||||
pub use issue_stats::IssueStats;
|
||||
pub use issue_subscribers::IssueSubscriber;
|
||||
pub use issue_templates::IssueTemplate;
|
||||
Reference in New Issue
Block a user