Merge pull request #208 from BillionClaw/clawoss/fix/calendar-owner-id-uuid-type
This commit is contained in:
@@ -31,7 +31,7 @@ pub struct Calendar {
|
|||||||
name: String,
|
name: String,
|
||||||
|
|
||||||
/// ID of the user who owns this calendar
|
/// ID of the user who owns this calendar
|
||||||
owner_id: String,
|
owner_id: Uuid,
|
||||||
|
|
||||||
/// Optional description of the calendar
|
/// Optional description of the calendar
|
||||||
description: Option<String>,
|
description: Option<String>,
|
||||||
@@ -61,7 +61,7 @@ impl Calendar {
|
|||||||
*/
|
*/
|
||||||
pub fn new(
|
pub fn new(
|
||||||
name: String,
|
name: String,
|
||||||
owner_id: String,
|
owner_id: Uuid,
|
||||||
description: Option<String>,
|
description: Option<String>,
|
||||||
color: Option<String>,
|
color: Option<String>,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
@@ -74,14 +74,6 @@ impl Calendar {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
if owner_id.is_empty() {
|
|
||||||
return Err(DomainError::new(
|
|
||||||
ErrorKind::InvalidInput,
|
|
||||||
"Calendar",
|
|
||||||
"Owner ID cannot be empty",
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(color_str) = &color {
|
if let Some(color_str) = &color {
|
||||||
Self::validate_color(color_str)?;
|
Self::validate_color(color_str)?;
|
||||||
}
|
}
|
||||||
@@ -116,7 +108,7 @@ impl Calendar {
|
|||||||
pub fn with_id(
|
pub fn with_id(
|
||||||
id: Uuid,
|
id: Uuid,
|
||||||
name: String,
|
name: String,
|
||||||
owner_id: String,
|
owner_id: Uuid,
|
||||||
description: Option<String>,
|
description: Option<String>,
|
||||||
color: Option<String>,
|
color: Option<String>,
|
||||||
created_at: DateTime<Utc>,
|
created_at: DateTime<Utc>,
|
||||||
@@ -131,14 +123,6 @@ impl Calendar {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
if owner_id.is_empty() {
|
|
||||||
return Err(DomainError::new(
|
|
||||||
ErrorKind::InvalidInput,
|
|
||||||
"Calendar",
|
|
||||||
"Owner ID cannot be empty",
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(color_str) = &color {
|
if let Some(color_str) = &color {
|
||||||
Self::validate_color(color_str)?;
|
Self::validate_color(color_str)?;
|
||||||
}
|
}
|
||||||
@@ -168,7 +152,7 @@ impl Calendar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the ID of the user who owns this calendar
|
/// Returns the ID of the user who owns this calendar
|
||||||
pub fn owner_id(&self) -> &str {
|
pub fn owner_id(&self) -> &Uuid {
|
||||||
&self.owner_id
|
&self.owner_id
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -297,8 +281,8 @@ impl Calendar {
|
|||||||
* @param user_id ID of the user to check ownership against
|
* @param user_id ID of the user to check ownership against
|
||||||
* @return true if the calendar belongs to the user, false otherwise
|
* @return true if the calendar belongs to the user, false otherwise
|
||||||
*/
|
*/
|
||||||
pub fn belongs_to(&self, user_id: &str) -> bool {
|
pub fn belongs_to(&self, user_id: &Uuid) -> bool {
|
||||||
self.owner_id == user_id
|
self.owner_id == *user_id
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -316,15 +300,17 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_init() {
|
fn test_init() {
|
||||||
let res = Calendar::new("Name".to_string(), "ID".to_string(), None, None);
|
let owner_id = Uuid::new_v4();
|
||||||
|
let res = Calendar::new("Name".to_string(), owner_id, None, None);
|
||||||
assert!(res.is_ok());
|
assert!(res.is_ok());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_init_color_rgb() {
|
fn test_init_color_rgb() {
|
||||||
|
let owner_id = Uuid::new_v4();
|
||||||
let res = Calendar::new(
|
let res = Calendar::new(
|
||||||
"Name".to_string(),
|
"Name".to_string(),
|
||||||
"ID".to_string(),
|
owner_id,
|
||||||
None,
|
None,
|
||||||
Some("#84FFa9".to_string()),
|
Some("#84FFa9".to_string()),
|
||||||
);
|
);
|
||||||
@@ -334,9 +320,10 @@ mod tests {
|
|||||||
/// Format as used by the android DAVx app
|
/// Format as used by the android DAVx app
|
||||||
#[test]
|
#[test]
|
||||||
fn test_init_color_rgba() {
|
fn test_init_color_rgba() {
|
||||||
|
let owner_id = Uuid::new_v4();
|
||||||
let res = Calendar::new(
|
let res = Calendar::new(
|
||||||
"Name".to_string(),
|
"Name".to_string(),
|
||||||
"ID".to_string(),
|
owner_id,
|
||||||
None,
|
None,
|
||||||
Some("#abcdef51".to_string()),
|
Some("#abcdef51".to_string()),
|
||||||
);
|
);
|
||||||
@@ -345,9 +332,10 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_init_bad_color_1() {
|
fn test_init_bad_color_1() {
|
||||||
|
let owner_id = Uuid::new_v4();
|
||||||
let res = Calendar::new(
|
let res = Calendar::new(
|
||||||
"Name".to_string(),
|
"Name".to_string(),
|
||||||
"ID".to_string(),
|
owner_id,
|
||||||
None,
|
None,
|
||||||
Some("foo".to_string()),
|
Some("foo".to_string()),
|
||||||
);
|
);
|
||||||
@@ -356,9 +344,10 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_init_bad_color_2() {
|
fn test_init_bad_color_2() {
|
||||||
|
let owner_id = Uuid::new_v4();
|
||||||
let res = Calendar::new(
|
let res = Calendar::new(
|
||||||
"Name".to_string(),
|
"Name".to_string(),
|
||||||
"ID".to_string(),
|
owner_id,
|
||||||
None,
|
None,
|
||||||
Some("#xxjjff".to_string()),
|
Some("#xxjjff".to_string()),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ impl CalendarStoragePort for CalendarStorageAdapter {
|
|||||||
dto: CreateCalendarDto,
|
dto: CreateCalendarDto,
|
||||||
owner_id: Uuid,
|
owner_id: Uuid,
|
||||||
) -> Result<CalendarDto, DomainError> {
|
) -> Result<CalendarDto, DomainError> {
|
||||||
let calendar = Calendar::new(dto.name, owner_id.to_string(), dto.description, dto.color)?;
|
let calendar = Calendar::new(dto.name, owner_id, dto.description, dto.color)?;
|
||||||
|
|
||||||
let created = self.calendar_repository.create_calendar(calendar).await?;
|
let created = self.calendar_repository.create_calendar(calendar).await?;
|
||||||
Ok(CalendarDto::from(created))
|
Ok(CalendarDto::from(created))
|
||||||
|
|||||||
Reference in New Issue
Block a user