This commit is contained in:
2025-09-14 15:00:57 +02:00
parent b918079117
commit a7cc5142ac
8 changed files with 335 additions and 120 deletions

View File

@@ -80,7 +80,31 @@ pub fn (self CalendarEvent) type_name() string {
return 'calendar_event'
}
pub fn (self CalendarEvent) dump(mut e &encoder.Encoder) ! {
// return example rpc call and result for each methodname
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", "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"}}', '1'
}
'get' {
return '{"id": 1}', '{"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"}'
}
'delete' {
return '{"id": 1}', 'true'
}
'exist' {
return '{"id": 1}', 'true'
}
'list' {
return '{}', '[{"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"}]'
}
else {
return '{}', '{}'
}
}
}
pub fn (self CalendarEvent) dump(mut e encoder.Encoder) ! {
e.add_string(self.title)
e.add_i64(self.start_time)
e.add_i64(self.end_time)
@@ -108,7 +132,7 @@ pub fn (self CalendarEvent) dump(mut e &encoder.Encoder) ! {
e.add_string(self.timezone)
}
fn (mut self DBCalendarEvent) load(mut o CalendarEvent, mut e &encoder.Decoder) ! {
fn (mut self DBCalendarEvent) load(mut o CalendarEvent, mut e encoder.Decoder) ! {
o.title = e.get_string()!
o.start_time = e.get_i64()!
o.end_time = e.get_i64()!
@@ -116,7 +140,7 @@ fn (mut self DBCalendarEvent) load(mut o CalendarEvent, mut e &encoder.Decoder)
o.attendees = e.get_list_u32()!
o.fs_items = e.get_list_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?
o.is_all_day = e.get_bool()!
o.is_recurring = e.get_bool()!

View File

@@ -30,13 +30,37 @@ pub fn (self ChatGroup) type_name() string {
return 'chat_group'
}
pub fn (self ChatGroup) dump(mut e &encoder.Encoder) ! {
// return example rpc call and result for each methodname
pub fn (self ChatGroup) example(methodname string) (string, string) {
match methodname {
'set' {
return '{"chat_group": {"name": "General Chat", "description": "A general chat group", "chat_type": "public_channel", "last_activity": 1678886400, "is_archived": false}}', '1'
}
'get' {
return '{"id": 1}', '{"name": "General Chat", "description": "A general chat group", "chat_type": "public_channel", "last_activity": 1678886400, "is_archived": false}'
}
'delete' {
return '{"id": 1}', 'true'
}
'exist' {
return '{"id": 1}', 'true'
}
'list' {
return '{}', '[{"name": "General Chat", "description": "A general chat group", "chat_type": "public_channel", "last_activity": 1678886400, "is_archived": false}]'
}
else {
return '{}', '{}'
}
}
}
pub fn (self ChatGroup) dump(mut e encoder.Encoder) ! {
e.add_u8(u8(self.chat_type))
e.add_i64(self.last_activity)
e.add_bool(self.is_archived)
}
fn (mut self DBChatGroup) load(mut o ChatGroup, mut e &encoder.Decoder) ! {
fn (mut self DBChatGroup) load(mut o ChatGroup, mut e encoder.Decoder) ! {
o.chat_type = unsafe { ChatType(e.get_u8()!) }
o.last_activity = e.get_i64()!
o.is_archived = e.get_bool()!

View File

@@ -67,7 +67,31 @@ pub fn (self ChatMessage) type_name() string {
return 'chat_message'
}
pub fn (self ChatMessage) dump(mut e &encoder.Encoder) ! {
// return example rpc call and result for each methodname
pub fn (self ChatMessage) example(methodname string) (string, string) {
match methodname {
'set' {
return '{"chat_message": {"content": "Hello, everyone!", "chat_group_id": 1, "sender_id": 1, "parent_messages": [], "fs_files": [], "message_type": "text", "status": "sent", "reactions": [], "mentions": []}}', '1'
}
'get' {
return '{"id": 1}', '{"content": "Hello, everyone!", "chat_group_id": 1, "sender_id": 1, "parent_messages": [], "fs_files": [], "message_type": "text", "status": "sent", "reactions": [], "mentions": []}'
}
'delete' {
return '{"id": 1}', 'true'
}
'exist' {
return '{"id": 1}', 'true'
}
'list' {
return '{}', '[{"content": "Hello, everyone!", "chat_group_id": 1, "sender_id": 1, "parent_messages": [], "fs_files": [], "message_type": "text", "status": "sent", "reactions": [], "mentions": []}]'
}
else {
return '{}', '{}'
}
}
}
pub fn (self ChatMessage) dump(mut e encoder.Encoder) ! {
e.add_string(self.content)
e.add_u32(self.chat_group_id)
e.add_u32(self.sender_id)
@@ -94,7 +118,7 @@ pub fn (self ChatMessage) dump(mut e &encoder.Encoder) ! {
e.add_list_u32(self.mentions)
}
fn (mut self DBChatMessage) load(mut o ChatMessage, mut e &encoder.Decoder) ! {
fn (mut self DBChatMessage) load(mut o ChatMessage, mut e encoder.Decoder) ! {
o.content = e.get_string()!
o.chat_group_id = e.get_u32()!
o.sender_id = e.get_u32()!

View File

@@ -26,13 +26,37 @@ pub fn (self Comment) type_name() string {
return 'comments'
}
pub fn (self Comment) dump(mut e &encoder.Encoder) ! {
// return example rpc call and result for each methodname
pub fn (self Comment) example(methodname string) (string, string) {
match methodname {
'set' {
return '{"comment": {"comment": "This is a test comment.", "parent": 0, "author": 1}}', '1'
}
'get' {
return '{"id": 1}', '{"comment": "This is a test comment.", "parent": 0, "author": 1}'
}
'delete' {
return '{"id": 1}', 'true'
}
'exist' {
return '{"id": 1}', 'true'
}
'list' {
return '{}', '[{"comment": "This is a test comment.", "parent": 0, "author": 1}]'
}
else {
return '{}', '{}'
}
}
}
pub fn (self Comment) dump(mut e encoder.Encoder) ! {
e.add_string(self.comment)
e.add_u32(self.parent)
e.add_u32(self.author)
}
fn (mut self DBComments) load(mut o Comment, mut e &encoder.Decoder) ! {
fn (mut self DBComments) load(mut o Comment, mut e encoder.Decoder) ! {
o.comment = e.get_string()!
o.parent = e.get_u32()!
o.author = e.get_u32()!

View File

@@ -33,7 +33,31 @@ pub fn (self Group) type_name() string {
return 'group'
}
pub fn (self Group) dump(mut e &encoder.Encoder) ! {
// return example rpc call and result for each methodname
pub fn (self Group) example(methodname string) (string, string) {
match methodname {
'set' {
return '{"group": {"name": "Admins", "description": "Administrators group", "members": [], "subgroups": [], "parent_group": 0, "is_public": false}}', '1'
}
'get' {
return '{"id": 1}', '{"name": "Admins", "description": "Administrators group", "members": [], "subgroups": [], "parent_group": 0, "is_public": false}'
}
'delete' {
return '{"id": 1}', 'true'
}
'exist' {
return '{"id": 1}', 'true'
}
'list' {
return '{}', '[{"name": "Admins", "description": "Administrators group", "members": [], "subgroups": [], "parent_group": 0, "is_public": false}]'
}
else {
return '{}', '{}'
}
}
}
pub fn (self Group) dump(mut e encoder.Encoder) ! {
e.add_u16(u16(self.members.len))
for member in self.members {
e.add_u32(member.user_id)
@@ -45,7 +69,7 @@ pub fn (self Group) dump(mut e &encoder.Encoder) ! {
e.add_bool(self.is_public)
}
fn (mut self DBGroup) load(mut o Group, mut e &encoder.Decoder) ! {
fn (mut self DBGroup) load(mut o Group, mut e encoder.Decoder) ! {
members_len := e.get_u16()!
mut members := []GroupMember{}
for _ in 0 .. members_len {
@@ -131,5 +155,4 @@ pub fn (mut self Group) add_member(user_id u32, role GroupRole) {
self.members << member
}
//CUSTOM FEATURES FOR GROUP
// CUSTOM FEATURES FOR GROUP

View File

@@ -20,7 +20,7 @@ pub mut:
pub struct Swimlane {
pub mut:
name string //allways to to_lower and trim_space
name string // allways to to_lower and trim_space
description string
order int
color string
@@ -29,7 +29,7 @@ pub mut:
pub struct Milestone {
pub mut:
name string //allways to to_lower and trim_space
name string // allways to to_lower and trim_space
description string
due_date i64
completed bool
@@ -53,7 +53,31 @@ pub fn (self Project) type_name() string {
return 'project'
}
pub fn (self Project) dump(mut e &encoder.Encoder) ! {
// return example rpc call and result for each methodname
pub fn (self Project) example(methodname string) (string, string) {
match methodname {
'set' {
return '{"project": {"name": "My Project", "description": "A project to track tasks", "swimlanes": [], "milestones": [], "issues": [], "fs_files": [], "status": "active", "start_date": "2025-01-01T00:00:00Z", "end_date": "2025-12-31T23:59:59Z"}}', '1'
}
'get' {
return '{"id": 1}', '{"name": "My Project", "description": "A project to track tasks", "swimlanes": [], "milestones": [], "issues": [], "fs_files": [], "status": "active", "start_date": "2025-01-01T00:00:00Z", "end_date": "2025-12-31T23:59:59Z"}'
}
'delete' {
return '{"id": 1}', 'true'
}
'exist' {
return '{"id": 1}', 'true'
}
'list' {
return '{}', '[{"name": "My Project", "description": "A project to track tasks", "swimlanes": [], "milestones": [], "issues": [], "fs_files": [], "status": "active", "start_date": "2025-01-01T00:00:00Z", "end_date": "2025-12-31T23:59:59Z"}]'
}
else {
return '{}', '{}'
}
}
}
pub fn (self Project) dump(mut e encoder.Encoder) ! {
e.add_u16(u16(self.swimlanes.len))
for swimlane in self.swimlanes {
e.add_string(swimlane.name)
@@ -79,7 +103,7 @@ pub fn (self Project) dump(mut e &encoder.Encoder) ! {
e.add_i64(self.end_date)
}
fn (mut self DBProject) load(mut o Project, mut e &encoder.Decoder) ! {
fn (mut self DBProject) load(mut o Project, mut e encoder.Decoder) ! {
swimlanes_len := e.get_u16()!
mut swimlanes := []Swimlane{}
for _ in 0 .. swimlanes_len {

View File

@@ -62,7 +62,31 @@ pub fn (self ProjectIssue) type_name() string {
return 'project_issue'
}
pub fn (self ProjectIssue) dump(mut e &encoder.Encoder) ! {
// return example rpc call and result for each methodname
pub fn (self ProjectIssue) example(methodname string) (string, string) {
match methodname {
'set' {
return '{"project_issue": {"title": "Implement new feature", "project_id": 1, "issue_type": "story", "priority": "high", "status": "open", "swimlane": "backlog", "assignees": [1], "reporter": 1, "milestone": "sprint 1", "deadline": "2025-03-01T00:00:00Z", "estimate": 8, "fs_files": [], "parent_id": 0, "children": []}}', '1'
}
'get' {
return '{"id": 1}', '{"title": "Implement new feature", "project_id": 1, "issue_type": "story", "priority": "high", "status": "open", "swimlane": "backlog", "assignees": [1], "reporter": 1, "milestone": "sprint 1", "deadline": "2025-03-01T00:00:00Z", "estimate": 8, "fs_files": [], "parent_id": 0, "children": []}'
}
'delete' {
return '{"id": 1}', 'true'
}
'exist' {
return '{"id": 1}', 'true'
}
'list' {
return '{}', '[{"title": "Implement new feature", "project_id": 1, "issue_type": "story", "priority": "high", "status": "open", "swimlane": "backlog", "assignees": [1], "reporter": 1, "milestone": "sprint 1", "deadline": "2025-03-01T00:00:00Z", "estimate": 8, "fs_files": [], "parent_id": 0, "children": []}]'
}
else {
return '{}', '{}'
}
}
}
pub fn (self ProjectIssue) dump(mut e encoder.Encoder) ! {
e.add_string(self.title)
e.add_u32(self.project_id)
e.add_u8(u8(self.issue_type))
@@ -79,7 +103,7 @@ pub fn (self ProjectIssue) dump(mut e &encoder.Encoder) ! {
e.add_list_u32(self.children)
}
fn (mut self DBProjectIssue) load(mut o ProjectIssue, mut e &encoder.Decoder) ! {
fn (mut self DBProjectIssue) load(mut o ProjectIssue, mut e encoder.Decoder) ! {
o.title = e.get_string()!
o.project_id = e.get_u32()!
o.issue_type = unsafe { IssueType(e.get_u8()!) }

View File

@@ -30,7 +30,55 @@ pub fn (self User) type_name() string {
return 'user'
}
pub fn (self User) dump(mut e &encoder.Encoder) ! {
// return example rpc call and result for each methodname
pub fn (self User) description(methodname string) string {
match methodname {
'set' {
return 'Create or update a user. Returns the ID of the user.'
}
'get' {
return 'Retrieve a user by ID. Returns the user object.'
}
'delete' {
return 'Delete a user by ID. Returns true if successful.'
}
'exist' {
return 'Check if a user exists by ID. Returns true or false.'
}
'list' {
return 'List all users. Returns an array of user objects.'
}
else {
return 'This is generic method for the root object, TODO fill in, ...'
}
}
}
// return example rpc call and result for each methodname
pub fn (self User) example(methodname string) (string, string) {
match methodname {
'set' {
return '{"user": {"name": "John Doe", "description": "A test user", "email": "john.doe@example.com", "public_key": "some_public_key", "phone": "123-456-7890", "address": "123 Main St", "avatar_url": "https://example.com/avatar.jpg", "bio": "Software Engineer", "timezone": "UTC", "status": "active"}}', '1'
}
'get' {
return '{"id": 1}', '{"name": "John Doe", "description": "A test user", "email": "john.doe@example.com", "public_key": "some_public_key", "phone": "123-456-7890", "address": "123 Main St", "avatar_url": "https://example.com/avatar.jpg", "bio": "Software Engineer", "timezone": "UTC", "status": "active"}'
}
'delete' {
return '{"id": 1}', 'true'
}
'exist' {
return '{"id": 1}', 'true'
}
'list' {
return '{}', '[{"name": "John Doe", "description": "A test user", "email": "john.doe@example.com", "public_key": "some_public_key", "phone": "123-456-7890", "address": "123 Main St", "avatar_url": "https://example.com/avatar.jpg", "bio": "Software Engineer", "timezone": "UTC", "status": "active"}]'
}
else {
return '{}', '{}'
}
}
}
pub fn (self User) dump(mut e encoder.Encoder) ! {
e.add_string(self.email)
e.add_string(self.public_key)
e.add_string(self.phone)
@@ -41,7 +89,7 @@ pub fn (self User) dump(mut e &encoder.Encoder) ! {
e.add_u8(u8(self.status))
}
fn (mut self DBUser) load(mut o User, mut e &encoder.Decoder) ! {
fn (mut self DBUser) load(mut o User, mut e encoder.Decoder) ! {
o.email = e.get_string()!
o.public_key = e.get_string()!
o.phone = e.get_string()!