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

Commit

Permalink
fixed nightly failure
Browse files Browse the repository at this point in the history
  • Loading branch information
thesuzerain committed Nov 3, 2023
1 parent 77617c2 commit f3b8375
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 50 deletions.
14 changes: 9 additions & 5 deletions src/routes/v3/organizations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,15 @@ pub async fn organization_follow(
.insert(&**pool)
.await
.map_err(|e| match e {
DatabaseError::Database(e)
if e.as_database_error()
.is_some_and(|e| e.is_unique_violation()) =>
{
ApiError::InvalidInput("You are already following this organization!".to_string())
DatabaseError::Database(e) => {
if let Some(db_err) = e.as_database_error() {
if db_err.is_unique_violation() {
return ApiError::InvalidInput(
"You are already following this organization!".to_string(),
);
}
}
e.into()
}
e => e.into(),
})?;
Expand Down
80 changes: 40 additions & 40 deletions src/routes/v3/users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,15 @@ pub async fn user_follow(
.insert(&**pool)
.await
.map_err(|e| match e {
DatabaseError::Database(e)
if e.as_database_error()
.is_some_and(|e| e.is_unique_violation()) =>
{
ApiError::InvalidInput("You are already following this user!".to_string())
DatabaseError::Database(e) => {
if let Some(db_err) = e.as_database_error() {
if db_err.is_unique_violation() {
return ApiError::InvalidInput(
"You are already following this user!".to_string(),
);
}
}
e.into()
}
e => e.into(),
})?;
Expand Down Expand Up @@ -143,10 +147,7 @@ pub async fn current_user_feed(
// - Projects created by organizations you follow
// - Versions created by users you follow
// - Versions created by organizations you follow
let event_types = [
EventType::ProjectPublished,
EventType::VersionCreated,
];
let event_types = [EventType::ProjectPublished, EventType::VersionCreated];
let selectors = followed_users
.into_iter()
.flat_map(|follow| {
Expand Down Expand Up @@ -186,39 +187,38 @@ pub async fn current_user_feed(
.await?;

for event in events {
let body =
match event.event_data {
EventData::ProjectPublished {
project_id,
creator_id,
} => authorized_projects.get(&project_id.into()).map(|p| {
FeedItemBody::ProjectPublished {
project_id: project_id.into(),
let body = match event.event_data {
EventData::ProjectPublished {
project_id,
creator_id,
} => authorized_projects.get(&project_id.into()).map(|p| {
FeedItemBody::ProjectPublished {
project_id: project_id.into(),
creator_id: creator_id.into(),
project_title: p.title.clone(),
}
}),
EventData::VersionCreated {
version_id,
creator_id,
} => {
let authorized_version = authorized_versions.get(&version_id.into());
let authorized_project =
authorized_version.and_then(|v| authorized_projects.get(&v.project_id));
if let (Some(authorized_version), Some(authorized_project)) =
(authorized_version, authorized_project)
{
Some(FeedItemBody::VersionCreated {
project_id: authorized_project.id,
version_id: authorized_version.id,
creator_id: creator_id.into(),
project_title: p.title.clone(),
}
}),
EventData::VersionCreated {
version_id,
creator_id,
} => {
let authorized_version = authorized_versions.get(&version_id.into());
let authorized_project =
authorized_version.and_then(|v| authorized_projects.get(&v.project_id));
if let (Some(authorized_version), Some(authorized_project)) =
(authorized_version, authorized_project)
{
Some(FeedItemBody::VersionCreated {
project_id: authorized_project.id,
version_id: authorized_version.id,
creator_id: creator_id.into(),
project_title: authorized_project.title.clone(),
})
} else {
None
}
project_title: authorized_project.title.clone(),
})
} else {
None
}
};
}
};

if let Some(body) = body {
let feed_item = FeedItem {
Expand Down
2 changes: 1 addition & 1 deletion tests/common/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ impl TemporaryDatabase {
.fetch_optional(&pool)
.await
.unwrap();
let needs_update = !dummy_data_update.is_some_and(|d| d == DUMMY_DATA_UPDATE);
let needs_update = !matches!(dummy_data_update, Some(DUMMY_DATA_UPDATE));
if needs_update {
println!("Dummy data updated, so template DB tables will be dropped and re-created");
// Drop all tables in the database so they can be re-created and later filled with updated dummy data
Expand Down
5 changes: 1 addition & 4 deletions tests/feed.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use crate::common::{
asserts::{
assert_feed_contains_project_created,
assert_feed_contains_version_created,
},
asserts::{assert_feed_contains_project_created, assert_feed_contains_version_created},
dummy_data::DummyProjectAlpha,
};
use assert_matches::assert_matches;
Expand Down

0 comments on commit f3b8375

Please sign in to comment.