Sanity checked all of V2 route conversions (#803)

* follows

* all v2 routes now either convert or have a comment

* added common structs, clippy

* merge fix

---------

Co-authored-by: Geometrically <18202329+Geometrically@users.noreply.github.com>
This commit is contained in:
Wyatt Verchere
2023-12-19 10:20:32 -08:00
committed by GitHub
parent 9f798559cf
commit d59c522f7f
20 changed files with 636 additions and 78 deletions

View File

@@ -1,5 +1,8 @@
// Legacy models from V2, where its useful to keep the struct for rerouting/conversion
pub mod notifications;
pub mod projects;
pub mod reports;
pub mod search;
pub mod teams;
pub mod threads;
pub mod user;

52
src/models/v2/reports.rs Normal file
View File

@@ -0,0 +1,52 @@
use crate::models::ids::{ReportId, ThreadId, UserId};
use crate::models::reports::{ItemType, Report};
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize)]
pub struct LegacyReport {
pub id: ReportId,
pub report_type: String,
pub item_id: String,
pub item_type: LegacyItemType,
pub reporter: UserId,
pub body: String,
pub created: DateTime<Utc>,
pub closed: bool,
pub thread_id: ThreadId,
}
#[derive(Serialize, Deserialize, Clone)]
#[serde(rename_all = "kebab-case")]
pub enum LegacyItemType {
Project,
Version,
User,
Unknown,
}
impl From<ItemType> for LegacyItemType {
fn from(x: ItemType) -> Self {
match x {
ItemType::Project => LegacyItemType::Project,
ItemType::Version => LegacyItemType::Version,
ItemType::User => LegacyItemType::User,
ItemType::Unknown => LegacyItemType::Unknown,
}
}
}
impl From<Report> for LegacyReport {
fn from(x: Report) -> Self {
LegacyReport {
id: x.id,
report_type: x.report_type,
item_id: x.item_id,
item_type: x.item_type.into(),
reporter: x.reporter,
body: x.body,
created: x.created,
closed: x.closed,
thread_id: x.thread_id,
}
}
}

120
src/models/v2/threads.rs Normal file
View File

@@ -0,0 +1,120 @@
use crate::models::ids::{ImageId, ProjectId, ReportId, ThreadId, ThreadMessageId};
use crate::models::projects::ProjectStatus;
use crate::models::users::{User, UserId};
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize)]
pub struct LegacyThread {
pub id: ThreadId,
#[serde(rename = "type")]
pub type_: LegacyThreadType,
pub project_id: Option<ProjectId>,
pub report_id: Option<ReportId>,
pub messages: Vec<LegacyThreadMessage>,
pub members: Vec<User>,
}
#[derive(Serialize, Deserialize)]
pub struct LegacyThreadMessage {
pub id: ThreadMessageId,
pub author_id: Option<UserId>,
pub body: LegacyMessageBody,
pub created: DateTime<Utc>,
}
#[derive(Serialize, Deserialize, Clone)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum LegacyMessageBody {
Text {
body: String,
#[serde(default)]
private: bool,
replying_to: Option<ThreadMessageId>,
#[serde(default)]
associated_images: Vec<ImageId>,
},
StatusChange {
new_status: ProjectStatus,
old_status: ProjectStatus,
},
ThreadClosure,
ThreadReopen,
Deleted,
}
#[derive(Serialize, Deserialize, Eq, PartialEq, Copy, Clone)]
#[serde(rename_all = "snake_case")]
pub enum LegacyThreadType {
Report,
Project,
DirectMessage,
}
impl From<crate::models::v3::threads::ThreadType> for LegacyThreadType {
fn from(t: crate::models::v3::threads::ThreadType) -> Self {
match t {
crate::models::v3::threads::ThreadType::Report => LegacyThreadType::Report,
crate::models::v3::threads::ThreadType::Project => LegacyThreadType::Project,
crate::models::v3::threads::ThreadType::DirectMessage => {
LegacyThreadType::DirectMessage
}
}
}
}
impl From<crate::models::v3::threads::MessageBody> for LegacyMessageBody {
fn from(b: crate::models::v3::threads::MessageBody) -> Self {
match b {
crate::models::v3::threads::MessageBody::Text {
body,
private,
replying_to,
associated_images,
} => LegacyMessageBody::Text {
body,
private,
replying_to,
associated_images,
},
crate::models::v3::threads::MessageBody::StatusChange {
new_status,
old_status,
} => LegacyMessageBody::StatusChange {
new_status,
old_status,
},
crate::models::v3::threads::MessageBody::ThreadClosure => {
LegacyMessageBody::ThreadClosure
}
crate::models::v3::threads::MessageBody::ThreadReopen => {
LegacyMessageBody::ThreadReopen
}
crate::models::v3::threads::MessageBody::Deleted => LegacyMessageBody::Deleted,
}
}
}
impl From<crate::models::v3::threads::ThreadMessage> for LegacyThreadMessage {
fn from(m: crate::models::v3::threads::ThreadMessage) -> Self {
LegacyThreadMessage {
id: m.id,
author_id: m.author_id,
body: m.body.into(),
created: m.created,
}
}
}
impl From<crate::models::v3::threads::Thread> for LegacyThread {
fn from(t: crate::models::v3::threads::Thread) -> Self {
LegacyThread {
id: t.id,
type_: t.type_.into(),
project_id: t.project_id,
report_id: t.report_id,
messages: t.messages.into_iter().map(|m| m.into()).collect(),
members: t.members,
}
}
}

53
src/models/v2/user.rs Normal file
View File

@@ -0,0 +1,53 @@
use crate::{
auth::AuthProvider,
models::{
ids::UserId,
users::{Badges, Role, UserPayoutData},
},
};
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct LegacyUser {
pub id: UserId,
pub username: String,
pub name: Option<String>,
pub avatar_url: Option<String>,
pub bio: Option<String>,
pub created: DateTime<Utc>,
pub role: Role,
pub badges: Badges,
pub auth_providers: Option<Vec<AuthProvider>>, // this was changed in v3, but not changes ones we want to keep out of v2
pub email: Option<String>,
pub email_verified: Option<bool>,
pub has_password: Option<bool>,
pub has_totp: Option<bool>,
pub payout_data: Option<UserPayoutData>, // this was changed in v3, but not ones we want to keep out of v2
// DEPRECATED. Always returns None
pub github_id: Option<u64>,
}
impl From<crate::models::v3::users::User> for LegacyUser {
fn from(data: crate::models::v3::users::User) -> Self {
Self {
id: data.id,
username: data.username,
name: data.name,
email: data.email,
email_verified: data.email_verified,
avatar_url: data.avatar_url,
bio: data.bio,
created: data.created,
role: data.role,
badges: data.badges,
payout_data: data.payout_data,
auth_providers: data.auth_providers,
has_password: data.has_password,
has_totp: data.has_totp,
github_id: data.github_id,
}
}
}