Skip to content

Commit

Permalink
feat(group): final fixes & more tests (#166)
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeDecMeetsMore authored Dec 5, 2024
1 parent 47e03ac commit 56eebfc
Show file tree
Hide file tree
Showing 19 changed files with 104 additions and 41 deletions.
4 changes: 4 additions & 0 deletions clients/javascript/lib/gen_types/CalendarEventDTO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ export type CalendarEventDTO = {
* UUID of the user
*/
userId: ID
/**
* Optional group ID
*/
groupId: ID | null
/**
* List of reminders
*/
Expand Down
6 changes: 6 additions & 0 deletions clients/javascript/lib/gen_types/CreateEventRequestBody.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ export type CreateEventRequestBody = {
* This is automatically set when the event is created from a service
*/
serviceId?: ID
/**
* Optional group UUID
* Allows to group events together (e.g. a project, a team, etc.)
* Default is None
*/
groupId?: ID
/**
* Optional metadata (e.g. {"key": "value"})
*/
Expand Down
4 changes: 0 additions & 4 deletions clients/javascript/lib/gen_types/EventGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,4 @@ export type EventGroup = {
* It allows to link a group of events to an outside entity
*/
externalId: string | null
/**
* List of event IDs in the group
*/
eventIds: Array<ID>
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export type SearchEventsRequestBody = {
/**
* Optional query on group ID
*/
groupId?: IDQuery
groupId?: ID
/**
* Optional query on start time - "lower than or equal", or "great than or equal" (UTC)
*/
Expand Down
6 changes: 6 additions & 0 deletions clients/javascript/lib/gen_types/UpdateEventRequestBody.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ export type UpdateEventRequestBody = {
* Optional service UUID
*/
serviceId?: ID
/**
* Optional group UUID
* Allows to group events together (e.g. a project, a team, etc.)
* Default is None
*/
groupId?: ID
/**
* Optional list of exclusion dates for the recurrence rule
*/
Expand Down
24 changes: 24 additions & 0 deletions clients/javascript/tests/calendarEvent.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,30 @@ describe('CalendarEvent API', () => {
expect(res.events.length).toBe(1)
expect(res.events[0].id).toBe(metadataEventId1)
})

it('should be search events on event group id', async () => {
const group = await adminClient.eventGroups.create(userId, {
calendarId,
})

const resCreate = await adminClient.events.create(userId, {
calendarId,
duration: 1000,
startTime: new Date(1000),
groupId: group.eventGroup.id,
})
expect(resCreate.event).toBeDefined()
expect(resCreate.event.calendarId).toBe(calendarId)

const resSearch = await adminClient.events.searchEvents({
userId,
groupId: group.eventGroup.id,
})

expect(resSearch.events.length).toBe(1)
expect(resSearch.events[0].id).toBe(resCreate.event.id)
expect(resSearch.events[0].groupId).toBe(group.eventGroup.id)
})
})

afterAll(async () => {
Expand Down
6 changes: 5 additions & 1 deletion clients/rust/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ impl CalendarEventClient {
recurrence: input.recurrence,
reminders: input.reminders,
service_id: input.service_id,
// TODO
group_id: None,
metadata: input.metadata,
};

Expand Down Expand Up @@ -168,12 +170,14 @@ impl CalendarEventClient {
parent_id: input.parent_id,
external_id: input.external_id,
busy: input.busy,
start_time: input.start_time,
duration: input.duration,
exdates: input.exdates,
recurrence: input.rrule_options,
reminders: input.reminders,
service_id: input.service_id,
start_time: input.start_time,
// TODO
group_id: None,
metadata: input.metadata,
};
self.base
Expand Down
5 changes: 4 additions & 1 deletion crates/api/src/event/create_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub async fn create_event_admin_controller(
recurrence: body.recurrence,
reminders: body.reminders,
service_id: body.service_id,
group_id: body.group_id,
metadata: body.metadata,
};

Expand Down Expand Up @@ -80,6 +81,7 @@ pub async fn create_event_controller(
user,
reminders: body.reminders,
service_id: body.service_id,
group_id: body.group_id,
metadata: body.metadata,
};

Expand All @@ -106,6 +108,7 @@ pub struct CreateEventUseCase {
pub recurrence: Option<RRuleOptions>,
pub reminders: Vec<CalendarEventReminder>,
pub service_id: Option<ID>,
pub group_id: Option<ID>,
pub metadata: Option<serde_json::Value>,
}

Expand Down Expand Up @@ -183,7 +186,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,
group_id: self.group_id.clone(),
metadata: self.metadata.clone(),
};

Expand Down
18 changes: 9 additions & 9 deletions crates/api/src/event/search_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub struct SearchEventsUseCase {
pub parent_id: Option<IDQuery>,

/// Optional query on the group ID
pub group_id: Option<IDQuery>,
pub group_id: Option<ID>,

/// Optional query on start time - "lower than or equal", or "great than or equal" (UTC)
pub start_time: Option<DateTimeQuery>,
Expand Down Expand Up @@ -143,14 +143,14 @@ impl UseCase for SearchEventsUseCase {
.events
.search_events(SearchEventsParams {
user_id: self.user_id.clone(),
calendar_ids: self.calendar_ids.clone(),
parent_id: self.parent_id.clone(),
group_id: self.group_id.clone(),
start_time: self.start_time.clone(),
end_time: self.end_time.clone(),
status: self.status.clone(),
updated_at: self.updated_at.clone(),
metadata: self.metadata.clone(),
calendar_ids: self.calendar_ids.take(),
parent_id: self.parent_id.take(),
group_id: self.group_id.take(),
start_time: self.start_time.take(),
end_time: self.end_time.take(),
status: self.status.take(),
updated_at: self.updated_at.take(),
metadata: self.metadata.take(),
})
.await;

Expand Down
8 changes: 8 additions & 0 deletions crates/api/src/event/update_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ pub async fn update_event_admin_controller(
recurrence: body.recurrence,
busy: body.busy,
service_id: body.service_id,
group_id: body.group_id,
exdates: body.exdates,
metadata: body.metadata,
};
Expand Down Expand Up @@ -89,6 +90,7 @@ pub async fn update_event_controller(
recurrence: body.recurrence,
busy: body.busy,
service_id: body.service_id,
group_id: body.group_id,
exdates: body.exdates,
metadata: body.metadata,
};
Expand Down Expand Up @@ -117,6 +119,7 @@ pub struct UpdateEventUseCase {
pub reminders: Option<Vec<CalendarEventReminder>>,
pub recurrence: Option<RRuleOptions>,
pub service_id: Option<ID>,
pub group_id: Option<ID>,
pub exdates: Option<Vec<DateTime<Utc>>>,
pub metadata: Option<serde_json::Value>,
}
Expand Down Expand Up @@ -173,6 +176,7 @@ impl UseCase for UpdateEventUseCase {
exdates,
reminders,
service_id,
group_id,
metadata,
} = self;

Expand Down Expand Up @@ -279,6 +283,10 @@ impl UseCase for UpdateEventUseCase {
e.external_id.clone_from(external_id);
}

if group_id.is_some() {
e.group_id.clone_from(group_id);
}

if location.is_some() {
e.location.clone_from(location);
}
Expand Down
1 change: 0 additions & 1 deletion crates/api/src/event_group/create_event_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ impl UseCase for CreateEventGroupUseCase {
calendar_id: calendar.id.clone(),
user_id: self.user.id.clone(),
account_id: self.user.account_id.clone(),
event_ids: vec![],
};

ctx.repos.event_groups.insert(&g).await?;
Expand Down
16 changes: 15 additions & 1 deletion crates/api_structs/src/event/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@ pub mod create_event {
#[ts(optional)]
pub service_id: Option<ID>,

/// Optional group UUID
/// Allows to group events together (e.g. a project, a team, etc.)
/// Default is None
#[serde(default)]
#[ts(optional)]
pub group_id: Option<ID>,

/// Optional metadata (e.g. {"key": "value"})
#[serde(default)]
#[ts(optional)]
Expand Down Expand Up @@ -270,7 +277,7 @@ pub mod search_events {

/// Optional query on group ID
#[ts(optional)]
pub group_id: Option<IDQuery>,
pub group_id: Option<ID>,

/// Optional query on start time - "lower than or equal", or "great than or equal" (UTC)
#[ts(optional)]
Expand Down Expand Up @@ -421,6 +428,13 @@ pub mod update_event {
#[ts(optional)]
pub service_id: Option<ID>,

/// Optional group UUID
/// Allows to group events together (e.g. a project, a team, etc.)
/// Default is None
#[serde(default)]
#[ts(optional)]
pub group_id: Option<ID>,

/// Optional list of exclusion dates for the recurrence rule
#[serde(default)]
#[ts(optional, type = "Array<Date>")]
Expand Down
4 changes: 4 additions & 0 deletions crates/api_structs/src/event/dtos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ pub struct CalendarEventDTO {
/// UUID of the user
pub user_id: ID,

/// Optional group ID
pub group_id: Option<ID>,

/// List of reminders
pub reminders: Vec<CalendarEventReminder>,

Expand Down Expand Up @@ -105,6 +108,7 @@ impl CalendarEventDTO {
exdates: event.exdates,
calendar_id: event.calendar_id,
user_id: event.user_id,
group_id: event.group_id,
reminders: event.reminders,
metadata: event.metadata,
}
Expand Down
3 changes: 0 additions & 3 deletions crates/domain/src/event_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,4 @@ pub struct EventGroup {
/// External ID - this is an ID external to the system
/// It allows to link a group of events to an outside entity
pub external_id: Option<String>,

/// List of event IDs in the group
pub event_ids: Vec<ID>,
}

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.

3 changes: 2 additions & 1 deletion crates/infra/src/repos/event/calendar_event/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ pub struct MostRecentCreatedServiceEvents {
pub created: Option<i64>,
}

#[derive(Debug, Clone)]
pub struct SearchEventsParams {
pub user_id: ID,
pub calendar_ids: Option<Vec<ID>>,
pub parent_id: Option<IDQuery>,
pub group_id: Option<IDQuery>,
pub group_id: Option<ID>,
pub start_time: Option<DateTimeQuery>,
pub end_time: Option<DateTimeQuery>,
pub status: Option<Vec<String>>,
Expand Down
Loading

0 comments on commit 56eebfc

Please sign in to comment.