This commit is contained in:
2025-09-18 06:30:26 +02:00
parent 9011f5b4c8
commit 6be418f8cb
4 changed files with 100 additions and 82 deletions

View File

@@ -34,7 +34,7 @@ pub fn test_get(url_ RedisURL) !&Redis {
url = RedisURL{ url = RedisURL{
address: url_.address address: url_.address
port: url_.port port: url_.port
db: 31 db: 15
} }
} }
return core_get(url)! return core_get(url)!

View File

@@ -34,7 +34,7 @@ pub mut:
attendance_required bool attendance_required bool
admin bool // if set can manage the main elements of the event = description, ... admin bool // if set can manage the main elements of the event = description, ...
organizer bool // if set means others can ask for support, doesn't mean is admin organizer bool // if set means others can ask for support, doesn't mean is admin
log AttendeeLog log []AttendeeLog
} }
pub enum EventPriority { pub enum EventPriority {
@@ -153,7 +153,7 @@ pub fn (self CalendarEvent) dump(mut e encoder.Encoder) ! {
e.add_i64(self.start_time) e.add_i64(self.start_time)
e.add_i64(self.end_time) e.add_i64(self.end_time)
e.add_string(self.location) e.add_string(self.location)
// Encode attendees array // Encode attendees array
e.add_u16(u16(self.attendees.len)) e.add_u16(u16(self.attendees.len))
for attendee in self.attendees { for attendee in self.attendees {
@@ -162,13 +162,16 @@ pub fn (self CalendarEvent) dump(mut e encoder.Encoder) ! {
e.add_bool(attendee.attendance_required) e.add_bool(attendee.attendance_required)
e.add_bool(attendee.admin) e.add_bool(attendee.admin)
e.add_bool(attendee.organizer) e.add_bool(attendee.organizer)
// Encode AttendeeLog // Encode AttendeeLog array
e.add_u64(attendee.log.timestamp) e.add_u16(u16(attendee.log.len))
e.add_u8(u8(attendee.log.status)) for log_entry in attendee.log {
e.add_string(attendee.log.remark) e.add_u64(log_entry.timestamp)
e.add_u8(u8(log_entry.status))
e.add_string(log_entry.remark)
}
} }
e.add_list_u32(self.fs_items) e.add_list_u32(self.fs_items)
e.add_u32(self.calendar_id) e.add_u32(self.calendar_id)
e.add_u8(u8(self.status)) e.add_u8(u8(self.status))
@@ -198,7 +201,7 @@ pub fn (mut self DBCalendarEvent) load(mut o CalendarEvent, mut e encoder.Decode
o.start_time = e.get_i64()! o.start_time = e.get_i64()!
o.end_time = e.get_i64()! o.end_time = e.get_i64()!
o.location = e.get_string()! o.location = e.get_string()!
// Decode attendees array // Decode attendees array
attendees_len := e.get_u16()! attendees_len := e.get_u16()!
mut attendees := []Attendee{} mut attendees := []Attendee{}
@@ -208,27 +211,33 @@ pub fn (mut self DBCalendarEvent) load(mut o CalendarEvent, mut e encoder.Decode
attendance_required := e.get_bool()! attendance_required := e.get_bool()!
admin := e.get_bool()! admin := e.get_bool()!
organizer := e.get_bool()! organizer := e.get_bool()!
// Decode AttendeeLog // Decode AttendeeLog array
timestamp := e.get_u64()! log_len := e.get_u16()!
status := unsafe { AttendanceStatus(e.get_u8()!) } mut log_entries := []AttendeeLog{}
remark := e.get_string()! for _ in 0 .. log_len {
timestamp := e.get_u64()!
status := unsafe { AttendanceStatus(e.get_u8()!) }
remark := e.get_string()!
log_entries << AttendeeLog{
timestamp: timestamp
status: status
remark: remark
}
}
attendees << Attendee{ attendees << Attendee{
user_id: user_id user_id: user_id
status_latest: status_latest status_latest: status_latest
attendance_required: attendance_required attendance_required: attendance_required
admin: admin admin: admin
organizer: organizer organizer: organizer
log: AttendeeLog{ log: log_entries
timestamp: timestamp
status: status
remark: remark
}
} }
} }
o.attendees = attendees o.attendees = attendees
o.fs_items = e.get_list_u32()! o.fs_items = e.get_list_u32()!
o.calendar_id = e.get_u32()! o.calendar_id = e.get_u32()!
o.status = unsafe { EventStatus(e.get_u8()!) } // TODO: is there no better way? o.status = unsafe { EventStatus(e.get_u8()!) } // TODO: is there no better way?
@@ -283,6 +292,7 @@ pub mut:
reminder_mins []int // Minutes before event for reminders reminder_mins []int // Minutes before event for reminders
color string // Hex color code color string // Hex color code
timezone string timezone string
priority EventPriority // Added missing priority field
securitypolicy u32 securitypolicy u32
tags []string tags []string
comments []db.CommentArg comments []db.CommentArg
@@ -303,6 +313,7 @@ pub fn (mut self DBCalendarEvent) new(args CalendarEventArg) !CalendarEvent {
reminder_mins: args.reminder_mins reminder_mins: args.reminder_mins
color: args.color color: args.color
timezone: args.timezone timezone: args.timezone
priority: args.priority // Added missing priority field
} }
// Set base fields // Set base fields

View File

@@ -15,8 +15,8 @@ fn test_calendar_event_new() ! {
name: 'test_event' name: 'test_event'
description: 'Test calendar event for unit testing' description: 'Test calendar event for unit testing'
title: 'Team Meeting' title: 'Team Meeting'
start_time: '2025-01-01T10:00:00Z' start_time: '2025-01-01 10:00:00'
end_time: '2025-01-01T11:00:00Z' end_time: '2025-01-01 11:00:00'
location: 'Office' location: 'Office'
attendees: []u32{} attendees: []u32{}
fs_items: []u32{} fs_items: []u32{}
@@ -28,13 +28,14 @@ fn test_calendar_event_new() ! {
reminder_mins: [15] reminder_mins: [15]
color: '#0000FF' color: '#0000FF'
timezone: 'UTC' timezone: 'UTC'
priority: .normal // Added missing priority field
securitypolicy: 0 securitypolicy: 0
tags: []string{} tags: []string{}
comments: []db.CommentArg{} comments: []db.CommentArg{}
} }
calendar_event := db_calendar_event.new(args)! calendar_event := db_calendar_event.new(args)!
assert calendar_event.name == 'test_event' assert calendar_event.name == 'test_event'
assert calendar_event.description == 'Test calendar event for unit testing' assert calendar_event.description == 'Test calendar event for unit testing'
assert calendar_event.title == 'Team Meeting' assert calendar_event.title == 'Team Meeting'
@@ -51,7 +52,7 @@ fn test_calendar_event_new() ! {
assert calendar_event.priority == .normal assert calendar_event.priority == .normal
assert calendar_event.public == false assert calendar_event.public == false
assert calendar_event.updated_at > 0 assert calendar_event.updated_at > 0
println(' CalendarEvent new test passed!') println(' CalendarEvent new test passed!')
} }
@@ -67,8 +68,8 @@ fn test_calendar_event_crud_operations() ! {
name: 'crud_test_event' name: 'crud_test_event'
description: 'Test calendar event for CRUD operations' description: 'Test calendar event for CRUD operations'
title: 'Team Meeting' title: 'Team Meeting'
start_time: '2025-01-01T10:00:00Z' start_time: '2025-01-01 10:00:00'
end_time: '2025-01-01T11:00:00Z' end_time: '2025-01-01 11:00:00'
location: 'Office' location: 'Office'
attendees: []u32{} attendees: []u32{}
fs_items: []u32{} fs_items: []u32{}
@@ -80,6 +81,7 @@ fn test_calendar_event_crud_operations() ! {
reminder_mins: [15] reminder_mins: [15]
color: '#0000FF' color: '#0000FF'
timezone: 'UTC' timezone: 'UTC'
priority: .normal // Added missing priority field
securitypolicy: 0 securitypolicy: 0
tags: []string{} tags: []string{}
comments: []db.CommentArg{} comments: []db.CommentArg{}
@@ -115,8 +117,8 @@ fn test_calendar_event_crud_operations() ! {
name: 'updated_event' name: 'updated_event'
description: 'Updated test calendar event' description: 'Updated test calendar event'
title: 'Updated Team Meeting' title: 'Updated Team Meeting'
start_time: '2025-01-01T12:00:00Z' start_time: '2025-01-01 12:00:00'
end_time: '2025-01-01T13:00:00Z' end_time: '2025-01-01 13:00:00'
location: 'Conference Room' location: 'Conference Room'
attendees: []u32{} attendees: []u32{}
fs_items: []u32{} fs_items: []u32{}
@@ -153,11 +155,11 @@ fn test_calendar_event_crud_operations() ! {
// Test delete operation // Test delete operation
db_calendar_event.delete(original_id)! db_calendar_event.delete(original_id)!
// Verify deletion // Verify deletion
exists_after_delete := db_calendar_event.exist(original_id)! exists_after_delete := db_calendar_event.exist(original_id)!
assert exists_after_delete == false assert exists_after_delete == false
println(' CalendarEvent CRUD operations test passed!') println(' CalendarEvent CRUD operations test passed!')
} }
@@ -173,8 +175,8 @@ fn test_calendar_event_attendees_encoding_decoding() ! {
name: 'attendees_test_event' name: 'attendees_test_event'
description: 'Test calendar event for attendees encoding/decoding' description: 'Test calendar event for attendees encoding/decoding'
title: 'Team Meeting' title: 'Team Meeting'
start_time: '2025-01-01T10:00:00Z' start_time: '2025-01-01 10:00:00'
end_time: '2025-01-01T11:00:00Z' end_time: '2025-01-01 11:00:00'
location: 'Office' location: 'Office'
attendees: []u32{} attendees: []u32{}
fs_items: []u32{} fs_items: []u32{}
@@ -186,13 +188,14 @@ fn test_calendar_event_attendees_encoding_decoding() ! {
reminder_mins: [15] reminder_mins: [15]
color: '#0000FF' color: '#0000FF'
timezone: 'UTC' timezone: 'UTC'
priority: .normal // Added missing priority field
securitypolicy: 0 securitypolicy: 0
tags: []string{} tags: []string{}
comments: []db.CommentArg{} comments: []db.CommentArg{}
} }
mut calendar_event := db_calendar_event.new(args)! mut calendar_event := db_calendar_event.new(args)!
// Add some attendees manually since the new method doesn't populate them // Add some attendees manually since the new method doesn't populate them
mut attendee1 := Attendee{ mut attendee1 := Attendee{
user_id: 100 user_id: 100
@@ -200,57 +203,61 @@ fn test_calendar_event_attendees_encoding_decoding() ! {
attendance_required: true attendance_required: true
admin: true admin: true
organizer: false organizer: false
log: AttendeeLog{ log: [
timestamp: 1234567890 AttendeeLog{
status: .accepted timestamp: 1234567890
remark: 'User accepted the invitation' status: .accepted
} remark: 'User accepted the invitation'
},
]
} }
mut attendee2 := Attendee{ mut attendee2 := Attendee{
user_id: 101 user_id: 101
status_latest: .tentative status_latest: .tentative
attendance_required: false attendance_required: false
admin: false admin: false
organizer: true organizer: true
log: AttendeeLog{ log: [
timestamp: 1234567891 AttendeeLog{
status: .tentative timestamp: 1234567891
remark: 'User is tentative' status: .tentative
} remark: 'User is tentative'
},
]
} }
calendar_event.attendees = [attendee1, attendee2] calendar_event.attendees = [attendee1, attendee2]
// Save the calendar event // Save the calendar event
calendar_event = db_calendar_event.set(calendar_event)! calendar_event = db_calendar_event.set(calendar_event)!
calendar_event_id := calendar_event.id calendar_event_id := calendar_event.id
// Retrieve and verify all fields were properly encoded/decoded // Retrieve and verify all fields were properly encoded/decoded
retrieved_event := db_calendar_event.get(calendar_event_id)! retrieved_event := db_calendar_event.get(calendar_event_id)!
assert retrieved_event.attendees.len == 2 assert retrieved_event.attendees.len == 2
// Verify first attendee details // Verify first attendee details
assert retrieved_event.attendees[0].user_id == 100 assert retrieved_event.attendees[0].user_id == 100
assert retrieved_event.attendees[0].status_latest == .accepted assert retrieved_event.attendees[0].status_latest == .accepted
assert retrieved_event.attendees[0].attendance_required == true assert retrieved_event.attendees[0].attendance_required == true
assert retrieved_event.attendees[0].admin == true assert retrieved_event.attendees[0].admin == true
assert retrieved_event.attendees[0].organizer == false assert retrieved_event.attendees[0].organizer == false
assert retrieved_event.attendees[0].log.timestamp == 1234567890 assert retrieved_event.attendees[0].log[0].timestamp == 1234567890
assert retrieved_event.attendees[0].log.status == .accepted assert retrieved_event.attendees[0].log[0].status == .accepted
assert retrieved_event.attendees[0].log.remark == 'User accepted the invitation' assert retrieved_event.attendees[0].log[0].remark == 'User accepted the invitation'
// Verify second attendee details // Verify second attendee details
assert retrieved_event.attendees[1].user_id == 101 assert retrieved_event.attendees[1].user_id == 101
assert retrieved_event.attendees[1].status_latest == .tentative assert retrieved_event.attendees[1].status_latest == .tentative
assert retrieved_event.attendees[1].attendance_required == false assert retrieved_event.attendees[1].attendance_required == false
assert retrieved_event.attendees[1].admin == false assert retrieved_event.attendees[1].admin == false
assert retrieved_event.attendees[1].organizer == true assert retrieved_event.attendees[1].organizer == true
assert retrieved_event.attendees[1].log.timestamp == 1234567891 assert retrieved_event.attendees[1].log[0].timestamp == 1234567891
assert retrieved_event.attendees[1].log.status == .tentative assert retrieved_event.attendees[1].log[0].status == .tentative
assert retrieved_event.attendees[1].log.remark == 'User is tentative' assert retrieved_event.attendees[1].log[0].remark == 'User is tentative'
println(' CalendarEvent attendees encoding/decoding test passed!') println(' CalendarEvent attendees encoding/decoding test passed!')
} }
@@ -266,8 +273,8 @@ fn test_calendar_event_recurrence_encoding_decoding() ! {
name: 'recurrence_test_event' name: 'recurrence_test_event'
description: 'Test calendar event for recurrence encoding/decoding' description: 'Test calendar event for recurrence encoding/decoding'
title: 'Weekly Team Meeting' title: 'Weekly Team Meeting'
start_time: '2025-01-01T10:00:00Z' start_time: '2025-01-01 10:00:00'
end_time: '2025-01-01T11:00:00Z' end_time: '2025-01-01 11:00:00'
location: 'Office' location: 'Office'
attendees: []u32{} attendees: []u32{}
fs_items: []u32{} fs_items: []u32{}
@@ -285,7 +292,7 @@ fn test_calendar_event_recurrence_encoding_decoding() ! {
} }
mut calendar_event := db_calendar_event.new(args)! mut calendar_event := db_calendar_event.new(args)!
// Add recurrence rules manually // Add recurrence rules manually
mut rule1 := RecurrenceRule{ mut rule1 := RecurrenceRule{
frequency: .weekly frequency: .weekly
@@ -295,7 +302,7 @@ fn test_calendar_event_recurrence_encoding_decoding() ! {
by_weekday: [1, 3, 5] // Monday, Wednesday, Friday by_weekday: [1, 3, 5] // Monday, Wednesday, Friday
by_monthday: []int{} by_monthday: []int{}
} }
mut rule2 := RecurrenceRule{ mut rule2 := RecurrenceRule{
frequency: .monthly frequency: .monthly
interval: 2 interval: 2
@@ -304,19 +311,19 @@ fn test_calendar_event_recurrence_encoding_decoding() ! {
by_weekday: []int{} by_weekday: []int{}
by_monthday: [1, 15] // 1st and 15th of each month by_monthday: [1, 15] // 1st and 15th of each month
} }
calendar_event.recurrence = [rule1, rule2] calendar_event.recurrence = [rule1, rule2]
// Save the calendar event // Save the calendar event
calendar_event = db_calendar_event.set(calendar_event)! calendar_event = db_calendar_event.set(calendar_event)!
calendar_event_id := calendar_event.id calendar_event_id := calendar_event.id
// Retrieve and verify all fields were properly encoded/decoded // Retrieve and verify all fields were properly encoded/decoded
retrieved_event := db_calendar_event.get(calendar_event_id)! retrieved_event := db_calendar_event.get(calendar_event_id)!
assert retrieved_event.recurrence.len == 2 assert retrieved_event.recurrence.len == 2
assert retrieved_event.is_recurring == true assert retrieved_event.is_recurring == true
// Verify first recurrence rule details // Verify first recurrence rule details
assert retrieved_event.recurrence[0].frequency == .weekly assert retrieved_event.recurrence[0].frequency == .weekly
assert retrieved_event.recurrence[0].interval == 1 assert retrieved_event.recurrence[0].interval == 1
@@ -324,7 +331,7 @@ fn test_calendar_event_recurrence_encoding_decoding() ! {
assert retrieved_event.recurrence[0].count == 0 assert retrieved_event.recurrence[0].count == 0
assert retrieved_event.recurrence[0].by_weekday == [1, 3, 5] assert retrieved_event.recurrence[0].by_weekday == [1, 3, 5]
assert retrieved_event.recurrence[0].by_monthday.len == 0 assert retrieved_event.recurrence[0].by_monthday.len == 0
// Verify second recurrence rule details // Verify second recurrence rule details
assert retrieved_event.recurrence[1].frequency == .monthly assert retrieved_event.recurrence[1].frequency == .monthly
assert retrieved_event.recurrence[1].interval == 2 assert retrieved_event.recurrence[1].interval == 2
@@ -332,7 +339,7 @@ fn test_calendar_event_recurrence_encoding_decoding() ! {
assert retrieved_event.recurrence[1].count == 12 assert retrieved_event.recurrence[1].count == 12
assert retrieved_event.recurrence[1].by_weekday.len == 0 assert retrieved_event.recurrence[1].by_weekday.len == 0
assert retrieved_event.recurrence[1].by_monthday == [1, 15] assert retrieved_event.recurrence[1].by_monthday == [1, 15]
println(' CalendarEvent recurrence encoding/decoding test passed!') println(' CalendarEvent recurrence encoding/decoding test passed!')
} }
@@ -348,8 +355,8 @@ fn test_calendar_event_type_name() ! {
name: 'type_test_event' name: 'type_test_event'
description: 'Test calendar event for type name' description: 'Test calendar event for type name'
title: 'Team Meeting' title: 'Team Meeting'
start_time: '2025-01-01T10:00:00Z' start_time: '2025-01-01 10:00:00'
end_time: '2025-01-01T11:00:00Z' end_time: '2025-01-01 11:00:00'
location: 'Office' location: 'Office'
attendees: []u32{} attendees: []u32{}
fs_items: []u32{} fs_items: []u32{}
@@ -367,11 +374,11 @@ fn test_calendar_event_type_name() ! {
} }
calendar_event := db_calendar_event.new(args)! calendar_event := db_calendar_event.new(args)!
// Test type_name method // Test type_name method
type_name := calendar_event.type_name() type_name := calendar_event.type_name()
assert type_name == 'calendar_event' assert type_name == 'calendar_event'
println(' CalendarEvent type_name test passed!') println(' CalendarEvent type_name test passed!')
} }
@@ -387,8 +394,8 @@ fn test_calendar_event_description() ! {
name: 'description_test_event' name: 'description_test_event'
description: 'Test calendar event for description' description: 'Test calendar event for description'
title: 'Team Meeting' title: 'Team Meeting'
start_time: '2025-01-01T10:00:00Z' start_time: '2025-01-01 10:00:00'
end_time: '2025-01-01T11:00:00Z' end_time: '2025-01-01 11:00:00'
location: 'Office' location: 'Office'
attendees: []u32{} attendees: []u32{}
fs_items: []u32{} fs_items: []u32{}
@@ -406,7 +413,7 @@ fn test_calendar_event_description() ! {
} }
calendar_event := db_calendar_event.new(args)! calendar_event := db_calendar_event.new(args)!
// Test description method for each methodname // Test description method for each methodname
assert calendar_event.description('set') == 'Create or update a calendar event. Returns the ID of the event.' assert calendar_event.description('set') == 'Create or update a calendar event. Returns the ID of the event.'
assert calendar_event.description('get') == 'Retrieve a calendar event by ID. Returns the event object.' assert calendar_event.description('get') == 'Retrieve a calendar event by ID. Returns the event object.'
@@ -414,7 +421,7 @@ fn test_calendar_event_description() ! {
assert calendar_event.description('exist') == 'Check if a calendar event exists by ID. Returns true or false.' assert calendar_event.description('exist') == 'Check if a calendar event exists by ID. Returns true or false.'
assert calendar_event.description('list') == 'List all calendar events. Returns an array of event objects.' assert calendar_event.description('list') == 'List all calendar events. Returns an array of event objects.'
assert calendar_event.description('unknown') == 'This is generic method for the root object, TODO fill in, ...' assert calendar_event.description('unknown') == 'This is generic method for the root object, TODO fill in, ...'
println(' CalendarEvent description test passed!') println(' CalendarEvent description test passed!')
} }
@@ -430,8 +437,8 @@ fn test_calendar_event_example() ! {
name: 'example_test_event' name: 'example_test_event'
description: 'Test calendar event for example' description: 'Test calendar event for example'
title: 'Team Meeting' title: 'Team Meeting'
start_time: '2025-01-01T10:00:00Z' start_time: '2025-01-01 10:00:00'
end_time: '2025-01-01T11:00:00Z' end_time: '2025-01-01 11:00:00'
location: 'Office' location: 'Office'
attendees: []u32{} attendees: []u32{}
fs_items: []u32{} fs_items: []u32{}
@@ -449,7 +456,7 @@ fn test_calendar_event_example() ! {
} }
calendar_event := db_calendar_event.new(args)! calendar_event := db_calendar_event.new(args)!
// Test example method for each methodname // Test example method for each methodname
set_call, set_result := calendar_event.example('set') set_call, set_result := calendar_event.example('set')
assert set_call == '{"calendar_event": {"title": "Team Meeting", "start_time": "2025-01-01T10:00:00Z", "end_time": "2025-01-01T11:00:00Z", "location": "Office", "attendees": [], "fs_items": [], "calendar_id": 1, "status": "published", "is_all_day": false, "is_recurring": false, "recurrence": [], "reminder_mins": [15], "color": "#0000FF", "timezone": "UTC"}}' assert set_call == '{"calendar_event": {"title": "Team Meeting", "start_time": "2025-01-01T10:00:00Z", "end_time": "2025-01-01T11:00:00Z", "location": "Office", "attendees": [], "fs_items": [], "calendar_id": 1, "status": "published", "is_all_day": false, "is_recurring": false, "recurrence": [], "reminder_mins": [15], "color": "#0000FF", "timezone": "UTC"}}'
@@ -474,6 +481,6 @@ fn test_calendar_event_example() ! {
unknown_call, unknown_result := calendar_event.example('unknown') unknown_call, unknown_result := calendar_event.example('unknown')
assert unknown_call == '{}' assert unknown_call == '{}'
assert unknown_result == '{}' assert unknown_result == '{}'
println(' CalendarEvent example test passed!') println(' CalendarEvent example test passed!')
} }

View File

@@ -78,7 +78,7 @@ pub fn (self User) example(methodname string) (string, string) {
} }
} }
fn (self User) dump(mut e encoder.Encoder) ! { pub fn (self User) dump(mut e encoder.Encoder) ! {
e.add_string(self.email) e.add_string(self.email)
e.add_string(self.public_key) e.add_string(self.public_key)
e.add_string(self.phone) e.add_string(self.phone)