...
This commit is contained in:
@@ -126,10 +126,10 @@ pub fn (self CalendarEvent) description(methodname string) string {
|
||||
pub fn (self CalendarEvent) example(methodname string) (string, string) {
|
||||
match methodname {
|
||||
'set' {
|
||||
return '{"calendar_event": {"title": "Team Meeting", "start_time": "2025-01-01T10:00:00Z", "end_time": "2025-01-01T11:00:00Z", "attendees": [], "docs": [], "calendar_id": 1, "status": "published", "is_all_day": false, "is_recurring": false, "recurrence": [], "reminder_mins": [15], "color": "#0000FF", "timezone": "UTC", "locations": []}}', '1'
|
||||
return '{"calendar_event": {"title": "Team Meeting", "start_time": "2025-01-01T10:00:00Z", "end_time": "2025-01-01T11:00:00Z", "attendees": [], "docs": [], "calendar_id": 1, "status": "published", "is_all_day": false, "reminder_mins": [15], "color": "#0000FF", "timezone": "UTC", "locations": []}}', '1'
|
||||
}
|
||||
'get' {
|
||||
return '{"id": 1}', '{"title": "Team Meeting", "start_time": "2025-01-01T10:00:00Z", "end_time": "2025-01-01T11:00:00Z", "attendees": [], "docs": [], "calendar_id": 1, "status": "published", "is_all_day": false, "is_recurring": false, "recurrence": [], "reminder_mins": [15], "color": "#0000FF", "timezone": "UTC", "locations": []}'
|
||||
return '{"id": 1}', '{"title": "Team Meeting", "start_time": "2025-01-01T10:00:00Z", "end_time": "2025-01-01T11:00:00Z", "attendees": [], "docs": [], "calendar_id": 1, "status": "published", "is_all_day": false, "reminder_mins": [15], "color": "#0000FF", "timezone": "UTC", "locations": []}'
|
||||
}
|
||||
'delete' {
|
||||
return '{"id": 1}', 'true'
|
||||
@@ -138,7 +138,7 @@ pub fn (self CalendarEvent) example(methodname string) (string, string) {
|
||||
return '{"id": 1}', 'true'
|
||||
}
|
||||
'list' {
|
||||
return '{}', '[{"title": "Team Meeting", "start_time": "2025-01-01T10:00:00Z", "end_time": "2025-01-01T11:00:00Z", "attendees": [], "docs": [], "calendar_id": 1, "status": "published", "is_all_day": false, "is_recurring": false, "recurrence": [], "reminder_mins": [15], "color": "#0000FF", "timezone": "UTC", "locations": []}]'
|
||||
return '{}', '[{"title": "Team Meeting", "start_time": "2025-01-01T10:00:00Z", "end_time": "2025-01-01T11:00:00Z", "attendees": [], "docs": [], "calendar_id": 1, "status": "published", "is_all_day": false, "reminder_mins": [15], "color": "#0000FF", "timezone": "UTC", "locations": []}]'
|
||||
}
|
||||
else {
|
||||
return '{}', '{}'
|
||||
@@ -184,21 +184,9 @@ pub fn (self CalendarEvent) dump(mut e encoder.Encoder) ! {
|
||||
e.add_u32(self.calendar_id)
|
||||
e.add_u8(u8(self.status))
|
||||
e.add_bool(self.is_all_day)
|
||||
e.add_bool(self.is_recurring)
|
||||
e.add_bool(self.public)
|
||||
e.add_u8(u8(self.priority))
|
||||
|
||||
// Encode recurrence array
|
||||
e.add_u16(u16(self.recurrence.len))
|
||||
for rule in self.recurrence {
|
||||
e.add_u8(u8(rule.frequency))
|
||||
e.add_int(rule.interval)
|
||||
e.add_i64(rule.until)
|
||||
e.add_int(rule.count)
|
||||
e.add_list_int(rule.by_weekday)
|
||||
e.add_list_int(rule.by_monthday)
|
||||
}
|
||||
|
||||
// Encode locations array
|
||||
e.add_u16(u16(self.locations.len))
|
||||
for location in self.locations {
|
||||
@@ -286,32 +274,9 @@ pub fn (mut self DBCalendarEvent) load(mut o CalendarEvent, mut e encoder.Decode
|
||||
o.calendar_id = e.get_u32()!
|
||||
o.status = unsafe { EventStatus(e.get_u8()!) } // TODO: is there no better way?
|
||||
o.is_all_day = e.get_bool()!
|
||||
o.is_recurring = e.get_bool()!
|
||||
o.public = e.get_bool()! // Added missing public field
|
||||
o.priority = unsafe { EventPriority(e.get_u8()!) } // Added missing priority field
|
||||
|
||||
// Decode recurrence array
|
||||
recurrence_len := e.get_u16()!
|
||||
mut recurrence := []RecurrenceRule{}
|
||||
for _ in 0 .. recurrence_len {
|
||||
frequency := unsafe { RecurrenceFreq(e.get_u8()!) }
|
||||
interval := e.get_int()!
|
||||
until := e.get_i64()!
|
||||
count := e.get_int()!
|
||||
by_weekday := e.get_list_int()!
|
||||
by_monthday := e.get_list_int()!
|
||||
|
||||
recurrence << RecurrenceRule{
|
||||
frequency: frequency
|
||||
interval: interval
|
||||
until: until
|
||||
count: count
|
||||
by_weekday: by_weekday
|
||||
by_monthday: by_monthday
|
||||
}
|
||||
}
|
||||
o.recurrence = recurrence
|
||||
|
||||
// Decode locations array
|
||||
locations_len := e.get_u16()!
|
||||
mut locations := []EventLocation{}
|
||||
@@ -363,8 +328,6 @@ pub mut:
|
||||
calendar_id u32 // Associated calendar
|
||||
status EventStatus
|
||||
is_all_day bool
|
||||
is_recurring bool
|
||||
recurrence []RecurrenceRule
|
||||
reminder_mins []int // Minutes before event for reminders
|
||||
color string // Hex color code
|
||||
timezone string
|
||||
@@ -394,8 +357,6 @@ pub fn (mut self DBCalendarEvent) new(args CalendarEventArg) !CalendarEvent {
|
||||
calendar_id: args.calendar_id
|
||||
status: args.status
|
||||
is_all_day: args.is_all_day
|
||||
is_recurring: args.is_recurring
|
||||
recurrence: args.recurrence
|
||||
reminder_mins: args.reminder_mins
|
||||
color: args.color
|
||||
timezone: args.timezone
|
||||
@@ -492,3 +453,4 @@ pub fn (mut self DBCalendarEvent) list(args CalendarEventListArg) ![]CalendarEve
|
||||
|
||||
return filtered_events
|
||||
}
|
||||
|
||||
@@ -22,8 +22,6 @@ fn test_calendar_event_new() ! {
|
||||
calendar_id: 1
|
||||
status: .published
|
||||
is_all_day: false
|
||||
is_recurring: false
|
||||
recurrence: []RecurrenceRule{}
|
||||
reminder_mins: [15]
|
||||
color: '#0000FF'
|
||||
timezone: 'UTC'
|
||||
@@ -46,8 +44,6 @@ fn test_calendar_event_new() ! {
|
||||
assert calendar_event.calendar_id == 1
|
||||
assert calendar_event.status == .published
|
||||
assert calendar_event.is_all_day == false
|
||||
assert calendar_event.is_recurring == false
|
||||
assert calendar_event.recurrence.len == 0
|
||||
assert calendar_event.reminder_mins == [15]
|
||||
assert calendar_event.color == '#0000FF'
|
||||
assert calendar_event.timezone == 'UTC'
|
||||
@@ -78,8 +74,6 @@ fn test_calendar_event_crud_operations() ! {
|
||||
calendar_id: 1
|
||||
status: .published
|
||||
is_all_day: false
|
||||
is_recurring: false
|
||||
recurrence: []RecurrenceRule{}
|
||||
reminder_mins: [15]
|
||||
color: '#0000FF'
|
||||
timezone: 'UTC'
|
||||
@@ -116,7 +110,6 @@ fn test_calendar_event_crud_operations() ! {
|
||||
assert retrieved_event.calendar_id == 1
|
||||
assert retrieved_event.status == .published
|
||||
assert retrieved_event.is_all_day == false
|
||||
assert retrieved_event.is_recurring == false
|
||||
assert retrieved_event.reminder_mins == [15]
|
||||
assert retrieved_event.color == '#0000FF'
|
||||
assert retrieved_event.timezone == 'UTC'
|
||||
@@ -145,8 +138,6 @@ fn test_calendar_event_crud_operations() ! {
|
||||
calendar_id: 2
|
||||
status: .draft
|
||||
is_all_day: true
|
||||
is_recurring: true
|
||||
recurrence: []RecurrenceRule{}
|
||||
reminder_mins: [30]
|
||||
color: '#FF0000'
|
||||
timezone: 'EST'
|
||||
@@ -180,7 +171,6 @@ fn test_calendar_event_crud_operations() ! {
|
||||
assert final_event.calendar_id == 2
|
||||
assert final_event.status == .draft
|
||||
assert final_event.is_all_day == true
|
||||
assert final_event.is_recurring == true
|
||||
assert final_event.reminder_mins == [30]
|
||||
assert final_event.color == '#FF0000'
|
||||
assert final_event.timezone == 'EST'
|
||||
@@ -220,12 +210,11 @@ fn test_calendar_event_attendees_encoding_decoding() ! {
|
||||
calendar_id: 1
|
||||
status: .published
|
||||
is_all_day: false
|
||||
is_recurring: false
|
||||
recurrence: []RecurrenceRule{}
|
||||
reminder_mins: [15]
|
||||
color: '#0000FF'
|
||||
timezone: 'UTC'
|
||||
priority: .normal // Added missing priority field
|
||||
is_template: false // Added missing is_template field
|
||||
securitypolicy: 0
|
||||
tags: []string{}
|
||||
comments: []db.CommentArg{}
|
||||
@@ -298,86 +287,6 @@ fn test_calendar_event_attendees_encoding_decoding() ! {
|
||||
println('✓ CalendarEvent attendees encoding/decoding test passed!')
|
||||
}
|
||||
|
||||
fn test_calendar_event_recurrence_encoding_decoding() ! {
|
||||
// Initialize DBCalendarEvent for testing
|
||||
mut mydb := db.new_test()!
|
||||
mut db_calendar_event := DBCalendarEvent{
|
||||
db: &mydb
|
||||
}
|
||||
|
||||
// Create a new calendar event with recurrence rules
|
||||
mut args := CalendarEventArg{
|
||||
name: 'recurrence_test_event'
|
||||
description: 'Test calendar event for recurrence encoding/decoding'
|
||||
title: 'Weekly Team Meeting'
|
||||
start_time: '2025-01-01 10:00:00'
|
||||
end_time: '2025-01-01 11:00:00'
|
||||
attendees: []u32{}
|
||||
docs: []u32{}
|
||||
calendar_id: 1
|
||||
status: .published
|
||||
is_all_day: false
|
||||
is_recurring: true
|
||||
recurrence: []RecurrenceRule{}
|
||||
reminder_mins: [15]
|
||||
color: '#0000FF'
|
||||
timezone: 'UTC'
|
||||
securitypolicy: 0
|
||||
tags: []string{}
|
||||
comments: []db.CommentArg{}
|
||||
}
|
||||
|
||||
mut calendar_event := db_calendar_event.new(args)!
|
||||
|
||||
// Add recurrence rules manually
|
||||
mut rule1 := RecurrenceRule{
|
||||
frequency: .weekly
|
||||
interval: 1
|
||||
until: 1893456000 // 2030-01-01
|
||||
count: 0
|
||||
by_weekday: [1, 3, 5] // Monday, Wednesday, Friday
|
||||
by_monthday: []int{}
|
||||
}
|
||||
|
||||
mut rule2 := RecurrenceRule{
|
||||
frequency: .monthly
|
||||
interval: 2
|
||||
until: 0
|
||||
count: 12
|
||||
by_weekday: []int{}
|
||||
by_monthday: [1, 15] // 1st and 15th of each month
|
||||
}
|
||||
|
||||
calendar_event.recurrence = [rule1, rule2]
|
||||
|
||||
// Save the calendar event
|
||||
calendar_event = db_calendar_event.set(calendar_event)!
|
||||
calendar_event_id := calendar_event.id
|
||||
|
||||
// Retrieve and verify all fields were properly encoded/decoded
|
||||
retrieved_event := db_calendar_event.get(calendar_event_id)!
|
||||
|
||||
assert retrieved_event.recurrence.len == 2
|
||||
assert retrieved_event.is_recurring == true
|
||||
|
||||
// Verify first recurrence rule details
|
||||
assert retrieved_event.recurrence[0].frequency == .weekly
|
||||
assert retrieved_event.recurrence[0].interval == 1
|
||||
assert retrieved_event.recurrence[0].until == 1893456000
|
||||
assert retrieved_event.recurrence[0].count == 0
|
||||
assert retrieved_event.recurrence[0].by_weekday == [1, 3, 5]
|
||||
assert retrieved_event.recurrence[0].by_monthday.len == 0
|
||||
|
||||
// Verify second recurrence rule details
|
||||
assert retrieved_event.recurrence[1].frequency == .monthly
|
||||
assert retrieved_event.recurrence[1].interval == 2
|
||||
assert retrieved_event.recurrence[1].until == 0
|
||||
assert retrieved_event.recurrence[1].count == 12
|
||||
assert retrieved_event.recurrence[1].by_weekday.len == 0
|
||||
assert retrieved_event.recurrence[1].by_monthday == [1, 15]
|
||||
|
||||
println('✓ CalendarEvent recurrence encoding/decoding test passed!')
|
||||
}
|
||||
|
||||
fn test_calendar_event_registration_desks_encoding_decoding() ! {
|
||||
// Initialize DBCalendarEvent for testing
|
||||
@@ -398,12 +307,11 @@ fn test_calendar_event_registration_desks_encoding_decoding() ! {
|
||||
calendar_id: 1
|
||||
status: .published
|
||||
is_all_day: false
|
||||
is_recurring: false
|
||||
recurrence: []RecurrenceRule{}
|
||||
reminder_mins: [15]
|
||||
color: '#0000FF'
|
||||
timezone: 'UTC'
|
||||
priority: .normal
|
||||
is_template: false
|
||||
securitypolicy: 0
|
||||
tags: []string{}
|
||||
comments: []db.CommentArg{}
|
||||
@@ -448,12 +356,11 @@ fn test_calendar_event_docs_encoding_decoding() ! {
|
||||
calendar_id: 1
|
||||
status: .published
|
||||
is_all_day: false
|
||||
is_recurring: false
|
||||
recurrence: []RecurrenceRule{}
|
||||
reminder_mins: [15]
|
||||
color: '#0000FF'
|
||||
timezone: 'UTC'
|
||||
priority: .normal
|
||||
is_template: false
|
||||
securitypolicy: 0
|
||||
tags: []string{}
|
||||
comments: []db.CommentArg{}
|
||||
@@ -517,8 +424,6 @@ fn test_calendar_event_type_name() ! {
|
||||
calendar_id: 1
|
||||
status: .published
|
||||
is_all_day: false
|
||||
is_recurring: false
|
||||
recurrence: []RecurrenceRule{}
|
||||
reminder_mins: [15]
|
||||
color: '#0000FF'
|
||||
timezone: 'UTC'
|
||||
@@ -555,8 +460,6 @@ fn test_calendar_event_description() ! {
|
||||
calendar_id: 1
|
||||
status: .published
|
||||
is_all_day: false
|
||||
is_recurring: false
|
||||
recurrence: []RecurrenceRule{}
|
||||
reminder_mins: [15]
|
||||
color: '#0000FF'
|
||||
timezone: 'UTC'
|
||||
@@ -597,8 +500,6 @@ fn test_calendar_event_example() ! {
|
||||
calendar_id: 1
|
||||
status: .published
|
||||
is_all_day: false
|
||||
is_recurring: false
|
||||
recurrence: []RecurrenceRule{}
|
||||
reminder_mins: [15]
|
||||
color: '#0000FF'
|
||||
timezone: 'UTC'
|
||||
|
||||
@@ -15,8 +15,25 @@ pub mut:
|
||||
author u32 // links to user
|
||||
to []u32 // if comment/message has been sent to someone specifically
|
||||
cc []u32 // like to but then for cc
|
||||
send_log []SendLog
|
||||
}
|
||||
|
||||
pub struct SendLog {
|
||||
pub mut:
|
||||
to []u32 // if comment/message has been sent to someone specifically
|
||||
cc []u32 // like to but then for cc
|
||||
status SendStatus
|
||||
timestamp u64 //when was it done
|
||||
}
|
||||
|
||||
pub struct SendStatus {
|
||||
pub mut:
|
||||
sent
|
||||
received
|
||||
acknowledged
|
||||
}
|
||||
|
||||
|
||||
//////////TO BE GENERATED BY AI////////////////////////////////
|
||||
///BASIC CRUD FUNCTIONS
|
||||
|
||||
|
||||
@@ -63,31 +63,33 @@ pub mut:
|
||||
@[params]
|
||||
pub struct PlanningListArg {
|
||||
pub mut:
|
||||
is_public bool
|
||||
limit int = 100 // Default limit is 100
|
||||
is_public bool
|
||||
calendar_template_id u32
|
||||
registration_desk_id u32
|
||||
limit int = 100 // Default limit is 100
|
||||
}
|
||||
|
||||
pub fn (self Planning) type_name() string {
|
||||
return 'calendar'
|
||||
return 'planning'
|
||||
}
|
||||
|
||||
// return example rpc call and result for each methodname
|
||||
pub fn (self Planning) description(methodname string) string {
|
||||
match methodname {
|
||||
'set' {
|
||||
return 'Create or update a calendar. Returns the ID of the calendar.'
|
||||
return 'Create or update a planning. Returns the ID of the planning.'
|
||||
}
|
||||
'get' {
|
||||
return 'Retrieve a calendar by ID. Returns the calendar object.'
|
||||
return 'Retrieve a planning by ID. Returns the planning object.'
|
||||
}
|
||||
'delete' {
|
||||
return 'Delete a calendar by ID. Returns true if successful.'
|
||||
return 'Delete a planning by ID. Returns true if successful.'
|
||||
}
|
||||
'exist' {
|
||||
return 'Check if a calendar exists by ID. Returns true or false.'
|
||||
return 'Check if a planning exists by ID. Returns true or false.'
|
||||
}
|
||||
'list' {
|
||||
return 'List all calendars. Returns an array of calendar objects.'
|
||||
return 'List all plannings. Returns an array of planning objects.'
|
||||
}
|
||||
else {
|
||||
return 'This is generic method for the root object, TODO fill in, ...'
|
||||
@@ -99,10 +101,10 @@ pub fn (self Planning) description(methodname string) string {
|
||||
pub fn (self Planning) example(methodname string) (string, string) {
|
||||
match methodname {
|
||||
'set' {
|
||||
return '{"calendar": {"name": "My Planning", "description": "A personal calendar", "color": "#FF0000", "timezone": "UTC", "is_public": true, "events": []}}', '1'
|
||||
return '{"planning": {"name": "My Planning", "description": "A personal planning", "color": "#FF0000", "timezone": "UTC", "is_public": true, "calendar_template_id": 1, "registration_desk_id": 10, "autoschedule_rules": [], "invite_rules": [], "attendees_required": [], "attendees_optional": []}}', '1'
|
||||
}
|
||||
'get' {
|
||||
return '{"id": 1}', '{"name": "My Planning", "description": "A personal calendar", "color": "#FF0000", "timezone": "UTC", "is_public": true, "events": []}'
|
||||
return '{"id": 1}', '{"name": "My Planning", "description": "A personal planning", "color": "#FF0000", "timezone": "UTC", "is_public": true, "calendar_template_id": 1, "registration_desk_id": 10, "autoschedule_rules": [], "invite_rules": [], "attendees_required": [], "attendees_optional": []}'
|
||||
}
|
||||
'delete' {
|
||||
return '{"id": 1}', 'true'
|
||||
@@ -111,7 +113,7 @@ pub fn (self Planning) example(methodname string) (string, string) {
|
||||
return '{"id": 1}', 'true'
|
||||
}
|
||||
'list' {
|
||||
return '{}', '[{"name": "My Planning", "description": "A personal calendar", "color": "#FF0000", "timezone": "UTC", "is_public": true, "events": []}]'
|
||||
return '{}', '[{"name": "My Planning", "description": "A personal planning", "color": "#FF0000", "timezone": "UTC", "is_public": true, "calendar_template_id": 1, "registration_desk_id": 10, "autoschedule_rules": [], "invite_rules": [], "attendees_required": [], "attendees_optional": []}]'
|
||||
}
|
||||
else {
|
||||
return '{}', '{}'
|
||||
@@ -123,7 +125,8 @@ pub fn (self Planning) dump(mut e encoder.Encoder) ! {
|
||||
e.add_string(self.color)
|
||||
e.add_string(self.timezone)
|
||||
e.add_bool(self.is_public)
|
||||
e.add_u32(self.calendar_id)
|
||||
e.add_u32(self.calendar_template_id)
|
||||
e.add_u32(self.registration_desk_id)
|
||||
|
||||
// Encode autoschedule_rules array
|
||||
e.add_u16(u16(self.autoschedule_rules.len))
|
||||
@@ -136,13 +139,20 @@ pub fn (self Planning) dump(mut e encoder.Encoder) ! {
|
||||
for rule in self.invite_rules {
|
||||
rule.dump(mut e)!
|
||||
}
|
||||
|
||||
// Encode attendees_required array
|
||||
e.add_list_u32(self.attendees_required)
|
||||
|
||||
// Encode attendees_optional array
|
||||
e.add_list_u32(self.attendees_optional)
|
||||
}
|
||||
|
||||
fn (mut self DBPlanning) load(mut o Planning, mut e encoder.Decoder) ! {
|
||||
o.color = e.get_string()!
|
||||
o.timezone = e.get_string()!
|
||||
o.is_public = e.get_bool()!
|
||||
o.calendar_id = e.get_u32()!
|
||||
o.calendar_template_id = e.get_u32()!
|
||||
o.registration_desk_id = e.get_u32()!
|
||||
|
||||
// Decode autoschedule_rules array
|
||||
autoschedule_rules_len := e.get_u16()!
|
||||
@@ -163,30 +173,53 @@ fn (mut self DBPlanning) load(mut o Planning, mut e encoder.Decoder) ! {
|
||||
invite_rules << rule
|
||||
}
|
||||
o.invite_rules = invite_rules
|
||||
|
||||
// Decode attendees_required array
|
||||
o.attendees_required = e.get_list_u32()!
|
||||
|
||||
// Decode attendees_optional array
|
||||
o.attendees_optional = e.get_list_u32()!
|
||||
}
|
||||
|
||||
@[params]
|
||||
pub struct PlanningArg {
|
||||
pub mut:
|
||||
name string
|
||||
description string
|
||||
color string
|
||||
timezone string
|
||||
is_public bool
|
||||
events []u32
|
||||
name string
|
||||
description string
|
||||
color string
|
||||
timezone string
|
||||
is_public bool
|
||||
calendar_template_id u32
|
||||
registration_desk_id u32
|
||||
autoschedule_rules []RecurrenceRule
|
||||
invite_rules []RecurrenceRule
|
||||
attendees_required []u32
|
||||
attendees_optional []u32
|
||||
securitypolicy u32
|
||||
tags []string
|
||||
comments []db.CommentArg
|
||||
}
|
||||
|
||||
// get new calendar, not from the DB
|
||||
pub fn (mut self DBPlanning) new(args PlanningArg) !Planning {
|
||||
mut o := Planning{
|
||||
color: args.color
|
||||
timezone: args.timezone
|
||||
is_public: args.is_public
|
||||
color: args.color
|
||||
timezone: args.timezone
|
||||
is_public: args.is_public
|
||||
calendar_template_id: args.calendar_template_id
|
||||
registration_desk_id: args.registration_desk_id
|
||||
autoschedule_rules: args.autoschedule_rules
|
||||
invite_rules: args.invite_rules
|
||||
attendees_required: args.attendees_required
|
||||
attendees_optional: args.attendees_optional
|
||||
}
|
||||
|
||||
// Set base fields
|
||||
o.name = args.name
|
||||
o.description = args.description
|
||||
o.securitypolicy = args.securitypolicy
|
||||
o.tags = self.db.tags_get(args.tags)!
|
||||
o.comments = self.db.comments_get(args.comments)!
|
||||
o.updated_at = ourtime.now().unix()
|
||||
|
||||
return o
|
||||
@@ -214,22 +247,33 @@ pub fn (mut self DBPlanning) get(id u32) !Planning {
|
||||
|
||||
pub fn (mut self DBPlanning) list(args PlanningListArg) ![]Planning {
|
||||
// Require at least one parameter to be provided
|
||||
if !args.is_public {
|
||||
// Require at least one parameter to be provided
|
||||
if !args.is_public && args.calendar_template_id == 0 && args.registration_desk_id == 0 {
|
||||
return error('At least one filter parameter must be provided')
|
||||
}
|
||||
|
||||
// Get all calendars from the database
|
||||
all_calendars := self.db.list[Planning]()!.map(self.get(it)!)
|
||||
// Get all plannings from the database
|
||||
all_plannings := self.db.list[Planning]()!.map(self.get(it)!)
|
||||
|
||||
// Apply filters
|
||||
mut filtered_calendars := []Planning{}
|
||||
for calendar in all_calendars {
|
||||
// Filter by is_public if provided (is_public is true)
|
||||
if args.is_public && !calendar.is_public {
|
||||
mut filtered_plannings := []Planning{}
|
||||
for planning in all_plannings {
|
||||
// Filter by is_public if provided
|
||||
if args.is_public && !planning.is_public {
|
||||
continue
|
||||
}
|
||||
|
||||
filtered_calendars << calendar
|
||||
// Filter by calendar_template_id if provided
|
||||
if args.calendar_template_id != 0 && planning.calendar_template_id != args.calendar_template_id {
|
||||
continue
|
||||
}
|
||||
|
||||
// Filter by registration_desk_id if provided
|
||||
if args.registration_desk_id != 0 && planning.registration_desk_id != args.registration_desk_id {
|
||||
continue
|
||||
}
|
||||
|
||||
filtered_plannings << planning
|
||||
}
|
||||
|
||||
// Limit results to 100 or the specified limit
|
||||
@@ -237,9 +281,9 @@ pub fn (mut self DBPlanning) list(args PlanningListArg) ![]Planning {
|
||||
if limit > 100 {
|
||||
limit = 100
|
||||
}
|
||||
if filtered_calendars.len > limit {
|
||||
return filtered_calendars[..limit]
|
||||
if filtered_plannings.len > limit {
|
||||
return filtered_plannings[..limit]
|
||||
}
|
||||
|
||||
return filtered_calendars
|
||||
return filtered_plannings
|
||||
}
|
||||
|
||||
@@ -12,12 +12,20 @@ fn test_planning_new() ! {
|
||||
|
||||
// Test creating a new planning
|
||||
mut args := PlanningArg{
|
||||
name: 'test_planning'
|
||||
description: 'Test planning for unit testing'
|
||||
color: '#FF0000'
|
||||
timezone: 'UTC'
|
||||
is_public: true
|
||||
events: []u32{}
|
||||
name: 'test_planning'
|
||||
description: 'Test planning for unit testing'
|
||||
color: '#FF0000'
|
||||
timezone: 'UTC'
|
||||
is_public: true
|
||||
calendar_template_id: 0
|
||||
registration_desk_id: 0
|
||||
autoschedule_rules: []RecurrenceRule{}
|
||||
invite_rules: []RecurrenceRule{}
|
||||
attendees_required: []u32{}
|
||||
attendees_optional: []u32{}
|
||||
securitypolicy: 0
|
||||
tags: []string{}
|
||||
comments: []db.CommentArg{}
|
||||
}
|
||||
|
||||
planning := db_planning.new(args)!
|
||||
@@ -27,9 +35,12 @@ fn test_planning_new() ! {
|
||||
assert planning.color == '#FF0000'
|
||||
assert planning.timezone == 'UTC'
|
||||
assert planning.is_public == true
|
||||
assert planning.calendar_id == 0
|
||||
assert planning.calendar_template_id == 0
|
||||
assert planning.registration_desk_id == 0
|
||||
assert planning.autoschedule_rules.len == 0
|
||||
assert planning.invite_rules.len == 0
|
||||
assert planning.attendees_required.len == 0
|
||||
assert planning.attendees_optional.len == 0
|
||||
assert planning.updated_at > 0
|
||||
|
||||
println('✓ Planning new test passed!')
|
||||
@@ -44,19 +55,24 @@ fn test_planning_crud_operations() ! {
|
||||
|
||||
// Create a new planning
|
||||
mut args := PlanningArg{
|
||||
name: 'crud_test_planning'
|
||||
description: 'Test planning for CRUD operations'
|
||||
color: '#00FF00'
|
||||
timezone: 'EST'
|
||||
is_public: false
|
||||
events: []u32{}
|
||||
name: 'crud_test_planning'
|
||||
description: 'Test planning for CRUD operations'
|
||||
color: '#00FF00'
|
||||
timezone: 'EST'
|
||||
is_public: false
|
||||
calendar_template_id: 1
|
||||
registration_desk_id: 10
|
||||
autoschedule_rules: []RecurrenceRule{}
|
||||
invite_rules: []RecurrenceRule{}
|
||||
attendees_required: [100, 101]
|
||||
attendees_optional: [200]
|
||||
securitypolicy: 0
|
||||
tags: []string{}
|
||||
comments: []db.CommentArg{}
|
||||
}
|
||||
|
||||
mut planning := db_planning.new(args)!
|
||||
|
||||
// Add some data for calendar_id, autoschedule_rules, and invite_rules
|
||||
planning.calendar_id = 1
|
||||
|
||||
// Create some recurrence rules
|
||||
mut rule1 := RecurrenceRule{
|
||||
until: 1893456000 // 2030-01-01
|
||||
@@ -92,7 +108,10 @@ fn test_planning_crud_operations() ! {
|
||||
assert retrieved_planning.color == '#00FF00'
|
||||
assert retrieved_planning.timezone == 'EST'
|
||||
assert retrieved_planning.is_public == false
|
||||
assert retrieved_planning.calendar_id == 1
|
||||
assert retrieved_planning.calendar_template_id == 1
|
||||
assert retrieved_planning.registration_desk_id == 10
|
||||
assert retrieved_planning.attendees_required == [100, 101]
|
||||
assert retrieved_planning.attendees_optional == [200]
|
||||
assert retrieved_planning.id == original_id
|
||||
|
||||
// Verify autoschedule_rules
|
||||
@@ -121,17 +140,24 @@ fn test_planning_crud_operations() ! {
|
||||
|
||||
// Test update
|
||||
mut updated_args := PlanningArg{
|
||||
name: 'updated_planning'
|
||||
description: 'Updated test planning'
|
||||
color: '#0000FF'
|
||||
timezone: 'PST'
|
||||
is_public: true
|
||||
events: []u32{}
|
||||
name: 'updated_planning'
|
||||
description: 'Updated test planning'
|
||||
color: '#0000FF'
|
||||
timezone: 'PST'
|
||||
is_public: true
|
||||
calendar_template_id: 2
|
||||
registration_desk_id: 20
|
||||
autoschedule_rules: []RecurrenceRule{}
|
||||
invite_rules: []RecurrenceRule{}
|
||||
attendees_required: [102]
|
||||
attendees_optional: []u32{}
|
||||
securitypolicy: 0
|
||||
tags: []string{}
|
||||
comments: []db.CommentArg{}
|
||||
}
|
||||
|
||||
mut updated_planning := db_planning.new(updated_args)!
|
||||
updated_planning.id = original_id
|
||||
updated_planning.calendar_id = 2
|
||||
|
||||
// Update rules
|
||||
mut updated_rule1 := RecurrenceRule{
|
||||
@@ -166,7 +192,10 @@ fn test_planning_crud_operations() ! {
|
||||
assert final_planning.color == '#0000FF'
|
||||
assert final_planning.timezone == 'PST'
|
||||
assert final_planning.is_public == true
|
||||
assert final_planning.calendar_id == 2
|
||||
assert final_planning.calendar_template_id == 2
|
||||
assert final_planning.registration_desk_id == 20
|
||||
assert final_planning.attendees_required == [102]
|
||||
assert final_planning.attendees_optional.len == 0
|
||||
|
||||
// Verify updated autoschedule_rules
|
||||
assert final_planning.autoschedule_rules.len == 1
|
||||
@@ -207,12 +236,20 @@ fn test_planning_recurrence_rules_encoding_decoding() ! {
|
||||
|
||||
// Create a new planning with recurrence rules
|
||||
mut args := PlanningArg{
|
||||
name: 'recurrence_test_planning'
|
||||
description: 'Test planning for recurrence rules encoding/decoding'
|
||||
color: '#FFFF00'
|
||||
timezone: 'UTC'
|
||||
is_public: true
|
||||
events: []u32{}
|
||||
name: 'recurrence_test_planning'
|
||||
description: 'Test planning for recurrence rules encoding/decoding'
|
||||
color: '#FFFF00'
|
||||
timezone: 'UTC'
|
||||
is_public: true
|
||||
calendar_template_id: 1
|
||||
registration_desk_id: 0
|
||||
autoschedule_rules: []RecurrenceRule{}
|
||||
invite_rules: []RecurrenceRule{}
|
||||
attendees_required: []u32{}
|
||||
attendees_optional: []u32{}
|
||||
securitypolicy: 0
|
||||
tags: []string{}
|
||||
comments: []db.CommentArg{}
|
||||
}
|
||||
|
||||
mut planning := db_planning.new(args)!
|
||||
@@ -303,7 +340,7 @@ fn test_planning_type_name() ! {
|
||||
|
||||
// Test type_name method
|
||||
type_name := planning.type_name()
|
||||
assert type_name == 'calendar'
|
||||
assert type_name == 'planning'
|
||||
|
||||
println('✓ Planning type_name test passed!')
|
||||
}
|
||||
@@ -328,11 +365,11 @@ fn test_planning_description() ! {
|
||||
planning := db_planning.new(args)!
|
||||
|
||||
// Test description method for each methodname
|
||||
assert planning.description('set') == 'Create or update a calendar. Returns the ID of the calendar.'
|
||||
assert planning.description('get') == 'Retrieve a calendar by ID. Returns the calendar object.'
|
||||
assert planning.description('delete') == 'Delete a calendar by ID. Returns true if successful.'
|
||||
assert planning.description('exist') == 'Check if a calendar exists by ID. Returns true or false.'
|
||||
assert planning.description('list') == 'List all calendars. Returns an array of calendar objects.'
|
||||
assert planning.description('set') == 'Create or update a planning. Returns the ID of the planning.'
|
||||
assert planning.description('get') == 'Retrieve a planning by ID. Returns the planning object.'
|
||||
assert planning.description('delete') == 'Delete a planning by ID. Returns true if successful.'
|
||||
assert planning.description('exist') == 'Check if a planning exists by ID. Returns true or false.'
|
||||
assert planning.description('list') == 'List all plannings. Returns an array of planning objects.'
|
||||
assert planning.description('unknown') == 'This is generic method for the root object, TODO fill in, ...'
|
||||
|
||||
println('✓ Planning description test passed!')
|
||||
@@ -359,12 +396,12 @@ fn test_planning_example() ! {
|
||||
|
||||
// Test example method for each methodname
|
||||
set_call, set_result := planning.example('set')
|
||||
assert set_call == '{"calendar": {"name": "My Planning", "description": "A personal calendar", "color": "#FF0000", "timezone": "UTC", "is_public": true, "events": []}}'
|
||||
assert set_call == '{"planning": {"name": "My Planning", "description": "A personal planning", "color": "#FF0000", "timezone": "UTC", "is_public": true, "calendar_template_id": 1, "registration_desk_id": 10, "autoschedule_rules": [], "invite_rules": [], "attendees_required": [], "attendees_optional": []}}'
|
||||
assert set_result == '1'
|
||||
|
||||
get_call, get_result := planning.example('get')
|
||||
assert get_call == '{"id": 1}'
|
||||
assert get_result == '{"name": "My Planning", "description": "A personal calendar", "color": "#FF0000", "timezone": "UTC", "is_public": true, "events": []}'
|
||||
assert get_result == '{"name": "My Planning", "description": "A personal planning", "color": "#FF0000", "timezone": "UTC", "is_public": true, "calendar_template_id": 1, "registration_desk_id": 10, "autoschedule_rules": [], "invite_rules": [], "attendees_required": [], "attendees_optional": []}'
|
||||
|
||||
delete_call, delete_result := planning.example('delete')
|
||||
assert delete_call == '{"id": 1}'
|
||||
@@ -376,7 +413,7 @@ fn test_planning_example() ! {
|
||||
|
||||
list_call, list_result := planning.example('list')
|
||||
assert list_call == '{}'
|
||||
assert list_result == '[{"name": "My Planning", "description": "A personal calendar", "color": "#FF0000", "timezone": "UTC", "is_public": true, "events": []}]'
|
||||
assert list_result == '[{"name": "My Planning", "description": "A personal planning", "color": "#FF0000", "timezone": "UTC", "is_public": true, "calendar_template_id": 1, "registration_desk_id": 10, "autoschedule_rules": [], "invite_rules": [], "attendees_required": [], "attendees_optional": []}]'
|
||||
|
||||
unknown_call, unknown_result := planning.example('unknown')
|
||||
assert unknown_call == '{}'
|
||||
|
||||
Reference in New Issue
Block a user