Skip to content

Commit

Permalink
Refactor db enums to be compatible with java (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
ofux authored Oct 9, 2023
1 parent 145f6b4 commit 8331235
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 7 deletions.
6 changes: 3 additions & 3 deletions api/src/presentation/http/dto/user_profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ impl From<AllocatedTime> for infrastructure::database::enums::AllocatedTime {
fn from(value: AllocatedTime) -> Self {
match value {
AllocatedTime::None => Self::None,
AllocatedTime::LessThanOneDay => Self::Lt1day,
AllocatedTime::OneToThreeDays => Self::_1to3days,
AllocatedTime::MoreThanThreeDays => Self::Gt3days,
AllocatedTime::LessThanOneDay => Self::LessThanOneDay,
AllocatedTime::OneToThreeDays => Self::OneToThreeDays,
AllocatedTime::MoreThanThreeDays => Self::GreaterThanThreeDays,
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion api/tests/update_user_profile_it.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,10 @@ impl<'a> Test<'a> {
(String::from("Typescript"), 0)
]))
);
assert_eq!(user_profile.weekly_allocated_time, AllocatedTime::Lt1day);
assert_eq!(
user_profile.weekly_allocated_time,
AllocatedTime::LessThanOneDay
);
assert_eq!(user_profile.avatar_url, None);
assert_eq!(user_profile.cover.unwrap(), ProfileCover::Cyan);

Expand Down
6 changes: 3 additions & 3 deletions common/infrastructure/src/database/enums/allocated_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use serde::{Deserialize, Serialize};
#[ExistingTypePath = "crate::database::schema::sql_types::AllocatedTime"]
pub enum AllocatedTime {
None,
Lt1day,
_1to3days,
Gt3days,
LessThanOneDay,
OneToThreeDays,
GreaterThanThreeDays,
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use serde::{Deserialize, Serialize};

#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, DbEnum)]
#[ExistingTypePath = "crate::database::schema::sql_types::ProjectVisibility"]
#[DbValueStyle = "SCREAMING_SNAKE_CASE"]
pub enum ProjectVisibility {
Public,
Private,
Expand Down
2 changes: 2 additions & 0 deletions migrations/2023-10-09-113924_refactor-enums-for-java/down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SELECT
1;
18 changes: 18 additions & 0 deletions migrations/2023-10-09-113924_refactor-enums-for-java/up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
ALTER TYPE public.project_visibility
RENAME VALUE 'public' TO 'PUBLIC';


ALTER TYPE public.project_visibility
RENAME VALUE 'private' TO 'PRIVATE';


ALTER TYPE public.allocated_time
RENAME VALUE 'lt1day' TO 'less_than_one_day';


ALTER TYPE public.allocated_time
RENAME VALUE '1to3days' TO 'one_to_three_days';


ALTER TYPE public.allocated_time
RENAME VALUE 'gt3days' TO 'greater_than_three_days';

0 comments on commit 8331235

Please sign in to comment.