Skip to content

Commit

Permalink
feat: add events groups
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeDecMeetsMore committed Dec 4, 2024
1 parent 4d8d008 commit bbf08d8
Show file tree
Hide file tree
Showing 16 changed files with 119 additions and 9 deletions.
1 change: 1 addition & 0 deletions crates/api/src/event/create_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ impl UseCase for CreateEventUseCase {
account_id: self.user.account_id.clone(),
reminders: self.reminders.clone(),
service_id: self.service_id.clone(),
group_id: None,
metadata: self.metadata.clone(),
};

Expand Down
1 change: 1 addition & 0 deletions crates/domain/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ pub struct CalendarEvent {
pub account_id: ID,
pub reminders: Vec<CalendarEventReminder>,
pub service_id: Option<ID>,
pub group_id: Option<ID>,
pub metadata: Option<serde_json::Value>,
}

Expand Down
16 changes: 16 additions & 0 deletions crates/domain/src/event_group.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use serde::{Deserialize, Serialize};
use ts_rs::TS;

use crate::ID;

/// Group of calendar events
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, TS)]
#[serde(rename_all = "camelCase")]
#[ts(export)]
pub struct EventGroup {
pub id: ID,
pub calendar_id: ID,
pub parent_id: Option<String>,
pub external_id: Option<String>,
pub event_ids: Vec<ID>,
}
1 change: 1 addition & 0 deletions crates/domain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pub mod booking_slots;
mod calendar;
mod date;
mod event;
pub mod event_group;
mod event_instance;
pub mod providers;
mod reminder;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions crates/infra/migrations/20241204000000_add_events_groups_table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
-- Create the `events_groups` table
CREATE TABLE IF NOT EXISTS events_groups (
group_uid uuid PRIMARY KEY DEFAULT uuid_generate_v4() NOT NULL,
calendar_uid uuid NOT NULL REFERENCES calendars(calendar_uid) ON DELETE CASCADE,
/*
parent_id is only useful for linking this event to an external object outside Nittei ecosystem
it's indexed, it's not a foreign key, and it's a string as the external object's id can have any format
*/
parent_id text,
external_id text
);

-- Add the `group_id` column to the `calendar_events` table
ALTER TABLE
calendar_events
ADD
COLUMN IF NOT EXISTS group_uid uuid REFERENCES events_groups(group_uid) ON DELETE NO ACTION;

-- Add a unique constraint on `external_id` in `events_groups`
ALTER TABLE
events_groups
ADD
CONSTRAINT events_groups__external_id__unique UNIQUE (external_id);

-- Add an index on `parent_id` in `events_groups`
CREATE INDEX IF NOT EXISTS events_groups__parent_id_idx ON events_groups (parent_id);

-- Add an index on `group_id` in `calendar_events`
CREATE INDEX IF NOT EXISTS calendar_events__group_uid_idx ON calendar_events (group_uid);
2 changes: 2 additions & 0 deletions crates/infra/src/repos/event/calendar_event/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ struct EventRaw {
exdates: Vec<DateTime<Utc>>,
reminders: Option<Value>,
service_uid: Option<Uuid>,
group_uid: Option<Uuid>,
metadata: Value,
}

Expand Down Expand Up @@ -101,6 +102,7 @@ impl TryFrom<EventRaw> for CalendarEvent {
exdates: e.exdates,
reminders,
service_id: e.service_uid.map(|id| id.into()),
group_id: e.group_uid.map(|id| id.into()),
metadata: serde_json::from_value(e.metadata)?,
})
}
Expand Down

0 comments on commit bbf08d8

Please sign in to comment.