Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
added new model confirmation tests
Browse files Browse the repository at this point in the history
+ title name change
  • Loading branch information
thesuzerain committed Nov 26, 2023
1 parent 2f8e6ba commit 8fab4f8
Show file tree
Hide file tree
Showing 47 changed files with 525 additions and 325 deletions.
10 changes: 5 additions & 5 deletions src/database/models/collection_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const COLLECTIONS_NAMESPACE: &str = "collections";
pub struct CollectionBuilder {
pub collection_id: CollectionId,
pub user_id: UserId,
pub title: String,
pub name: String,
pub description: String,
pub status: CollectionStatus,
pub projects: Vec<ProjectId>,
Expand All @@ -25,7 +25,7 @@ impl CollectionBuilder {
) -> Result<CollectionId, DatabaseError> {
let collection_struct = Collection {
id: self.collection_id,
title: self.title,
name: self.name,
user_id: self.user_id,
description: self.description,
created: Utc::now(),
Expand All @@ -44,7 +44,7 @@ impl CollectionBuilder {
pub struct Collection {
pub id: CollectionId,
pub user_id: UserId,
pub title: String,
pub name: String,
pub description: String,
pub created: DateTime<Utc>,
pub updated: DateTime<Utc>,
Expand Down Expand Up @@ -72,7 +72,7 @@ impl Collection {
",
self.id as CollectionId,
self.user_id as UserId,
&self.title,
&self.name,
&self.description,
self.created,
self.icon_url.as_ref(),
Expand Down Expand Up @@ -209,7 +209,7 @@ impl Collection {
Collection {
id: CollectionId(id),
user_id: UserId(m.user_id),
title: m.title.clone(),
name: m.title.clone(),
description: m.description.clone(),
icon_url: m.icon_url.clone(),
color: m.color.map(|x| x as u32),
Expand Down
2 changes: 1 addition & 1 deletion src/database/models/notification_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub struct Notification {
pub struct NotificationAction {
pub id: NotificationActionId,
pub notification_id: NotificationId,
pub title: String,
pub name: String,
pub action_route_method: String,
pub action_route: String,
}
Expand Down
14 changes: 7 additions & 7 deletions src/database/models/organization_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub struct Organization {
pub id: OrganizationId,

/// The title (and slug) of the organization
pub title: String,
pub name: String,

/// The associated team of the organization
pub team_id: TeamId,
Expand All @@ -40,7 +40,7 @@ impl Organization {
VALUES ($1, $2, $3, $4, $5, $6)
",
self.id.0,
self.title,
self.name,
self.team_id as TeamId,
self.description,
self.icon_url,
Expand Down Expand Up @@ -149,7 +149,7 @@ impl Organization {
{
remaining_strings.retain(|x| {
&to_base62(organization.id.0 as u64) != x
&& organization.title.to_lowercase() != x.to_lowercase()
&& organization.name.to_lowercase() != x.to_lowercase()
});
found_organizations.push(organization);
continue;
Expand Down Expand Up @@ -181,7 +181,7 @@ impl Organization {
.try_filter_map(|e| async {
Ok(e.right().map(|m| Organization {
id: OrganizationId(m.id),
title: m.title,
name: m.title,
team_id: TeamId(m.team_id),
description: m.description,
icon_url: m.icon_url,
Expand All @@ -203,7 +203,7 @@ impl Organization {
redis
.set(
ORGANIZATIONS_TITLES_NAMESPACE,
&organization.title.to_lowercase(),
&organization.name.to_lowercase(),
&organization.id.0.to_string(),
None,
)
Expand Down Expand Up @@ -240,7 +240,7 @@ impl Organization {
if let Some(result) = result {
Ok(Some(Organization {
id: OrganizationId(result.id),
title: result.title,
name: result.title,
team_id: TeamId(result.team_id),
description: result.description,
icon_url: result.icon_url,
Expand Down Expand Up @@ -279,7 +279,7 @@ impl Organization {
super::project_item::Project::remove(project_id, transaction, redis).await?;
}

Organization::clear_cache(id, Some(organization.title), redis).await?;
Organization::clear_cache(id, Some(organization.name), redis).await?;

sqlx::query!(
"
Expand Down
18 changes: 9 additions & 9 deletions src/database/models/project_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl DonationUrl {
pub struct GalleryItem {
pub image_url: String,
pub featured: bool,
pub title: Option<String>,
pub name: Option<String>,
pub description: Option<String>,
pub created: DateTime<Utc>,
pub ordering: i64,
Expand All @@ -65,7 +65,7 @@ impl GalleryItem {
project_id: ProjectId,
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
) -> Result<(), sqlx::error::Error> {
let (project_ids, image_urls, featureds, titles, descriptions, orderings): (
let (project_ids, image_urls, featureds, names, descriptions, orderings): (
Vec<_>,
Vec<_>,
Vec<_>,
Expand All @@ -79,7 +79,7 @@ impl GalleryItem {
project_id.0,
gi.image_url,
gi.featured,
gi.title,
gi.name,
gi.description,
gi.ordering,
)
Expand All @@ -95,7 +95,7 @@ impl GalleryItem {
&project_ids[..],
&image_urls[..],
&featureds[..],
&titles[..] as &[Option<String>],
&names[..] as &[Option<String>],
&descriptions[..] as &[Option<String>],
&orderings[..]
)
Expand Down Expand Up @@ -143,7 +143,7 @@ pub struct ProjectBuilder {
pub project_id: ProjectId,
pub team_id: TeamId,
pub organization_id: Option<OrganizationId>,
pub title: String,
pub name: String,
pub description: String,
pub body: String,
pub icon_url: Option<String>,
Expand Down Expand Up @@ -174,7 +174,7 @@ impl ProjectBuilder {
id: self.project_id,
team_id: self.team_id,
organization_id: self.organization_id,
title: self.title,
name: self.name,
description: self.description,
body: self.body,
body_url: None,
Expand Down Expand Up @@ -245,7 +245,7 @@ pub struct Project {
pub id: ProjectId,
pub team_id: TeamId,
pub organization_id: Option<OrganizationId>,
pub title: String,
pub name: String,
pub description: String,
pub body: String,
pub body_url: Option<String>,
Expand Down Expand Up @@ -297,7 +297,7 @@ impl Project {
",
self.id as ProjectId,
self.team_id as TeamId,
&self.title,
&self.name,
&self.description,
&self.body,
self.published,
Expand Down Expand Up @@ -612,7 +612,7 @@ impl Project {
id: ProjectId(id),
team_id: TeamId(m.team_id),
organization_id: m.organization_id.map(OrganizationId),
title: m.title.clone(),
name: m.title.clone(),
description: m.description.clone(),
downloads: m.downloads,
body_url: None,
Expand Down
1 change: 1 addition & 0 deletions src/models/v2/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
// Legacy models from V2, where its useful to keep the struct for rerouting/conversion
pub mod projects;
pub mod notifications;
54 changes: 54 additions & 0 deletions src/models/v2/notifications.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
use chrono::{DateTime, Utc};
use serde::{Serialize, Deserialize};

use crate::models::{ids::{NotificationId, UserId}, notifications::{NotificationBody, Notification, NotificationAction}};

#[derive(Serialize, Deserialize)]
pub struct LegacyNotification {
pub id: NotificationId,
pub user_id: UserId,
pub read: bool,
pub created: DateTime<Utc>,
pub body: NotificationBody,

// DEPRECATED: use body field instead
#[serde(rename = "type")]
pub type_: Option<String>,
pub title: String,
pub text: String,
pub link: String,
pub actions: Vec<LegacyNotificationAction>,
}

#[derive(Serialize, Deserialize, Clone)]
pub struct LegacyNotificationAction {
pub title: String,
/// The route to call when this notification action is called. Formatted HTTP Method, route
pub action_route: (String, String),
}

impl LegacyNotification {
pub fn from(notification : Notification) -> Self {
Self {
id: notification.id,
user_id: notification.user_id,
read: notification.read,
created: notification.created,
body: notification.body,
type_: notification.type_,
title: notification.name,
text: notification.text,
link: notification.link,
actions: notification.actions.into_iter().map(LegacyNotificationAction::from).collect()
}
}
}

impl LegacyNotificationAction {
pub fn from(notification_action : NotificationAction) -> Self {
Self {
title: notification_action.name,
action_route: notification_action.action_route
}
}
}
31 changes: 27 additions & 4 deletions src/models/v2/projects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::database::models::{version_item, DatabaseError};
use crate::database::redis::RedisPool;
use crate::models::ids::{ProjectId, VersionId};
use crate::models::projects::{
Dependency, DonationLink, GalleryItem, License, Loader, ModeratorMessage, MonetizationStatus,
Dependency, DonationLink, License, Loader, ModeratorMessage, MonetizationStatus,
Project, ProjectStatus, Version, VersionFile, VersionStatus, VersionType,
};
use crate::models::threads::ThreadId;
Expand Down Expand Up @@ -57,7 +57,7 @@ pub struct LegacyProject {
pub wiki_url: Option<String>,
pub discord_url: Option<String>,
pub donation_urls: Option<Vec<DonationLink>>,
pub gallery: Vec<GalleryItem>,
pub gallery: Vec<LegacyGalleryItem>,
pub color: Option<u32>,
pub thread_id: ThreadId,
pub monetization_status: MonetizationStatus,
Expand Down Expand Up @@ -129,7 +129,7 @@ impl LegacyProject {
project_type,
team: data.team,
organization: data.organization,
title: data.title,
title: data.name,
description: data.description,
body: data.body,
body_url: data.body_url,
Expand All @@ -153,7 +153,7 @@ impl LegacyProject {
wiki_url: data.wiki_url,
discord_url: data.discord_url,
donation_urls: data.donation_urls,
gallery: data.gallery,
gallery: data.gallery.into_iter().map(LegacyGalleryItem::from).collect(),
color: data.color,
thread_id: data.thread_id,
monetization_status: data.monetization_status,
Expand Down Expand Up @@ -307,3 +307,26 @@ impl From<Version> for LegacyVersion {
}
}
}

#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct LegacyGalleryItem {
pub url: String,
pub featured: bool,
pub name : Option<String>,
pub description: Option<String>,
pub created: DateTime<Utc>,
pub ordering: i64,
}

impl LegacyGalleryItem {
fn from(data: crate::models::projects::GalleryItem) -> Self {
Self {
url: data.url,
featured: data.featured,
name: data.name,
description: data.description,
created: data.created,
ordering: data.ordering,
}
}
}
4 changes: 2 additions & 2 deletions src/models/v3/collections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub struct Collection {
/// The person that has ownership of this collection.
pub user: UserId,
/// The title or name of the collection.
pub title: String,
pub name: String,
/// A short description of the collection.
pub description: String,

Expand Down Expand Up @@ -48,7 +48,7 @@ impl From<database::models::Collection> for Collection {
id: c.id.into(),
user: c.user_id.into(),
created: c.created,
title: c.title,
name: c.name,
description: c.description,
updated: c.updated,
projects: c.projects.into_iter().map(|x| x.into()).collect(),
Expand Down
Loading

0 comments on commit 8fab4f8

Please sign in to comment.