From 9ed01e86bacf199de6fbd7a42175165e23270872 Mon Sep 17 00:00:00 2001 From: despiegk Date: Sun, 14 Sep 2025 14:00:21 +0200 Subject: [PATCH] ... --- lib/hero/heromodels/rpc/factory.v | 35 + lib/hero/heromodels/rpc/openrpc.json | 1874 ++++++++++++++++++ lib/hero/heromodels/rpc/rpc_calendar_event.v | 105 + lib/hero/heromodels/rpc/rpc_chat_group.v | 83 + lib/hero/heromodels/rpc/rpc_chat_message.v | 95 + lib/hero/heromodels/rpc/rpc_group.v | 78 + lib/hero/heromodels/rpc/rpc_project.v | 91 + lib/hero/heromodels/rpc/rpc_project_issue.v | 105 + lib/hero/heromodels/rpc/rpc_user.v | 92 + 9 files changed, 2558 insertions(+) create mode 100644 lib/hero/heromodels/rpc/rpc_calendar_event.v create mode 100644 lib/hero/heromodels/rpc/rpc_chat_group.v create mode 100644 lib/hero/heromodels/rpc/rpc_chat_message.v create mode 100644 lib/hero/heromodels/rpc/rpc_group.v create mode 100644 lib/hero/heromodels/rpc/rpc_project.v create mode 100644 lib/hero/heromodels/rpc/rpc_project_issue.v create mode 100644 lib/hero/heromodels/rpc/rpc_user.v diff --git a/lib/hero/heromodels/rpc/factory.v b/lib/hero/heromodels/rpc/factory.v index 9d1592c9..9d109dae 100644 --- a/lib/hero/heromodels/rpc/factory.v +++ b/lib/hero/heromodels/rpc/factory.v @@ -24,5 +24,40 @@ pub fn start(args ServerArgs) ! { openrpc_handler.register_procedure_handle('calendar_delete', calendar_delete) openrpc_handler.register_procedure_handle('calendar_list', calendar_list) + openrpc_handler.register_procedure_handle('calendar_event_get', calendar_event_get) + openrpc_handler.register_procedure_handle('calendar_event_set', calendar_event_set) + openrpc_handler.register_procedure_handle('calendar_event_delete', calendar_event_delete) + openrpc_handler.register_procedure_handle('calendar_event_list', calendar_event_list) + + openrpc_handler.register_procedure_handle('chat_group_get', chat_group_get) + openrpc_handler.register_procedure_handle('chat_group_set', chat_group_set) + openrpc_handler.register_procedure_handle('chat_group_delete', chat_group_delete) + openrpc_handler.register_procedure_handle('chat_group_list', chat_group_list) + + openrpc_handler.register_procedure_handle('chat_message_get', chat_message_get) + openrpc_handler.register_procedure_handle('chat_message_set', chat_message_set) + openrpc_handler.register_procedure_handle('chat_message_delete', chat_message_delete) + openrpc_handler.register_procedure_handle('chat_message_list', chat_message_list) + + openrpc_handler.register_procedure_handle('group_get', group_get) + openrpc_handler.register_procedure_handle('group_set', group_set) + openrpc_handler.register_procedure_handle('group_delete', group_delete) + openrpc_handler.register_procedure_handle('group_list', group_list) + + openrpc_handler.register_procedure_handle('project_issue_get', project_issue_get) + openrpc_handler.register_procedure_handle('project_issue_set', project_issue_set) + openrpc_handler.register_procedure_handle('project_issue_delete', project_issue_delete) + openrpc_handler.register_procedure_handle('project_issue_list', project_issue_list) + + openrpc_handler.register_procedure_handle('project_get', project_get) + openrpc_handler.register_procedure_handle('project_set', project_set) + openrpc_handler.register_procedure_handle('project_delete', project_delete) + openrpc_handler.register_procedure_handle('project_list', project_list) + + openrpc_handler.register_procedure_handle('user_get', user_get) + openrpc_handler.register_procedure_handle('user_set', user_set) + openrpc_handler.register_procedure_handle('user_delete', user_delete) + openrpc_handler.register_procedure_handle('user_list', user_list) + openrpc.start_unix_server(openrpc_handler, socket_path: args.socket_path)! } diff --git a/lib/hero/heromodels/rpc/openrpc.json b/lib/hero/heromodels/rpc/openrpc.json index 3e9b3a87..a54acb69 100644 --- a/lib/hero/heromodels/rpc/openrpc.json +++ b/lib/hero/heromodels/rpc/openrpc.json @@ -221,6 +221,1329 @@ } } } + }, + { + "name": "calendar_event_get", + "summary": "Get a calendar event by ID", + "params": [ + { + "name": "id", + "description": "ID of calendar event to fetch", + "required": true, + "schema": { + "type": "integer", + "minimum": 0 + } + } + ], + "result": { + "name": "calendar_event", + "description": "Calendar event object", + "schema": { + "$ref": "#/components/schemas/CalendarEvent" + } + } + }, + { + "name": "calendar_event_set", + "summary": "Create or update a calendar event", + "params": [ + { + "name": "name", + "description": "Name of the calendar event", + "schema": { + "type": "string" + } + }, + { + "name": "description", + "description": "Description of the calendar event", + "schema": { + "type": "string" + } + }, + { + "name": "title", + "description": "Title of the calendar event", + "schema": { + "type": "string" + } + }, + { + "name": "start_time", + "description": "Start time of the calendar event", + "schema": { + "type": "string" + } + }, + { + "name": "end_time", + "description": "End time of the calendar event", + "schema": { + "type": "string" + } + }, + { + "name": "location", + "description": "Location of the calendar event", + "schema": { + "type": "string" + } + }, + { + "name": "attendees", + "description": "IDs of user groups", + "schema": { + "type": "array", + "items": { + "type": "integer", + "minimum": 0 + } + } + }, + { + "name": "fs_items", + "description": "IDs of linked files or dirs", + "schema": { + "type": "array", + "items": { + "type": "integer", + "minimum": 0 + } + } + }, + { + "name": "calendar_id", + "description": "Associated calendar ID", + "schema": { + "type": "integer", + "minimum": 0 + } + }, + { + "name": "status", + "description": "Event status", + "schema": { + "type": "string", + "enum": [ + "draft", + "published", + "cancelled", + "completed" + ] + } + }, + { + "name": "is_all_day", + "description": "Whether the event is all day", + "schema": { + "type": "boolean" + } + }, + { + "name": "is_recurring", + "description": "Whether the event is recurring", + "schema": { + "type": "boolean" + } + }, + { + "name": "recurrence", + "description": "Recurrence rules", + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/RecurrenceRule" + } + } + }, + { + "name": "reminder_mins", + "description": "Minutes before event for reminders", + "schema": { + "type": "array", + "items": { + "type": "integer" + } + } + }, + { + "name": "color", + "description": "Hex color code", + "schema": { + "type": "string" + } + }, + { + "name": "timezone", + "description": "Timezone of the calendar event", + "schema": { + "type": "string" + } + }, + { + "name": "securitypolicy", + "description": "Security policy ID", + "schema": { + "type": "integer", + "minimum": 0 + } + }, + { + "name": "tags", + "description": "Tags for the calendar event", + "schema": { + "type": "array", + "items": { + "type": "string" + } + } + }, + { + "name": "comments", + "description": "Comments for the calendar event", + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/CommentArg" + } + } + } + ], + "result": { + "name": "id", + "description": "ID of the created/updated calendar event", + "schema": { + "type": "integer", + "minimum": 0 + } + } + }, + { + "name": "calendar_event_delete", + "summary": "Delete a calendar event by ID", + "params": [ + { + "name": "id", + "description": "ID of calendar event to delete", + "required": true, + "schema": { + "type": "integer", + "minimum": 0 + } + } + ], + "result": { + "name": "result", + "description": "Success result", + "schema": { + "type": "boolean" + } + } + }, + { + "name": "calendar_event_list", + "summary": "List all calendar events", + "params": [], + "result": { + "name": "calendar_events", + "description": "List of all calendar event objects", + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/CalendarEvent" + } + } + } + }, + { + "name": "chat_group_get", + "summary": "Get a chat group by ID", + "params": [ + { + "name": "id", + "description": "ID of chat group to fetch", + "required": true, + "schema": { + "type": "integer", + "minimum": 0 + } + } + ], + "result": { + "name": "chat_group", + "description": "Chat group object", + "schema": { + "$ref": "#/components/schemas/ChatGroup" + } + } + }, + { + "name": "chat_group_set", + "summary": "Create or update a chat group", + "params": [ + { + "name": "name", + "description": "Name of the chat group", + "schema": { + "type": "string" + } + }, + { + "name": "description", + "description": "Description of the chat group", + "schema": { + "type": "string" + } + }, + { + "name": "chat_type", + "description": "Type of chat", + "schema": { + "type": "string", + "enum": [ + "public_channel", + "private_channel", + "direct_message", + "group_message" + ] + } + }, + { + "name": "last_activity", + "description": "Unix timestamp of last activity", + "schema": { + "type": "integer" + } + }, + { + "name": "is_archived", + "description": "Whether the chat group is archived", + "schema": { + "type": "boolean" + } + }, + { + "name": "securitypolicy", + "description": "Security policy ID", + "schema": { + "type": "integer", + "minimum": 0 + } + }, + { + "name": "tags", + "description": "Tags for the chat group", + "schema": { + "type": "array", + "items": { + "type": "string" + } + } + }, + { + "name": "comments", + "description": "Comments for the chat group", + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/CommentArg" + } + } + } + ], + "result": { + "name": "id", + "description": "ID of the created/updated chat group", + "schema": { + "type": "integer", + "minimum": 0 + } + } + }, + { + "name": "chat_group_delete", + "summary": "Delete a chat group by ID", + "params": [ + { + "name": "id", + "description": "ID of chat group to delete", + "required": true, + "schema": { + "type": "integer", + "minimum": 0 + } + } + ], + "result": { + "name": "result", + "description": "Success result", + "schema": { + "type": "boolean" + } + } + }, + { + "name": "chat_group_list", + "summary": "List all chat groups", + "params": [], + "result": { + "name": "chat_groups", + "description": "List of all chat group objects", + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/ChatGroup" + } + } + } + }, + { + "name": "chat_message_get", + "summary": "Get a chat message by ID", + "params": [ + { + "name": "id", + "description": "ID of chat message to fetch", + "required": true, + "schema": { + "type": "integer", + "minimum": 0 + } + } + ], + "result": { + "name": "chat_message", + "description": "Chat message object", + "schema": { + "$ref": "#/components/schemas/ChatMessage" + } + } + }, + { + "name": "chat_message_set", + "summary": "Create or update a chat message", + "params": [ + { + "name": "name", + "description": "Name of the chat message", + "schema": { + "type": "string" + } + }, + { + "name": "description", + "description": "Description of the chat message", + "schema": { + "type": "string" + } + }, + { + "name": "content", + "description": "Message content", + "schema": { + "type": "string" + } + }, + { + "name": "chat_group_id", + "description": "Associated chat group ID", + "schema": { + "type": "integer", + "minimum": 0 + } + }, + { + "name": "sender_id", + "description": "User ID of sender", + "schema": { + "type": "integer", + "minimum": 0 + } + }, + { + "name": "parent_messages", + "description": "Referenced/replied messages", + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/MessageLink" + } + } + }, + { + "name": "fs_files", + "description": "IDs of linked files", + "schema": { + "type": "array", + "items": { + "type": "integer", + "minimum": 0 + } + } + }, + { + "name": "message_type", + "description": "Type of message", + "schema": { + "type": "string", + "enum": [ + "text", + "image", + "file", + "voice", + "video", + "system", + "announcement" + ] + } + }, + { + "name": "status", + "description": "Message status", + "schema": { + "type": "string", + "enum": [ + "sent", + "delivered", + "read", + "failed", + "deleted" + ] + } + }, + { + "name": "reactions", + "description": "Message reactions", + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/MessageReaction" + } + } + }, + { + "name": "mentions", + "description": "User IDs mentioned in message", + "schema": { + "type": "array", + "items": { + "type": "integer", + "minimum": 0 + } + } + }, + { + "name": "securitypolicy", + "description": "Security policy ID", + "schema": { + "type": "integer", + "minimum": 0 + } + }, + { + "name": "tags", + "description": "Tags for the chat message", + "schema": { + "type": "array", + "items": { + "type": "string" + } + } + }, + { + "name": "comments", + "description": "Comments for the chat message", + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/CommentArg" + } + } + } + ], + "result": { + "name": "id", + "description": "ID of the created/updated chat message", + "schema": { + "type": "integer", + "minimum": 0 + } + } + }, + { + "name": "chat_message_delete", + "summary": "Delete a chat message by ID", + "params": [ + { + "name": "id", + "description": "ID of chat message to delete", + "required": true, + "schema": { + "type": "integer", + "minimum": 0 + } + } + ], + "result": { + "name": "result", + "description": "Success result", + "schema": { + "type": "boolean" + } + } + }, + { + "name": "chat_message_list", + "summary": "List all chat messages", + "params": [], + "result": { + "name": "chat_messages", + "description": "List of all chat message objects", + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/ChatMessage" + } + } + } + }, + { + "name": "group_get", + "summary": "Get a group by ID", + "params": [ + { + "name": "id", + "description": "ID of group to fetch", + "required": true, + "schema": { + "type": "integer", + "minimum": 0 + } + } + ], + "result": { + "name": "group", + "description": "Group object", + "schema": { + "$ref": "#/components/schemas/Group" + } + } + }, + { + "name": "group_set", + "summary": "Create or update a group", + "params": [ + { + "name": "name", + "description": "Name of the group", + "schema": { + "type": "string" + } + }, + { + "name": "description", + "description": "Description of the group", + "schema": { + "type": "string" + } + }, + { + "name": "members", + "description": "Group members", + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/GroupMember" + } + } + }, + { + "name": "subgroups", + "description": "IDs of child groups", + "schema": { + "type": "array", + "items": { + "type": "integer", + "minimum": 0 + } + } + }, + { + "name": "parent_group", + "description": "ID of parent group", + "schema": { + "type": "integer", + "minimum": 0 + } + }, + { + "name": "is_public", + "description": "Whether the group is public", + "schema": { + "type": "boolean" + } + } + ], + "result": { + "name": "id", + "description": "ID of the created/updated group", + "schema": { + "type": "integer", + "minimum": 0 + } + } + }, + { + "name": "group_delete", + "summary": "Delete a group by ID", + "params": [ + { + "name": "id", + "description": "ID of group to delete", + "required": true, + "schema": { + "type": "integer", + "minimum": 0 + } + } + ], + "result": { + "name": "result", + "description": "Success result", + "schema": { + "type": "boolean" + } + } + }, + { + "name": "group_list", + "summary": "List all groups", + "params": [], + "result": { + "name": "groups", + "description": "List of all group objects", + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/Group" + } + } + } + }, + { + "name": "project_issue_get", + "summary": "Get a project issue by ID", + "params": [ + { + "name": "id", + "description": "ID of project issue to fetch", + "required": true, + "schema": { + "type": "integer", + "minimum": 0 + } + } + ], + "result": { + "name": "project_issue", + "description": "Project issue object", + "schema": { + "$ref": "#/components/schemas/ProjectIssue" + } + } + }, + { + "name": "project_issue_set", + "summary": "Create or update a project issue", + "params": [ + { + "name": "name", + "description": "Name of the project issue", + "schema": { + "type": "string" + } + }, + { + "name": "description", + "description": "Description of the project issue", + "schema": { + "type": "string" + } + }, + { + "name": "title", + "description": "Title of the project issue", + "schema": { + "type": "string" + } + }, + { + "name": "project_id", + "description": "Associated project ID", + "schema": { + "type": "integer", + "minimum": 0 + } + }, + { + "name": "issue_type", + "description": "Type of issue", + "schema": { + "type": "string", + "enum": [ + "task", + "story", + "bug", + "question", + "epic", + "subtask" + ] + } + }, + { + "name": "priority", + "description": "Issue priority", + "schema": { + "type": "string", + "enum": [ + "lowest", + "low", + "medium", + "high", + "highest", + "critical" + ] + } + }, + { + "name": "status", + "description": "Issue status", + "schema": { + "type": "string", + "enum": [ + "open", + "in_progress", + "blocked", + "review", + "testing", + "done", + "closed" + ] + } + }, + { + "name": "swimlane", + "description": "Current swimlane", + "schema": { + "type": "string" + } + }, + { + "name": "assignees", + "description": "User IDs of assignees", + "schema": { + "type": "array", + "items": { + "type": "integer", + "minimum": 0 + } + } + }, + { + "name": "reporter", + "description": "User ID of reporter", + "schema": { + "type": "integer", + "minimum": 0 + } + }, + { + "name": "milestone", + "description": "Associated milestone", + "schema": { + "type": "string" + } + }, + { + "name": "deadline", + "description": "Deadline as string", + "schema": { + "type": "string" + } + }, + { + "name": "estimate", + "description": "Story points or hours", + "schema": { + "type": "integer" + } + }, + { + "name": "fs_files", + "description": "IDs of linked files", + "schema": { + "type": "array", + "items": { + "type": "integer", + "minimum": 0 + } + } + }, + { + "name": "parent_id", + "description": "Parent issue ID", + "schema": { + "type": "integer", + "minimum": 0 + } + }, + { + "name": "children", + "description": "Child issue IDs", + "schema": { + "type": "array", + "items": { + "type": "integer", + "minimum": 0 + } + } + }, + { + "name": "securitypolicy", + "description": "Security policy ID", + "schema": { + "type": "integer", + "minimum": 0 + } + }, + { + "name": "tags", + "description": "Tags for the project issue", + "schema": { + "type": "array", + "items": { + "type": "string" + } + } + }, + { + "name": "comments", + "description": "Comments for the project issue", + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/CommentArg" + } + } + } + ], + "result": { + "name": "id", + "description": "ID of the created/updated project issue", + "schema": { + "type": "integer", + "minimum": 0 + } + } + }, + { + "name": "project_issue_delete", + "summary": "Delete a project issue by ID", + "params": [ + { + "name": "id", + "description": "ID of project issue to delete", + "required": true, + "schema": { + "type": "integer", + "minimum": 0 + } + } + ], + "result": { + "name": "result", + "description": "Success result", + "schema": { + "type": "boolean" + } + } + }, + { + "name": "project_issue_list", + "summary": "List all project issues", + "params": [], + "result": { + "name": "project_issues", + "description": "List of all project issue objects", + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/ProjectIssue" + } + } + } + }, + { + "name": "project_get", + "summary": "Get a project by ID", + "params": [ + { + "name": "id", + "description": "ID of project to fetch", + "required": true, + "schema": { + "type": "integer", + "minimum": 0 + } + } + ], + "result": { + "name": "project", + "description": "Project object", + "schema": { + "$ref": "#/components/schemas/Project" + } + } + }, + { + "name": "project_set", + "summary": "Create or update a project", + "params": [ + { + "name": "name", + "description": "Name of the project", + "schema": { + "type": "string" + } + }, + { + "name": "description", + "description": "Description of the project", + "schema": { + "type": "string" + } + }, + { + "name": "swimlanes", + "description": "Project swimlanes", + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/Swimlane" + } + } + }, + { + "name": "milestones", + "description": "Project milestones", + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/Milestone" + } + } + }, + { + "name": "issues", + "description": "IDs of project issues", + "schema": { + "type": "array", + "items": { + "type": "string" + } + } + }, + { + "name": "fs_files", + "description": "IDs of linked files or dirs", + "schema": { + "type": "array", + "items": { + "type": "integer", + "minimum": 0 + } + } + }, + { + "name": "status", + "description": "Project status", + "schema": { + "type": "string", + "enum": [ + "planning", + "active", + "on_hold", + "completed", + "cancelled" + ] + } + }, + { + "name": "start_date", + "description": "Start date as string", + "schema": { + "type": "string" + } + }, + { + "name": "end_date", + "description": "End date as string", + "schema": { + "type": "string" + } + }, + { + "name": "securitypolicy", + "description": "Security policy ID", + "schema": { + "type": "integer", + "minimum": 0 + } + }, + { + "name": "tags", + "description": "Tags for the project", + "schema": { + "type": "array", + "items": { + "type": "string" + } + } + }, + { + "name": "comments", + "description": "Comments for the project", + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/CommentArg" + } + } + } + ], + "result": { + "name": "id", + "description": "ID of the created/updated project", + "schema": { + "type": "integer", + "minimum": 0 + } + } + }, + { + "name": "project_delete", + "summary": "Delete a project by ID", + "params": [ + { + "name": "id", + "description": "ID of project to delete", + "required": true, + "schema": { + "type": "integer", + "minimum": 0 + } + } + ], + "result": { + "name": "result", + "description": "Success result", + "schema": { + "type": "boolean" + } + } + }, + { + "name": "project_list", + "summary": "List all projects", + "params": [], + "result": { + "name": "projects", + "description": "List of all project objects", + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/Project" + } + } + } + }, + { + "name": "user_get", + "summary": "Get a user by ID", + "params": [ + { + "name": "id", + "description": "ID of user to fetch", + "required": true, + "schema": { + "type": "integer", + "minimum": 0 + } + } + ], + "result": { + "name": "user", + "description": "User object", + "schema": { + "$ref": "#/components/schemas/User" + } + } + }, + { + "name": "user_set", + "summary": "Create or update a user", + "params": [ + { + "name": "name", + "description": "Name of the user", + "required": true, + "schema": { + "type": "string" + } + }, + { + "name": "description", + "description": "Description of the user", + "schema": { + "type": "string" + } + }, + { + "name": "email", + "description": "Email of the user", + "schema": { + "type": "string" + } + }, + { + "name": "public_key", + "description": "Public key for encryption/signing", + "schema": { + "type": "string" + } + }, + { + "name": "phone", + "description": "Phone number of the user", + "schema": { + "type": "string" + } + }, + { + "name": "address", + "description": "Address of the user", + "schema": { + "type": "string" + } + }, + { + "name": "avatar_url", + "description": "Avatar URL of the user", + "schema": { + "type": "string" + } + }, + { + "name": "bio", + "description": "Bio of the user", + "schema": { + "type": "string" + } + }, + { + "name": "timezone", + "description": "Timezone of the user", + "schema": { + "type": "string" + } + }, + { + "name": "status", + "description": "User status", + "schema": { + "type": "string", + "enum": [ + "active", + "inactive", + "suspended", + "pending" + ] + } + }, + { + "name": "securitypolicy", + "description": "Security policy ID", + "schema": { + "type": "integer", + "minimum": 0 + } + }, + { + "name": "tags", + "description": "Tags for the user", + "schema": { + "type": "integer", + "minimum": 0 + } + }, + { + "name": "comments", + "description": "Comments for the user", + "schema": { + "type": "array", + "items": { + "type": "integer", + "minimum": 0 + } + } + } + ], + "result": { + "name": "id", + "description": "ID of the created/updated user", + "schema": { + "type": "integer", + "minimum": 0 + } + } + }, + { + "name": "user_delete", + "summary": "Delete a user by ID", + "params": [ + { + "name": "id", + "description": "ID of user to delete", + "required": true, + "schema": { + "type": "integer", + "minimum": 0 + } + } + ], + "result": { + "name": "result", + "description": "Success result", + "schema": { + "type": "boolean" + } + } + }, + { + "name": "user_list", + "summary": "List all users", + "params": [], + "result": { + "name": "users", + "description": "List of all user objects", + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/User" + } + } + } } ], "components": { @@ -309,6 +1632,557 @@ "type": "boolean" } } + }, + "CalendarEvent": { + "title": "CalendarEvent", + "description": "A calendar event object", + "allOf": [ + { + "$ref": "#/components/schemas/Base" + } + ], + "properties": { + "title": { + "type": "string" + }, + "start_time": { + "type": "integer" + }, + "end_time": { + "type": "integer" + }, + "location": { + "type": "string" + }, + "attendees": { + "type": "array", + "items": { + "type": "integer", + "minimum": 0 + } + }, + "fs_items": { + "type": "array", + "items": { + "type": "integer", + "minimum": 0 + } + }, + "calendar_id": { + "type": "integer", + "minimum": 0 + }, + "status": { + "type": "string", + "enum": [ + "draft", + "published", + "cancelled", + "completed" + ] + }, + "is_all_day": { + "type": "boolean" + }, + "is_recurring": { + "type": "boolean" + }, + "recurrence": { + "type": "array", + "items": { + "$ref": "#/components/schemas/RecurrenceRule" + } + }, + "reminder_mins": { + "type": "array", + "items": { + "type": "integer" + } + }, + "color": { + "type": "string" + }, + "timezone": { + "type": "string" + } + } + }, + "RecurrenceRule": { + "title": "RecurrenceRule", + "description": "A recurrence rule for calendar events", + "type": "object", + "properties": { + "frequency": { + "type": "string", + "enum": [ + "none", + "daily", + "weekly", + "monthly", + "yearly" + ] + }, + "interval": { + "type": "integer" + }, + "until": { + "type": "integer" + }, + "count": { + "type": "integer" + }, + "by_weekday": { + "type": "array", + "items": { + "type": "integer" + } + }, + "by_monthday": { + "type": "array", + "items": { + "type": "integer" + } + } + } + }, + "ChatGroup": { + "title": "ChatGroup", + "description": "A chat group object", + "allOf": [ + { + "$ref": "#/components/schemas/Base" + } + ], + "properties": { + "chat_type": { + "type": "string", + "enum": [ + "public_channel", + "private_channel", + "direct_message", + "group_message" + ] + }, + "last_activity": { + "type": "integer" + }, + "is_archived": { + "type": "boolean" + } + } + }, + "ChatMessage": { + "title": "ChatMessage", + "description": "A chat message object", + "allOf": [ + { + "$ref": "#/components/schemas/Base" + } + ], + "properties": { + "content": { + "type": "string" + }, + "chat_group_id": { + "type": "integer", + "minimum": 0 + }, + "sender_id": { + "type": "integer", + "minimum": 0 + }, + "parent_messages": { + "type": "array", + "items": { + "$ref": "#/components/schemas/MessageLink" + } + }, + "fs_files": { + "type": "array", + "items": { + "type": "integer", + "minimum": 0 + } + }, + "message_type": { + "type": "string", + "enum": [ + "text", + "image", + "file", + "voice", + "video", + "system", + "announcement" + ] + }, + "status": { + "type": "string", + "enum": [ + "sent", + "delivered", + "read", + "failed", + "deleted" + ] + }, + "reactions": { + "type": "array", + "items": { + "$ref": "#/components/schemas/MessageReaction" + } + }, + "mentions": { + "type": "array", + "items": { + "type": "integer", + "minimum": 0 + } + } + } + }, + "MessageLink": { + "title": "MessageLink", + "description": "A link to another message", + "type": "object", + "properties": { + "message_id": { + "type": "integer", + "minimum": 0 + }, + "link_type": { + "type": "string", + "enum": [ + "reply", + "reference", + "forward", + "quote" + ] + } + } + }, + "MessageReaction": { + "title": "MessageReaction", + "description": "A reaction to a message", + "type": "object", + "properties": { + "user_id": { + "type": "integer", + "minimum": 0 + }, + "emoji": { + "type": "string" + }, + "timestamp": { + "type": "integer" + } + } + }, + "Group": { + "title": "Group", + "description": "A group object", + "allOf": [ + { + "$ref": "#/components/schemas/Base" + } + ], + "properties": { + "members": { + "type": "array", + "items": { + "$ref": "#/components/schemas/GroupMember" + } + }, + "subgroups": { + "type": "array", + "items": { + "type": "integer", + "minimum": 0 + } + }, + "parent_group": { + "type": "integer", + "minimum": 0 + }, + "is_public": { + "type": "boolean" + } + } + }, + "GroupMember": { + "title": "GroupMember", + "description": "A group member", + "type": "object", + "properties": { + "user_id": { + "type": "integer", + "minimum": 0 + }, + "role": { + "type": "string", + "enum": [ + "reader", + "writer", + "admin", + "owner" + ] + }, + "joined_at": { + "type": "integer" + } + } + }, + "ProjectIssue": { + "title": "ProjectIssue", + "description": "A project issue object", + "allOf": [ + { + "$ref": "#/components/schemas/Base" + } + ], + "properties": { + "title": { + "type": "string" + }, + "project_id": { + "type": "integer", + "minimum": 0 + }, + "issue_type": { + "type": "string", + "enum": [ + "task", + "story", + "bug", + "question", + "epic", + "subtask" + ] + }, + "priority": { + "type": "string", + "enum": [ + "lowest", + "low", + "medium", + "high", + "highest", + "critical" + ] + }, + "status": { + "type": "string", + "enum": [ + "open", + "in_progress", + "blocked", + "review", + "testing", + "done", + "closed" + ] + }, + "swimlane": { + "type": "string" + }, + "assignees": { + "type": "array", + "items": { + "type": "integer", + "minimum": 0 + } + }, + "reporter": { + "type": "integer", + "minimum": 0 + }, + "milestone": { + "type": "string" + }, + "deadline": { + "type": "integer" + }, + "estimate": { + "type": "integer" + }, + "fs_files": { + "type": "array", + "items": { + "type": "integer", + "minimum": 0 + } + }, + "parent_id": { + "type": "integer", + "minimum": 0 + }, + "children": { + "type": "array", + "items": { + "type": "integer", + "minimum": 0 + } + } + } + }, + "Project": { + "title": "Project", + "description": "A project object", + "allOf": [ + { + "$ref": "#/components/schemas/Base" + } + ], + "properties": { + "swimlanes": { + "type": "array", + "items": { + "$ref": "#/components/schemas/Swimlane" + } + }, + "milestones": { + "type": "array", + "items": { + "$ref": "#/components/schemas/Milestone" + } + }, + "issues": { + "type": "array", + "items": { + "type": "string" + } + }, + "fs_files": { + "type": "array", + "items": { + "type": "integer", + "minimum": 0 + } + }, + "status": { + "type": "string", + "enum": [ + "planning", + "active", + "on_hold", + "completed", + "cancelled" + ] + }, + "start_date": { + "type": "integer" + }, + "end_date": { + "type": "integer" + } + } + }, + "Swimlane": { + "title": "Swimlane", + "description": "A project swimlane", + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "description": { + "type": "string" + }, + "order": { + "type": "integer" + }, + "color": { + "type": "string" + }, + "is_done": { + "type": "boolean" + } + } + }, + "Milestone": { + "title": "Milestone", + "description": "A project milestone", + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "description": { + "type": "string" + }, + "due_date": { + "type": "integer" + }, + "completed": { + "type": "boolean" + }, + "issues": { + "type": "array", + "items": { + "type": "integer", + "minimum": 0 + } + } + } + }, + "User": { + "title": "User", + "description": "A user object", + "allOf": [ + { + "$ref": "#/components/schemas/Base" + } + ], + "properties": { + "email": { + "type": "string" + }, + "public_key": { + "type": "string" + }, + "phone": { + "type": "string" + }, + "address": { + "type": "string" + }, + "avatar_url": { + "type": "string" + }, + "bio": { + "type": "string" + }, + "timezone": { + "type": "string" + }, + "status": { + "type": "string", + "enum": [ + "active", + "inactive", + "suspended", + "pending" + ] + } + } + }, + "CommentArg": { + "title": "CommentArg", + "description": "A comment argument", + "type": "object", + "properties": { + "comment": { + "type": "string" + }, + "parent": { + "type": "integer", + "minimum": 0 + }, + "author": { + "type": "integer", + "minimum": 0 + } + } } } } diff --git a/lib/hero/heromodels/rpc/rpc_calendar_event.v b/lib/hero/heromodels/rpc/rpc_calendar_event.v new file mode 100644 index 00000000..edfa7f1e --- /dev/null +++ b/lib/hero/heromodels/rpc/rpc_calendar_event.v @@ -0,0 +1,105 @@ +module rpc + +import json +import freeflowuniverse.herolib.schemas.jsonrpc { Request, Response, new_response_true, new_response_u32 } +import freeflowuniverse.herolib.hero.heromodels +import freeflowuniverse.herolib.hero.db +// CalendarEvent-specific argument structures + +@[params] +pub struct CalendarEventGetArgs { +pub mut: + id u32 @[required] +} + +@[params] +pub struct CalendarEventSetArgs { +pub mut: + name string + description string + title string + start_time string // use ourtime module to go from string to epoch + end_time string // use ourtime module to go from string to epoch + location string + attendees []u32 // IDs of user groups + fs_items []u32 // IDs of linked files or dirs + calendar_id u32 // Associated calendar + status heromodels.EventStatus + is_all_day bool + is_recurring bool + recurrence []heromodels.RecurrenceRule + reminder_mins []int // Minutes before event for reminders + color string // Hex color code + timezone string + securitypolicy u32 + tags []string + comments []db.CommentArg +} + +@[params] +pub struct CalendarEventDeleteArgs { +pub mut: + id u32 @[required] +} + +pub fn calendar_event_get(request Request) !Response { + payload := jsonrpc.decode_payload[CalendarEventGetArgs](request.params) or { + return jsonrpc.invalid_params + } + + mut mydb := heromodels.new()! + calendar_event := mydb.calendar_event.get(payload.id)! + + return jsonrpc.new_response(request.id, json.encode(calendar_event)) +} + +pub fn calendar_event_set(request Request) !Response { + payload := jsonrpc.decode_payload[CalendarEventSetArgs](request.params) or { + return jsonrpc.invalid_params + } + + mut mydb := heromodels.new()! + mut calendar_event_obj := mydb.calendar_event.new( + name: payload.name + description: payload.description + title: payload.title + start_time: payload.start_time + end_time: payload.end_time + location: payload.location + attendees: payload.attendees + fs_items: payload.fs_items + calendar_id: payload.calendar_id + status: payload.status + is_all_day: payload.is_all_day + is_recurring: payload.is_recurring + recurrence: payload.recurrence + reminder_mins: payload.reminder_mins + color: payload.color + timezone: payload.timezone + securitypolicy: payload.securitypolicy + tags: payload.tags + comments: payload.comments + )! + + id := mydb.calendar_event.set(calendar_event_obj)! + + return new_response_u32(request.id, id) +} + +pub fn calendar_event_delete(request Request) !Response { + payload := jsonrpc.decode_payload[CalendarEventDeleteArgs](request.params) or { + return jsonrpc.invalid_params + } + + mut mydb := heromodels.new()! + mydb.calendar_event.delete(payload.id)! + + return new_response_true(request.id) // return true as jsonrpc (bool) +} + +pub fn calendar_event_list(request Request) !Response { + mut mydb := heromodels.new()! + calendar_events := mydb.calendar_event.list()! + + return jsonrpc.new_response(request.id, json.encode(calendar_events)) +} diff --git a/lib/hero/heromodels/rpc/rpc_chat_group.v b/lib/hero/heromodels/rpc/rpc_chat_group.v new file mode 100644 index 00000000..b6e1afec --- /dev/null +++ b/lib/hero/heromodels/rpc/rpc_chat_group.v @@ -0,0 +1,83 @@ +module rpc + +import json +import freeflowuniverse.herolib.schemas.jsonrpc { Request, Response, new_response_true, new_response_u32 } +import freeflowuniverse.herolib.hero.heromodels +import freeflowuniverse.herolib.hero.db +// ChatGroup-specific argument structures + +@[params] +pub struct ChatGroupGetArgs { +pub mut: + id u32 @[required] +} + +@[params] +pub struct ChatGroupSetArgs { +pub mut: + name string + description string + chat_type heromodels.ChatType + last_activity i64 + is_archived bool + securitypolicy u32 + tags []string + comments []db.CommentArg +} + +@[params] +pub struct ChatGroupDeleteArgs { +pub mut: + id u32 @[required] +} + +pub fn chat_group_get(request Request) !Response { + payload := jsonrpc.decode_payload[ChatGroupGetArgs](request.params) or { + return jsonrpc.invalid_params + } + + mut mydb := heromodels.new()! + chat_group := mydb.chat_group.get(payload.id)! + + return jsonrpc.new_response(request.id, json.encode(chat_group)) +} + +pub fn chat_group_set(request Request) !Response { + payload := jsonrpc.decode_payload[ChatGroupSetArgs](request.params) or { + return jsonrpc.invalid_params + } + + mut mydb := heromodels.new()! + mut chat_group_obj := mydb.chat_group.new( + name: payload.name + description: payload.description + chat_type: payload.chat_type + last_activity: payload.last_activity + is_archived: payload.is_archived + securitypolicy: payload.securitypolicy + tags: payload.tags + comments: payload.comments + )! + + id := mydb.chat_group.set(chat_group_obj)! + + return new_response_u32(request.id, id) +} + +pub fn chat_group_delete(request Request) !Response { + payload := jsonrpc.decode_payload[ChatGroupDeleteArgs](request.params) or { + return jsonrpc.invalid_params + } + + mut mydb := heromodels.new()! + mydb.chat_group.delete(payload.id)! + + return new_response_true(request.id) // return true as jsonrpc (bool) +} + +pub fn chat_group_list(request Request) !Response { + mut mydb := heromodels.new()! + chat_groups := mydb.chat_group.list()! + + return jsonrpc.new_response(request.id, json.encode(chat_groups)) +} diff --git a/lib/hero/heromodels/rpc/rpc_chat_message.v b/lib/hero/heromodels/rpc/rpc_chat_message.v new file mode 100644 index 00000000..4eb97a80 --- /dev/null +++ b/lib/hero/heromodels/rpc/rpc_chat_message.v @@ -0,0 +1,95 @@ +module rpc + +import json +import freeflowuniverse.herolib.schemas.jsonrpc { Request, Response, new_response_true, new_response_u32 } +import freeflowuniverse.herolib.hero.heromodels +import freeflowuniverse.herolib.hero.db +// ChatMessage-specific argument structures + +@[params] +pub struct ChatMessageGetArgs { +pub mut: + id u32 @[required] +} + +@[params] +pub struct ChatMessageSetArgs { +pub mut: + name string + description string + content string + chat_group_id u32 + sender_id u32 + parent_messages []heromodels.MessageLink + fs_files []u32 + message_type heromodels.MessageType + status heromodels.MessageStatus + reactions []heromodels.MessageReaction + mentions []u32 + securitypolicy u32 + tags []string + comments []db.CommentArg +} + +@[params] +pub struct ChatMessageDeleteArgs { +pub mut: + id u32 @[required] +} + +pub fn chat_message_get(request Request) !Response { + payload := jsonrpc.decode_payload[ChatMessageGetArgs](request.params) or { + return jsonrpc.invalid_params + } + + mut mydb := heromodels.new()! + chat_message := mydb.chat_message.get(payload.id)! + + return jsonrpc.new_response(request.id, json.encode(chat_message)) +} + +pub fn chat_message_set(request Request) !Response { + payload := jsonrpc.decode_payload[ChatMessageSetArgs](request.params) or { + return jsonrpc.invalid_params + } + + mut mydb := heromodels.new()! + mut chat_message_obj := mydb.chat_message.new( + name: payload.name + description: payload.description + content: payload.content + chat_group_id: payload.chat_group_id + sender_id: payload.sender_id + parent_messages: payload.parent_messages + fs_files: payload.fs_files + message_type: payload.message_type + status: payload.status + reactions: payload.reactions + mentions: payload.mentions + securitypolicy: payload.securitypolicy + tags: payload.tags + comments: payload.comments + )! + + id := mydb.chat_message.set(chat_message_obj)! + + return new_response_u32(request.id, id) +} + +pub fn chat_message_delete(request Request) !Response { + payload := jsonrpc.decode_payload[ChatMessageDeleteArgs](request.params) or { + return jsonrpc.invalid_params + } + + mut mydb := heromodels.new()! + mydb.chat_message.delete(payload.id)! + + return new_response_true(request.id) // return true as jsonrpc (bool) +} + +pub fn chat_message_list(request Request) !Response { + mut mydb := heromodels.new()! + chat_messages := mydb.chat_message.list()! + + return jsonrpc.new_response(request.id, json.encode(chat_messages)) +} diff --git a/lib/hero/heromodels/rpc/rpc_group.v b/lib/hero/heromodels/rpc/rpc_group.v new file mode 100644 index 00000000..d1a6c7c7 --- /dev/null +++ b/lib/hero/heromodels/rpc/rpc_group.v @@ -0,0 +1,78 @@ +module rpc + +import json +import freeflowuniverse.herolib.schemas.jsonrpc { Request, Response, new_response_true, new_response_u32 } +import freeflowuniverse.herolib.hero.heromodels + +// Group-specific argument structures +@[params] +pub struct GroupGetArgs { +pub mut: + id u32 @[required] +} + +@[params] +pub struct GroupSetArgs { +pub mut: + name string + description string + members []heromodels.GroupMember + subgroups []u32 + parent_group u32 + is_public bool +} + +@[params] +pub struct GroupDeleteArgs { +pub mut: + id u32 @[required] +} + +pub fn group_get(request Request) !Response { + payload := jsonrpc.decode_payload[GroupGetArgs](request.params) or { + return jsonrpc.invalid_params + } + + mut mydb := heromodels.new()! + group := mydb.group.get(payload.id)! + + return jsonrpc.new_response(request.id, json.encode(group)) +} + +pub fn group_set(request Request) !Response { + payload := jsonrpc.decode_payload[GroupSetArgs](request.params) or { + return jsonrpc.invalid_params + } + + mut mydb := heromodels.new()! + mut group_obj := mydb.group.new( + name: payload.name + description: payload.description + members: payload.members + subgroups: payload.subgroups + parent_group: payload.parent_group + is_public: payload.is_public + )! + + id := mydb.group.set(group_obj)! + + return new_response_u32(request.id, id) +} + +pub fn group_delete(request Request) !Response { + payload := jsonrpc.decode_payload[GroupDeleteArgs](request.params) or { + return jsonrpc.invalid_params + } + + mut mydb := heromodels.new()! + mydb.group.delete(payload.id)! + + return new_response_true(request.id) // return true as jsonrpc (bool) +} + +pub fn group_list(request Request) !Response { + mut mydb := heromodels.new()! + groups := mydb.group.list()! + + return jsonrpc.new_response(request.id, json.encode(groups)) +} diff --git a/lib/hero/heromodels/rpc/rpc_project.v b/lib/hero/heromodels/rpc/rpc_project.v new file mode 100644 index 00000000..57b3ad72 --- /dev/null +++ b/lib/hero/heromodels/rpc/rpc_project.v @@ -0,0 +1,91 @@ +module rpc + +import json +import freeflowuniverse.herolib.schemas.jsonrpc { Request, Response, new_response_true, new_response_u32 } +import freeflowuniverse.herolib.hero.heromodels +import freeflowuniverse.herolib.hero.db + +// Project-specific argument structures +@[params] +pub struct ProjectGetArgs { +pub mut: + id u32 @[required] +} + +@[params] +pub struct ProjectSetArgs { +pub mut: + name string + description string + swimlanes []heromodels.Swimlane + milestones []heromodels.Milestone + issues []string + fs_files []u32 + status heromodels.ProjectStatus + start_date string // Use ourtime module to convert to epoch + end_date string // Use ourtime module to convert to epoch + securitypolicy u32 + tags []string + comments []db.CommentArg +} + +@[params] +pub struct ProjectDeleteArgs { +pub mut: + id u32 @[required] +} + +pub fn project_get(request Request) !Response { + payload := jsonrpc.decode_payload[ProjectGetArgs](request.params) or { + return jsonrpc.invalid_params + } + + mut mydb := heromodels.new()! + project := mydb.project.get(payload.id)! + + return jsonrpc.new_response(request.id, json.encode(project)) +} + +pub fn project_set(request Request) !Response { + payload := jsonrpc.decode_payload[ProjectSetArgs](request.params) or { + return jsonrpc.invalid_params + } + + mut mydb := heromodels.new()! + mut project_obj := mydb.project.new( + name: payload.name + description: payload.description + swimlanes: payload.swimlanes + milestones: payload.milestones + issues: payload.issues + fs_files: payload.fs_files + status: payload.status + start_date: payload.start_date + end_date: payload.end_date + securitypolicy: payload.securitypolicy + tags: payload.tags + comments: payload.comments + )! + + id := mydb.project.set(project_obj)! + + return new_response_u32(request.id, id) +} + +pub fn project_delete(request Request) !Response { + payload := jsonrpc.decode_payload[ProjectDeleteArgs](request.params) or { + return jsonrpc.invalid_params + } + + mut mydb := heromodels.new()! + mydb.project.delete(payload.id)! + + return new_response_true(request.id) // return true as jsonrpc (bool) +} + +pub fn project_list(request Request) !Response { + mut mydb := heromodels.new()! + projects := mydb.project.list()! + + return jsonrpc.new_response(request.id, json.encode(projects)) +} diff --git a/lib/hero/heromodels/rpc/rpc_project_issue.v b/lib/hero/heromodels/rpc/rpc_project_issue.v new file mode 100644 index 00000000..ab20f1ed --- /dev/null +++ b/lib/hero/heromodels/rpc/rpc_project_issue.v @@ -0,0 +1,105 @@ +module rpc + +import json +import freeflowuniverse.herolib.schemas.jsonrpc { Request, Response, new_response_true, new_response_u32 } +import freeflowuniverse.herolib.hero.heromodels +import freeflowuniverse.herolib.hero.db +// ProjectIssue-specific argument structures + +@[params] +pub struct ProjectIssueGetArgs { +pub mut: + id u32 @[required] +} + +@[params] +pub struct ProjectIssueSetArgs { +pub mut: + name string + description string + title string + project_id u32 + issue_type heromodels.IssueType + priority heromodels.IssuePriority + status heromodels.IssueStatus + swimlane string + assignees []u32 + reporter u32 + milestone string + deadline string // Use ourtime module to convert to epoch + estimate int + fs_files []u32 + parent_id u32 + children []u32 + securitypolicy u32 + tags []string + comments []db.CommentArg +} + +@[params] +pub struct ProjectIssueDeleteArgs { +pub mut: + id u32 @[required] +} + +pub fn project_issue_get(request Request) !Response { + payload := jsonrpc.decode_payload[ProjectIssueGetArgs](request.params) or { + return jsonrpc.invalid_params + } + + mut mydb := heromodels.new()! + project_issue := mydb.project_issue.get(payload.id)! + + return jsonrpc.new_response(request.id, json.encode(project_issue)) +} + +pub fn project_issue_set(request Request) !Response { + payload := jsonrpc.decode_payload[ProjectIssueSetArgs](request.params) or { + return jsonrpc.invalid_params + } + + mut mydb := heromodels.new()! + mut project_issue_obj := mydb.project_issue.new( + name: payload.name + description: payload.description + title: payload.title + project_id: payload.project_id + issue_type: payload.issue_type + priority: payload.priority + status: payload.status + swimlane: payload.swimlane + assignees: payload.assignees + reporter: payload.reporter + milestone: payload.milestone + deadline: payload.deadline + estimate: payload.estimate + fs_files: payload.fs_files + parent_id: payload.parent_id + children: payload.children + securitypolicy: payload.securitypolicy + tags: payload.tags + comments: payload.comments + )! + + id := mydb.project_issue.set(project_issue_obj)! + + return new_response_u32(request.id, id) +} + +pub fn project_issue_delete(request Request) !Response { + payload := jsonrpc.decode_payload[ProjectIssueDeleteArgs](request.params) or { + return jsonrpc.invalid_params + } + + mut mydb := heromodels.new()! + mydb.project_issue.delete(payload.id)! + + return new_response_true(request.id) // return true as jsonrpc (bool) +} + +pub fn project_issue_list(request Request) !Response { + mut mydb := heromodels.new()! + project_issues := mydb.project_issue.list()! + + return jsonrpc.new_response(request.id, json.encode(project_issues)) +} diff --git a/lib/hero/heromodels/rpc/rpc_user.v b/lib/hero/heromodels/rpc/rpc_user.v new file mode 100644 index 00000000..39c47052 --- /dev/null +++ b/lib/hero/heromodels/rpc/rpc_user.v @@ -0,0 +1,92 @@ +module rpc + +import json +import freeflowuniverse.herolib.schemas.jsonrpc { Request, Response, new_response_true, new_response_u32 } +import freeflowuniverse.herolib.hero.heromodels + +// User-specific argument structures +@[params] +pub struct UserGetArgs { +pub mut: + id u32 @[required] +} + +@[params] +pub struct UserSetArgs { +pub mut: + name string @[required] + description string + email string + public_key string // for encryption/signing + phone string + address string + avatar_url string + bio string + timezone string + status heromodels.UserStatus + securitypolicy u32 + tags u32 + comments []u32 +} + +@[params] +pub struct UserDeleteArgs { +pub mut: + id u32 @[required] +} + +pub fn user_get(request Request) !Response { + payload := jsonrpc.decode_payload[UserGetArgs](request.params) or { + return jsonrpc.invalid_params + } + + mut mydb := heromodels.new()! + user := mydb.user.get(payload.id)! + + return jsonrpc.new_response(request.id, json.encode(user)) +} + +pub fn user_set(request Request) !Response { + payload := jsonrpc.decode_payload[UserSetArgs](request.params) or { + return jsonrpc.invalid_params + } + + mut mydb := heromodels.new()! + mut user_obj := mydb.user.new( + name: payload.name + description: payload.description + email: payload.email + public_key: payload.public_key + phone: payload.phone + address: payload.address + avatar_url: payload.avatar_url + bio: payload.bio + timezone: payload.timezone + status: payload.status + securitypolicy: payload.securitypolicy + tags: payload.tags + comments: payload.comments + )! + + id := mydb.user.set(user_obj)! + + return new_response_u32(request.id, id) +} + +pub fn user_delete(request Request) !Response { + payload := jsonrpc.decode_payload[UserDeleteArgs](request.params) or { + return jsonrpc.invalid_params + } + + mut mydb := heromodels.new()! + mydb.user.delete(payload.id)! + + return new_response_true(request.id) // return true as jsonrpc (bool) +} + +pub fn user_list(request Request) !Response { + mut mydb := heromodels.new()! + users := mydb.user.list()! + + return jsonrpc.new_response(request.id, json.encode(users)) +}