This commit is contained in:
2025-09-19 12:57:01 +02:00
parent b66020cf64
commit bfafc06140
9 changed files with 377 additions and 9 deletions

View File

@@ -3,6 +3,9 @@ module heromodels
import freeflowuniverse.herolib.data.encoder
import freeflowuniverse.herolib.data.ourtime
import freeflowuniverse.herolib.hero.db
import freeflowuniverse.herolib.schemas.jsonrpc { Response, new_error, new_response, new_response_false, new_response_ok, new_response_true, new_response_int }
import freeflowuniverse.herolib.hero.user { UserRef }
import json
// CalendarEvent represents a single event in a calendar
@[heap]
@@ -276,3 +279,43 @@ pub fn (mut self DBCalendarEvent) get(id u32) !CalendarEvent {
pub fn (mut self DBCalendarEvent) list() ![]CalendarEvent {
return self.db.list[CalendarEvent]()!.map(self.get(it)!)
}
pub fn calendar_event_handle(mut f ModelsFactory, rpcid int, servercontext map[string]string, userref UserRef, method string, params string) !Response {
match method {
'get' {
id := db.decode_u32(params)!
res := f.calendar_event.get(id)!
return new_response(rpcid, json.encode(res))
}
'set' {
mut o := db.decode_generic[CalendarEvent](params)!
o = f.calendar_event.set(o)!
return new_response_int(rpcid, int(o.id))
}
'delete' {
id := db.decode_u32(params)!
f.calendar_event.delete(id)!
return new_response_ok(rpcid)
}
'exist' {
id := db.decode_u32(params)!
if f.calendar_event.exist(id)! {
return new_response_true(rpcid)
} else {
return new_response_false(rpcid)
}
}
'list' {
req := jsonrpc.new_request(method, '')
res := f.calendar_event.list()!
return new_response(req.id, json.encode(res))
}
else {
return new_error(rpcid,
code: 32601
message: 'Method ${method} not found on calendar_event'
)
}
}
}

View File

@@ -3,6 +3,9 @@ module heromodels
import freeflowuniverse.herolib.data.encoder
import freeflowuniverse.herolib.data.ourtime
import freeflowuniverse.herolib.hero.db
import freeflowuniverse.herolib.schemas.jsonrpc { Response, new_error, new_response, new_response_false, new_response_ok, new_response_true, new_response_int }
import freeflowuniverse.herolib.hero.user { UserRef }
import json
// ChatGroup represents a chat channel or conversation
@[heap]
@@ -145,3 +148,43 @@ pub fn (mut self DBChatGroup) get(id u32) !ChatGroup {
pub fn (mut self DBChatGroup) list() ![]ChatGroup {
return self.db.list[ChatGroup]()!.map(self.get(it)!)
}
pub fn chat_group_handle(mut f ModelsFactory, rpcid int, servercontext map[string]string, userref UserRef, method string, params string) !Response {
match method {
'get' {
id := db.decode_u32(params)!
res := f.chat_group.get(id)!
return new_response(rpcid, json.encode(res))
}
'set' {
mut o := db.decode_generic[ChatGroup](params)!
o = f.chat_group.set(o)!
return new_response_int(rpcid, int(o.id))
}
'delete' {
id := db.decode_u32(params)!
f.chat_group.delete(id)!
return new_response_ok(rpcid)
}
'exist' {
id := db.decode_u32(params)!
if f.chat_group.exist(id)! {
return new_response_true(rpcid)
} else {
return new_response_false(rpcid)
}
}
'list' {
req := jsonrpc.new_request(method, '')
res := f.chat_group.list()!
return new_response(req.id, json.encode(res))
}
else {
return new_error(rpcid,
code: 32601
message: 'Method ${method} not found on chat_group'
)
}
}
}

View File

@@ -3,6 +3,9 @@ module heromodels
import freeflowuniverse.herolib.data.encoder
import freeflowuniverse.herolib.data.ourtime
import freeflowuniverse.herolib.hero.db
import freeflowuniverse.herolib.schemas.jsonrpc { Response, new_error, new_response, new_response_false, new_response_ok, new_response_true, new_response_int }
import freeflowuniverse.herolib.hero.user { UserRef }
import json
// ChatMessage represents a message in a chat group
@[heap]
@@ -95,10 +98,10 @@ pub fn (self ChatMessage) description(methodname string) string {
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'
return '{"chat_message": {"content": "Hello, everyone!", "chat_group_id": 1, "sender_id": 1, "parent_messages": [{"message_id": 123, "link_type": "reply"}], "fs_files": [], "message_type": "text", "status": "sent", "reactions": [{"user_id": 2, "emoji": "👍", "timestamp": 1678886400}], "mentions": [2, 3]}}', '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": []}'
return '{"id": 1}', '{"content": "Hello, everyone!", "chat_group_id": 1, "sender_id": 1, "parent_messages": [{"message_id": 123, "link_type": "reply"}], "fs_files": [], "message_type": "text", "status": "sent", "reactions": [{"user_id": 2, "emoji": "👍", "timestamp": 1678886400}], "mentions": [2, 3]}'
}
'delete' {
return '{"id": 1}', 'true'
@@ -107,7 +110,7 @@ pub fn (self ChatMessage) example(methodname string) (string, string) {
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": []}]'
return '{}', '[{"content": "Hello, everyone!", "chat_group_id": 1, "sender_id": 1, "parent_messages": [{"message_id": 123, "link_type": "reply"}], "fs_files": [], "message_type": "text", "status": "sent", "reactions": [{"user_id": 2, "emoji": "👍", "timestamp": 1678886400}], "mentions": [2, 3]}]'
}
else {
return '{}', '{}'
@@ -249,3 +252,43 @@ pub fn (mut self DBChatMessage) get(id u32) !ChatMessage {
pub fn (mut self DBChatMessage) list() ![]ChatMessage {
return self.db.list[ChatMessage]()!.map(self.get(it)!)
}
pub fn chat_message_handle(mut f ModelsFactory, rpcid int, servercontext map[string]string, userref UserRef, method string, params string) !Response {
match method {
'get' {
id := db.decode_u32(params)!
res := f.chat_message.get(id)!
return new_response(rpcid, json.encode(res))
}
'set' {
mut o := db.decode_generic[ChatMessage](params)!
o = f.chat_message.set(o)!
return new_response_int(rpcid, int(o.id))
}
'delete' {
id := db.decode_u32(params)!
f.chat_message.delete(id)!
return new_response_ok(rpcid)
}
'exist' {
id := db.decode_u32(params)!
if f.chat_message.exist(id)! {
return new_response_true(rpcid)
} else {
return new_response_false(rpcid)
}
}
'list' {
req := jsonrpc.new_request(method, '')
res := f.chat_message.list()!
return new_response(req.id, json.encode(res))
}
else {
return new_error(rpcid,
code: 32601
message: 'Method ${method} not found on chat_message'
)
}
}
}

View File

@@ -4,6 +4,9 @@ import freeflowuniverse.herolib.data.encoder
import freeflowuniverse.herolib.data.ourtime
import freeflowuniverse.herolib.hero.db
import freeflowuniverse.herolib.schemas.jsonrpc { Response, new_error, new_response, new_response_false, new_response_ok, new_response_true, new_response_int }
import freeflowuniverse.herolib.hero.user { UserRef }
import json
@[heap]
pub struct Comment {
db.Base
@@ -128,3 +131,43 @@ pub fn (mut self DBComments) get(id u32) !Comment {
pub fn (mut self DBComments) list() ![]Comment {
return self.db.list[Comment]()!.map(self.get(it)!)
}
pub fn comment_handle(mut f ModelsFactory, rpcid int, servercontext map[string]string, userref UserRef, method string, params string) !Response {
match method {
'get' {
id := db.decode_u32(params)!
res := f.comments.get(id)!
return new_response(rpcid, json.encode(res))
}
'set' {
mut o := db.decode_generic[Comment](params)!
o = f.comments.set(o)!
return new_response_int(rpcid, int(o.id))
}
'delete' {
id := db.decode_u32(params)!
f.comments.delete(id)!
return new_response_ok(rpcid)
}
'exist' {
id := db.decode_u32(params)!
if f.comments.exist(id)! {
return new_response_true(rpcid)
} else {
return new_response_false(rpcid)
}
}
'list' {
req := jsonrpc.new_request(method, '')
res := f.comments.list()!
return new_response(req.id, json.encode(res))
}
else {
return new_error(rpcid,
code: 32601
message: 'Method ${method} not found on comment'
)
}
}
}

View File

@@ -106,6 +106,30 @@ pub fn group_api_handler(rpcid int, servercontext map[string]string, actorname s
'calendar' {
return calendar_handle(mut f, rpcid, servercontext, userref, methodname, params)!
}
'calendar_event' {
return calendar_event_handle(mut f, rpcid, servercontext, userref, methodname, params)!
}
'comment' {
return comment_handle(mut f, rpcid, servercontext, userref, methodname, params)!
}
'chat_group' {
return chat_group_handle(mut f, rpcid, servercontext, userref, methodname, params)!
}
'chat_message' {
return chat_message_handle(mut f, rpcid, servercontext, userref, methodname, params)!
}
'group' {
return group_handle(mut f, rpcid, servercontext, userref, methodname, params)!
}
'project' {
return project_handle(mut f, rpcid, servercontext, userref, methodname, params)!
}
'project_issue' {
return project_issue_handle(mut f, rpcid, servercontext, userref, methodname, params)!
}
'user' {
return user_handle(mut f, rpcid, servercontext, userref, methodname, params)!
}
else {
return jsonrpc.new_error(rpcid,
code: 32111

View File

@@ -3,6 +3,9 @@ module heromodels
import freeflowuniverse.herolib.data.encoder
import freeflowuniverse.herolib.data.ourtime
import freeflowuniverse.herolib.hero.db
import freeflowuniverse.herolib.schemas.jsonrpc { Response, new_error, new_response, new_response_false, new_response_ok, new_response_true, new_response_int }
import freeflowuniverse.herolib.hero.user { UserRef }
import json
// Group represents a collection of users with roles and permissions
@[heap]
@@ -61,10 +64,10 @@ pub fn (self Group) description(methodname string) string {
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'
return '{"group": {"name": "Admins", "description": "Administrators group", "members": [{"user_id": 1, "role": "admin", "joined_at": 1678886400}], "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}'
return '{"id": 1}', '{"name": "Admins", "description": "Administrators group", "members": [{"user_id": 1, "role": "admin", "joined_at": 1678886400}], "subgroups": [], "parent_group": 0, "is_public": false}'
}
'delete' {
return '{"id": 1}', 'true'
@@ -73,7 +76,7 @@ pub fn (self Group) example(methodname string) (string, string) {
return '{"id": 1}', 'true'
}
'list' {
return '{}', '[{"name": "Admins", "description": "Administrators group", "members": [], "subgroups": [], "parent_group": 0, "is_public": false}]'
return '{}', '[{"name": "Admins", "description": "Administrators group", "members": [{"user_id": 1, "role": "admin", "joined_at": 1678886400}], "subgroups": [], "parent_group": 0, "is_public": false}]'
}
else {
return '{}', '{}'
@@ -180,3 +183,43 @@ pub fn (mut self Group) add_member(user_id u32, role GroupRole) {
}
// CUSTOM FEATURES FOR GROUP
pub fn group_handle(mut f ModelsFactory, rpcid int, servercontext map[string]string, userref UserRef, method string, params string) !Response {
match method {
'get' {
id := db.decode_u32(params)!
res := f.group.get(id)!
return new_response(rpcid, json.encode(res))
}
'set' {
mut o := db.decode_generic[Group](params)!
o = f.group.set(o)!
return new_response_int(rpcid, int(o.id))
}
'delete' {
id := db.decode_u32(params)!
f.group.delete(id)!
return new_response_ok(rpcid)
}
'exist' {
id := db.decode_u32(params)!
if f.group.exist(id)! {
return new_response_true(rpcid)
} else {
return new_response_false(rpcid)
}
}
'list' {
req := jsonrpc.new_request(method, '')
res := f.group.list()!
return new_response(req.id, json.encode(res))
}
else {
return new_error(rpcid,
code: 32601
message: 'Method ${method} not found on group'
)
}
}
}

View File

@@ -3,6 +3,9 @@ module heromodels
import freeflowuniverse.herolib.data.encoder
import freeflowuniverse.herolib.data.ourtime
import freeflowuniverse.herolib.hero.db
import freeflowuniverse.herolib.schemas.jsonrpc { Response, new_error, new_response, new_response_false, new_response_ok, new_response_true, new_response_int }
import freeflowuniverse.herolib.hero.user { UserRef }
import json
// Project represents a collection of issues organized in swimlanes
@[heap]
@@ -81,10 +84,10 @@ pub fn (self Project) description(methodname string) string {
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'
return '{"project": {"name": "My Project", "description": "A project to track tasks", "swimlanes": [{"name": "To Do", "description": "Tasks to be done", "order": 1, "color": "#FF0000", "is_done": false}], "milestones": [{"name": "V1", "description": "Version 1", "due_date": 1678886400, "completed": false, "issues": [1, 2]}], "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"}'
return '{"id": 1}', '{"name": "My Project", "description": "A project to track tasks", "swimlanes": [{"name": "To Do", "description": "Tasks to be done", "order": 1, "color": "#FF0000", "is_done": false}], "milestones": [{"name": "V1", "description": "Version 1", "due_date": 1678886400, "completed": false, "issues": [1, 2]}], "issues": [], "fs_files": [], "status": "active", "start_date": "2025-01-01T00:00:00Z", "end_date": "2025-12-31T23:59:59Z"}'
}
'delete' {
return '{"id": 1}', 'true'
@@ -93,7 +96,7 @@ pub fn (self Project) example(methodname string) (string, string) {
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"}]'
return '{}', '[{"name": "My Project", "description": "A project to track tasks", "swimlanes": [{"name": "To Do", "description": "Tasks to be done", "order": 1, "color": "#FF0000", "is_done": false}], "milestones": [{"name": "V1", "description": "Version 1", "due_date": 1678886400, "completed": false, "issues": [1, 2]}], "issues": [], "fs_files": [], "status": "active", "start_date": "2025-01-01T00:00:00Z", "end_date": "2025-12-31T23:59:59Z"}]'
}
else {
return '{}', '{}'
@@ -240,3 +243,43 @@ pub fn (mut self DBProject) get(id u32) !Project {
pub fn (mut self DBProject) list() ![]Project {
return self.db.list[Project]()!.map(self.get(it)!)
}
pub fn project_handle(mut f ModelsFactory, rpcid int, servercontext map[string]string, userref UserRef, method string, params string) !Response {
match method {
'get' {
id := db.decode_u32(params)!
res := f.project.get(id)!
return new_response(rpcid, json.encode(res))
}
'set' {
mut o := db.decode_generic[Project](params)!
o = f.project.set(o)!
return new_response_int(rpcid, int(o.id))
}
'delete' {
id := db.decode_u32(params)!
f.project.delete(id)!
return new_response_ok(rpcid)
}
'exist' {
id := db.decode_u32(params)!
if f.project.exist(id)! {
return new_response_true(rpcid)
} else {
return new_response_false(rpcid)
}
}
'list' {
req := jsonrpc.new_request(method, '')
res := f.project.list()!
return new_response(req.id, json.encode(res))
}
else {
return new_error(rpcid,
code: 32601
message: 'Method ${method} not found on project'
)
}
}
}

View File

@@ -3,6 +3,9 @@ module heromodels
import freeflowuniverse.herolib.data.encoder
import freeflowuniverse.herolib.data.ourtime
import freeflowuniverse.herolib.hero.db
import freeflowuniverse.herolib.schemas.jsonrpc { Response, new_error, new_response, new_response_false, new_response_ok, new_response_true, new_response_int }
import freeflowuniverse.herolib.hero.user { UserRef }
import json
// ProjectIssue represents a task, story, bug, or question in a project
@[heap]
@@ -258,3 +261,43 @@ pub fn (mut self DBProjectIssue) get(id u32) !ProjectIssue {
pub fn (mut self DBProjectIssue) list() ![]ProjectIssue {
return self.db.list[ProjectIssue]()!.map(self.get(it)!)
}
pub fn project_issue_handle(mut f ModelsFactory, rpcid int, servercontext map[string]string, userref UserRef, method string, params string) !Response {
match method {
'get' {
id := db.decode_u32(params)!
res := f.project_issue.get(id)!
return new_response(rpcid, json.encode(res))
}
'set' {
mut o := db.decode_generic[ProjectIssue](params)!
o = f.project_issue.set(o)!
return new_response_int(rpcid, int(o.id))
}
'delete' {
id := db.decode_u32(params)!
f.project_issue.delete(id)!
return new_response_ok(rpcid)
}
'exist' {
id := db.decode_u32(params)!
if f.project_issue.exist(id)! {
return new_response_true(rpcid)
} else {
return new_response_false(rpcid)
}
}
'list' {
req := jsonrpc.new_request(method, '')
res := f.project_issue.list()!
return new_response(req.id, json.encode(res))
}
else {
return new_error(rpcid,
code: 32601
message: 'Method ${method} not found on project_issue'
)
}
}
}

View File

@@ -3,6 +3,9 @@ module heromodels
import freeflowuniverse.herolib.data.encoder
import freeflowuniverse.herolib.data.ourtime
import freeflowuniverse.herolib.hero.db
import freeflowuniverse.herolib.schemas.jsonrpc { Response, new_error, new_response, new_response_false, new_response_ok, new_response_true, new_response_int }
import freeflowuniverse.herolib.hero.user { UserRef }
import json
// User represents a person in the system
@[heap]
@@ -169,3 +172,43 @@ pub fn (mut self DBUser) get(id u32) !User {
pub fn (mut self DBUser) list() ![]User {
return self.db.list[User]()!.map(self.get(it)!)
}
pub fn user_handle(mut f ModelsFactory, rpcid int, servercontext map[string]string, userref UserRef, method string, params string) !Response {
match method {
'get' {
id := db.decode_u32(params)!
res := f.user.get(id)!
return new_response(rpcid, json.encode(res))
}
'set' {
mut o := db.decode_generic[User](params)!
o = f.user.set(o)!
return new_response_int(rpcid, int(o.id))
}
'delete' {
id := db.decode_u32(params)!
f.user.delete(id)!
return new_response_ok(rpcid)
}
'exist' {
id := db.decode_u32(params)!
if f.user.exist(id)! {
return new_response_true(rpcid)
} else {
return new_response_false(rpcid)
}
}
'list' {
req := jsonrpc.new_request(method, '')
res := f.user.list()!
return new_response(req.id, json.encode(res))
}
else {
return new_error(rpcid,
code: 32601
message: 'Method ${method} not found on user'
)
}
}
}