fix: Fix the examples

- Updated the examples to match the new fix of the heromodels
- Removed the caller variable of the set method since the method does
  not return a value now
This commit is contained in:
Mahmoud-Emad
2025-09-15 17:44:09 +03:00
parent ff16a9bc07
commit e2a894de29
22 changed files with 1494 additions and 1464 deletions

6
examples/hero/heromodels/heromodels_calendar_event.vsh Normal file → Executable file
View File

@@ -31,10 +31,10 @@ o.tags = mydb.calendar_event.db.tags_get(['work', 'meeting', 'team'])!
// Add comments if needed
// o.comments = mydb.calendar_event.db.comments_get([CommentArg{comment: 'This is a comment'}])!
oid := mydb.calendar_event.set(o)!
mut o2 := mydb.calendar_event.get(oid)!
mydb.calendar_event.set(mut o)!
mut o2 := mydb.calendar_event.get(o.id)!
println('Calendar Event ID: ${oid}')
println('Calendar Event ID: ${o.id}')
println('Calendar Event object: ${o2}')
mut objects := mydb.calendar_event.list()!

View File

@@ -41,10 +41,10 @@ o.tags = mydb.calendar_event.db.tags_get(['work', 'meeting', 'team'])!
// Add comments if needed
// o.comments = mydb.calendar_event.db.comments_get([CommentArg{comment: 'This is a comment'}])!
oid := mydb.calendar_event.set(o)!
mut o2 := mydb.calendar_event.get(oid)!
mydb.calendar_event.set(mut o)!
mut o2 := mydb.calendar_event.get(o.id)!
println('Calendar Event ID: ${oid}')
println('Calendar Event ID: ${o.id}')
println('Calendar Event object: ${o2}')
mut objects := mydb.calendar_event.list()!

10
examples/hero/heromodels/heromodels_chat_group.vsh Normal file → Executable file
View File

@@ -15,11 +15,11 @@ mut chat_group := mydb.chat_group.new(
)!
// Save to database
oid := mydb.chat_group.set(chat_group)!
println('Created chat group with ID: ${oid}')
mydb.chat_group.set(mut chat_group)!
println('Created chat group with ID: ${chat_group.id}')
// Retrieve from database
mut chat_group2 := mydb.chat_group.get(oid)!
mut chat_group2 := mydb.chat_group.get(chat_group.id)!
println('Retrieved chat group: ${chat_group2}')
// List all chat groups
@@ -29,8 +29,8 @@ println('All chat groups: ${chat_groups}')
// Update the chat group
chat_group2.is_archived = true
chat_group2.last_activity = 1672531200
mydb.chat_group.set(chat_group2)!
mydb.chat_group.set(mut chat_group2)!
// Retrieve updated chat group
mut chat_group3 := mydb.chat_group.get(oid)!
mut chat_group3 := mydb.chat_group.get(chat_group2.id)!
println('Updated chat group: ${chat_group3}')

15
examples/hero/heromodels/heromodels_chat_message.vsh Normal file → Executable file
View File

@@ -13,14 +13,15 @@ mut chat_group := mydb.chat_group.new(
last_activity: 0
is_archived: false
)!
chat_group_id := mydb.chat_group.set(chat_group)!
mydb.chat_group.set(mut chat_group)!
// Create a new chat message
mut chat_message := mydb.chat_message.new(
name: 'Hello World Message'
description: 'A simple hello world message'
content: 'Hello, world!'
chat_group_id: chat_group_id
chat_group_id: chat_group.id
sender_id: 1
parent_messages: []
fs_files: []
@@ -31,11 +32,11 @@ mut chat_message := mydb.chat_message.new(
)!
// Save to database
oid := mydb.chat_message.set(chat_message)!
println('Created chat message with ID: ${oid}')
mydb.chat_message.set(mut chat_message)!
println('Created chat message with ID: ${chat_message.id}')
// Retrieve from database
mut chat_message2 := mydb.chat_message.get(oid)!
mut chat_message2 := mydb.chat_message.get(chat_message.id)!
println('Retrieved chat message: ${chat_message2}')
// List all chat messages
@@ -44,8 +45,8 @@ println('All chat messages: ${chat_messages}')
// Update the chat message
chat_message2.status = .read
mydb.chat_message.set(chat_message2)!
mydb.chat_message.set(mut chat_message2)!
// Retrieve updated chat message
mut chat_message3 := mydb.chat_message.get(oid)!
mut chat_message3 := mydb.chat_message.get(chat_message.id)!
println('Updated chat message: ${chat_message3}')

14
examples/hero/heromodels/heromodels_group.vsh Normal file → Executable file
View File

@@ -18,15 +18,15 @@ mut o := mydb.group.new(
o.tags = mydb.group.db.tags_get(['team', 'development'])!
// Save to database
oid := mydb.group.set(o)!
println('Created Group ID: ${oid}')
mydb.group.set(mut o)!
println('Created Group ID: ${o.id}')
// Check if the group exists
mut exists := mydb.group.exist(oid)!
mut exists := mydb.group.exist(o.id)!
println('Group exists: ${exists}')
// Retrieve from database
mut o2 := mydb.group.get(oid)!
mut o2 := mydb.group.get(o.id)!
println('Retrieved Group object: ${o2}')
// List all groups
@@ -34,9 +34,9 @@ mut objects := mydb.group.list()!
println('All groups: ${objects}')
// Delete the group
mydb.group.delete(oid)!
println('Deleted group with ID: ${oid}')
mydb.group.delete(o.id)!
println('Deleted group with ID: ${o.id}')
// Check if the group still exists
exists = mydb.group.exist(oid)!
exists = mydb.group.exist(o.id)!
println('Group exists after deletion: ${exists}')

View File

@@ -23,11 +23,11 @@ o.add_member(3, heromodels.GroupRole.reader)
o.tags = mydb.group.db.tags_get(['team', 'marketing'])!
// Save to database
oid := mydb.group.set(o)!
println('Created Group ID: ${oid}')
mydb.group.set(mut o)!
println('Created Group ID: ${o.id}')
// Retrieve from database
mut o2 := mydb.group.get(oid)!
mut o2 := mydb.group.get(o.id)!
println('Retrieved Group object: ${o2}')
// Check the number of members

View File

@@ -14,8 +14,8 @@ mut parent_group := mydb.group.new(
parent_group: 0
)!
parent_oid := mydb.group.set(parent_group)!
println('Created Parent Group ID: ${parent_oid}')
mydb.group.set(mut parent_group)!
println('Created Parent Group ID: ${parent_group.id}')
// Create a subgroup
mut subgroup := mydb.group.new(
@@ -24,20 +24,20 @@ mut subgroup := mydb.group.new(
is_public: false
members: []
subgroups: []
parent_group: parent_oid
parent_group: parent_group.id
)!
sub_oid := mydb.group.set(subgroup)!
println('Created Subgroup ID: ${sub_oid}')
mydb.group.set(mut subgroup)!
println('Created Subgroup ID: ${subgroup.id}')
// Update the parent group to include the subgroup
mut updated_parent := mydb.group.get(parent_oid)!
updated_parent.subgroups = [sub_oid]
mydb.group.set(updated_parent)!
mut updated_parent := mydb.group.get(parent_group.id)!
updated_parent.subgroups = [subgroup.id]
mydb.group.set(mut updated_parent)!
// Retrieve both groups to verify relationships
mut parent_from_db := mydb.group.get(parent_oid)!
mut sub_from_db := mydb.group.get(sub_oid)!
mut parent_from_db := mydb.group.get(parent_group.id)!
mut sub_from_db := mydb.group.get(subgroup.id)!
println('Parent Group: ${parent_from_db}')
println('Subgroup: ${sub_from_db}')

View File

@@ -29,15 +29,15 @@ mut o := mydb.group.new(
o.tags = mydb.group.db.tags_get(['team', 'development'])!
// Save to database
oid := mydb.group.set(o)!
println('Created Group ID: ${oid}')
mydb.group.set(mut o)!
println('Created Group ID: ${o.id}')
// Check if the group exists
mut exists := mydb.group.exist(oid)!
mut exists := mydb.group.exist(o.id)!
println('Group exists: ${exists}')
// Retrieve from database
mut o2 := mydb.group.get(oid)!
mut o2 := mydb.group.get(o.id)!
println('Retrieved Group object: ${o2}')
// List all groups

14
examples/hero/heromodels/heromodels_project.vsh Normal file → Executable file
View File

@@ -1,4 +1,4 @@
#!/usr/bin/env -S v -n -w -cg -gc none -cc tcc -d use_openssl,enable_globals -no-skip-unused run
#!/usr/bin/env -S v -n -w -cg -gc none -cc tcc -d use_openssl -enable-globals -no-skip-unused run
import freeflowuniverse.herolib.hero.heromodels
import freeflowuniverse.herolib.hero.db
@@ -66,11 +66,11 @@ mut project := mydb.project.new(
)!
// Save the project to the database
project_id := mydb.project.set(project)!
println('Created project with ID: ${project_id}')
mydb.project.set(mut project)!
println('Created project with ID: ${project.id}')
// Retrieve the project from the database
mut retrieved_project := mydb.project.get(project_id)!
mut retrieved_project := mydb.project.get(project.id)!
println('Retrieved project: ${retrieved_project}')
// List all projects
@@ -78,13 +78,13 @@ mut all_projects := mydb.project.list()!
println('All projects: ${all_projects}')
// Check if the project exists
exists := mydb.project.exist(project_id)!
mut exists := mydb.project.exist(project.id)!
println('Project exists: ${exists}')
// Delete the project
mydb.project.delete(project_id)!
mydb.project.delete(project.id)!
println('Project deleted')
// Check if the project still exists
exists = mydb.project.exist(project_id)!
exists = mydb.project.exist(project.id)!
println('Project exists after deletion: ${exists}')

55
examples/hero/heromodels/heromodels_project_issue.vsh Normal file → Executable file
View File

@@ -1,4 +1,4 @@
#!/usr/bin/env -S v -n -w -cg -gc none -cc tcc -d use_openssl,enable_globals -no-skip-unused run
#!/usr/bin/env -S v -n -w -cg -gc none -cc tcc -d use_openssl -enable-globals -no-skip-unused run
import freeflowuniverse.herolib.hero.heromodels
import freeflowuniverse.herolib.hero.db
@@ -6,12 +6,51 @@ import freeflowuniverse.herolib.hero.db
mut mydb := heromodels.new()!
mydb.project_issue.db.redis.flushdb()!
// Create swimlanes
swimlane := heromodels.Swimlane{
name: 'todo'
description: 'Tasks to be done'
order: 1
color: '#FF0000'
is_done: false
}
// Create milestones
milestone := heromodels.Milestone{
name: 'phase_1'
description: 'First development phase'
due_date: 1672531200 // 2023-01-01
completed: false
issues: [u32(1), u32(2)]
}
// Create a new project
mut project := mydb.project.new(
name: 'Sample Project'
description: 'A sample project for demonstration'
swimlanes: [swimlane]
milestones: [milestone]
issues: ['issue1', 'issue2', 'issue3']
fs_files: [u32(100), u32(200)]
status: .active
start_date: '2023-01-01'
end_date: '2023-12-31'
tags: ['sample', 'demo', 'project']
comments: [db.CommentArg{
comment: 'This is a sample project'
}]
)!
// Save the project to the database
mydb.project.set(mut project)!
println('Created project with ID: ${project.id}')
// Create a new project issue
mut issue := mydb.project_issue.new(
name: 'Fix login bug'
description: 'Users are unable to login with their credentials'
title: 'Login functionality is broken'
project_id: u32(1)
project_id: project.id
issue_type: .bug
priority: .high
status: .open
@@ -36,11 +75,11 @@ mut issue := mydb.project_issue.new(
)!
// Save the issue to the database
issue_id := mydb.project_issue.set(issue)!
println('Created project issue with ID: ${issue_id}')
mydb.project_issue.set(mut issue)!
println('Created project issue with ID: ${issue.id}')
// Retrieve the issue from the database
mut retrieved_issue := mydb.project_issue.get(issue_id)!
mut retrieved_issue := mydb.project_issue.get(issue.id)!
println('Retrieved project issue: ${retrieved_issue}')
// List all project issues
@@ -48,13 +87,13 @@ mut all_issues := mydb.project_issue.list()!
println('All project issues: ${all_issues}')
// Check if the issue exists
exists := mydb.project_issue.exist(issue_id)!
mut exists := mydb.project_issue.exist(issue.id)!
println('Project issue exists: ${exists}')
// Delete the issue
mydb.project_issue.delete(issue_id)!
mydb.project_issue.delete(issue.id)!
println('Project issue deleted')
// Check if the issue still exists
exists = mydb.project_issue.exist(issue_id)!
exists = mydb.project_issue.exist(issue.id)!
println('Project issue exists after deletion: ${exists}')

14
examples/hero/heromodels/heromodels_user.vsh Normal file → Executable file
View File

@@ -22,15 +22,15 @@ mut o := mydb.user.new(
)!
// Save to database
oid := mydb.user.set(o)!
println('Created User ID: ${oid}')
mydb.user.set(mut o)!
println('Created User ID: ${o.id}')
// Check if the user exists
mut exists := mydb.user.exist(oid)!
mut exists := mydb.user.exist(o.id)!
println('User exists: ${exists}')
// Retrieve from database
mut o2 := mydb.user.get(oid)!
mut o2 := mydb.user.get(o.id)!
println('Retrieved User object: ${o2}')
// List all users
@@ -38,9 +38,9 @@ mut objects := mydb.user.list()!
println('All users: ${objects}')
// Delete the user
mydb.user.delete(oid)!
println('Deleted user with ID: ${oid}')
mydb.user.delete(o.id)!
println('Deleted user with ID: ${o.id}')
// Check if the user still exists
exists = mydb.user.exist(oid)!
exists = mydb.user.exist(o.id)!
println('User exists after deletion: ${exists}')

View File

@@ -1,12 +1,12 @@
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals -no-skip-unused run
import json
import freeflowuniverse.herolib.hero.heromodels.openrpc
import freeflowuniverse.herolib.hero.heromodels.rpc
import freeflowuniverse.herolib.schemas.jsonrpc
import freeflowuniverse.herolib.hero.heromodels
fn main() {
mut handler := openrpc.new_heromodels_handler()!
mut handler := rpc.new()!
my_calendar := heromodels.calendar_new(
name: 'My Calendar'

View File

@@ -31,13 +31,6 @@ pub fn (mut self DB) set[T](mut obj T) ! {
}
obj.dump(mut e)!
// $for method in T.methods {
// $if method.name == 'dump' {
// println(method)
// method.name(mut e)!
// }
// }
self.redis.hset(self.db_name[T](), obj.id.str(), e.data.bytestr())!
}

View File

@@ -1,281 +1,278 @@
module heromodels
// import freeflowuniverse.herolib.data.encoder
// import freeflowuniverse.herolib.data.ourtime
// import freeflowuniverse.herolib.hero.db
import freeflowuniverse.herolib.data.encoder
import freeflowuniverse.herolib.data.ourtime
import freeflowuniverse.herolib.hero.db
// // CalendarEvent represents a single event in a calendar
// @[heap]
// pub struct CalendarEvent {
// db.Base
// pub mut:
// title string
// start_time i64 // Unix timestamp
// end_time i64 // Unix timestamp
// location string
// attendees []u32 // IDs of user groups
// fs_items []u32 // IDs of linked files or dirs
// calendar_id u32 // Associated calendar
// status EventStatus
// is_all_day bool
// is_recurring bool
// recurrence []RecurrenceRule // normally empty
// reminder_mins []int // Minutes before event for reminders
// color string // Hex color code
// timezone string
// }
// CalendarEvent represents a single event in a calendar
@[heap]
pub struct CalendarEvent {
db.Base
pub mut:
title string
start_time i64 // Unix timestamp
end_time i64 // Unix timestamp
location string
attendees []u32 // IDs of user groups
fs_items []u32 // IDs of linked files or dirs
calendar_id u32 // Associated calendar
status EventStatus
is_all_day bool
is_recurring bool
recurrence []RecurrenceRule // normally empty
reminder_mins []int // Minutes before event for reminders
color string // Hex color code
timezone string
}
// pub struct Attendee {
// pub mut:
// user_id u32
// status AttendanceStatus
// role AttendeeRole
// }
pub struct Attendee {
pub mut:
user_id u32
status AttendanceStatus
role AttendeeRole
}
// pub enum AttendanceStatus {
// no_response
// accepted
// declined
// tentative
// }
pub enum AttendanceStatus {
no_response
accepted
declined
tentative
}
// pub enum AttendeeRole {
// required
// optional
// organizer
// }
pub enum AttendeeRole {
required
optional
organizer
}
// pub enum EventStatus {
// draft
// published
// cancelled
// completed
// }
pub enum EventStatus {
draft
published
cancelled
completed
}
// pub struct RecurrenceRule {
// pub mut:
// frequency RecurrenceFreq
// interval int // Every N frequencies
// until i64 // End date (Unix timestamp)
// count int // Number of occurrences
// by_weekday []int // Days of week (0=Sunday)
// by_monthday []int // Days of month
// }
pub struct RecurrenceRule {
pub mut:
frequency RecurrenceFreq
interval int // Every N frequencies
until i64 // End date (Unix timestamp)
count int // Number of occurrences
by_weekday []int // Days of week (0=Sunday)
by_monthday []int // Days of month
}
// pub enum RecurrenceFreq {
// none
// daily
// weekly
// monthly
// yearly
// }
pub enum RecurrenceFreq {
none
daily
weekly
monthly
yearly
}
// pub struct DBCalendarEvent {
// pub mut:
// db &db.DB @[skip; str: skip]
// }
pub struct DBCalendarEvent {
pub mut:
db &db.DB @[skip; str: skip]
}
// pub fn (self CalendarEvent) type_name() string {
// return 'calendar_event'
// }
pub fn (self CalendarEvent) type_name() string {
return 'calendar_event'
}
// // return example rpc call and result for each methodname
// pub fn (self CalendarEvent) description(methodname string) string {
// match methodname {
// 'set' {
// return 'Create or update a calendar event. Returns the ID of the event.'
// }
// 'get' {
// return 'Retrieve a calendar event by ID. Returns the event object.'
// }
// 'delete' {
// return 'Delete a calendar event by ID. Returns true if successful.'
// }
// 'exist' {
// return 'Check if a calendar event exists by ID. Returns true or false.'
// }
// 'list' {
// return 'List all calendar events. Returns an array of event 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 CalendarEvent) description(methodname string) string {
match methodname {
'set' {
return 'Create or update a calendar event. Returns the ID of the event.'
}
'get' {
return 'Retrieve a calendar event by ID. Returns the event object.'
}
'delete' {
return 'Delete a calendar event by ID. Returns true if successful.'
}
'exist' {
return 'Check if a calendar event exists by ID. Returns true or false.'
}
'list' {
return 'List all calendar events. Returns an array of event 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 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 '{}', '{}'
// }
// }
// }
// 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) ! {
// println('Dumping calendar event')
// // e.add_string(self.title)
// // e.add_i64(self.start_time)
// // e.add_i64(self.end_time)
// // e.add_string(self.location)
// // e.add_list_u32(self.attendees)
// // e.add_list_u32(self.fs_items)
// // e.add_u32(self.calendar_id)
// // e.add_u8(u8(self.status))
// // e.add_bool(self.is_all_day)
// // e.add_bool(self.is_recurring)
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)
e.add_string(self.location)
e.add_list_u32(self.attendees)
e.add_list_u32(self.fs_items)
e.add_u32(self.calendar_id)
e.add_u8(u8(self.status))
e.add_bool(self.is_all_day)
e.add_bool(self.is_recurring)
// println('Here we are')
// Encode recurrence array
e.add_u16(u16(self.recurrence.len))
for rule in self.recurrence {
e.add_u8(u8(rule.frequency))
e.add_int(rule.interval)
e.add_i64(rule.until)
e.add_int(rule.count)
e.add_list_int(rule.by_weekday)
e.add_list_int(rule.by_monthday)
}
// // Encode recurrence array
// // e.add_u16(u16(self.recurrence.len))
// // for rule in self.recurrence {
// // e.add_u8(u8(rule.frequency))
// // e.add_int(rule.interval)
// // e.add_i64(rule.until)
// // e.add_int(rule.count)
// // e.add_list_int(rule.by_weekday)
// // e.add_list_int(rule.by_monthday)
// // }
e.add_list_int(self.reminder_mins)
e.add_string(self.color)
e.add_string(self.timezone)
}
// // e.add_list_int(self.reminder_mins)
// // e.add_string(self.color)
// // e.add_string(self.timezone)
// }
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()!
o.location = e.get_string()!
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.is_all_day = e.get_bool()!
o.is_recurring = e.get_bool()!
// 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()!
// o.location = e.get_string()!
// 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.is_all_day = e.get_bool()!
// o.is_recurring = e.get_bool()!
// Decode recurrence array
recurrence_len := e.get_u16()!
mut recurrence := []RecurrenceRule{}
for _ in 0 .. recurrence_len {
frequency := unsafe { RecurrenceFreq(e.get_u8()!) }
interval := e.get_int()!
until := e.get_i64()!
count := e.get_int()!
by_weekday := e.get_list_int()!
by_monthday := e.get_list_int()!
// // Decode recurrence array
// recurrence_len := e.get_u16()!
// mut recurrence := []RecurrenceRule{}
// for _ in 0 .. recurrence_len {
// frequency := unsafe { RecurrenceFreq(e.get_u8()!) }
// interval := e.get_int()!
// until := e.get_i64()!
// count := e.get_int()!
// by_weekday := e.get_list_int()!
// by_monthday := e.get_list_int()!
recurrence << RecurrenceRule{
frequency: frequency
interval: interval
until: until
count: count
by_weekday: by_weekday
by_monthday: by_monthday
}
}
o.recurrence = recurrence
// recurrence << RecurrenceRule{
// frequency: frequency
// interval: interval
// until: until
// count: count
// by_weekday: by_weekday
// by_monthday: by_monthday
// }
// }
// o.recurrence = recurrence
o.reminder_mins = e.get_list_int()!
o.color = e.get_string()!
o.timezone = e.get_string()!
}
// o.reminder_mins = e.get_list_int()!
// o.color = e.get_string()!
// o.timezone = e.get_string()!
// }
@[params]
pub struct CalendarEventArg {
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 EventStatus
is_all_day bool
is_recurring bool
recurrence []RecurrenceRule
reminder_mins []int // Minutes before event for reminders
color string // Hex color code
timezone string
securitypolicy u32
tags []string
comments []db.CommentArg
}
// @[params]
// pub struct CalendarEventArg {
// 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 EventStatus
// is_all_day bool
// is_recurring bool
// recurrence []RecurrenceRule
// reminder_mins []int // Minutes before event for reminders
// color string // Hex color code
// timezone string
// securitypolicy u32
// tags []string
// comments []db.CommentArg
// }
// get new calendar event, not from the DB
pub fn (mut self DBCalendarEvent) new(args CalendarEventArg) !CalendarEvent {
mut o := CalendarEvent{
title: args.title
location: args.location
attendees: args.attendees
fs_items: args.fs_items
calendar_id: args.calendar_id
status: args.status
is_all_day: args.is_all_day
is_recurring: args.is_recurring
recurrence: args.recurrence
reminder_mins: args.reminder_mins
color: args.color
timezone: args.timezone
}
// // get new calendar event, not from the DB
// pub fn (mut self DBCalendarEvent) new(args CalendarEventArg) !CalendarEvent {
// mut o := CalendarEvent{
// title: args.title
// location: args.location
// attendees: args.attendees
// fs_items: args.fs_items
// calendar_id: args.calendar_id
// status: args.status
// is_all_day: args.is_all_day
// is_recurring: args.is_recurring
// recurrence: args.recurrence
// reminder_mins: args.reminder_mins
// color: args.color
// timezone: args.timezone
// }
// Set base fields
o.name = args.name
o.description = args.description
o.securitypolicy = args.securitypolicy
o.tags = self.db.tags_get(args.tags)!
o.comments = self.db.comments_get(args.comments)!
o.updated_at = ourtime.now().unix()
// // Set base fields
// o.name = args.name
// o.description = args.description
// o.securitypolicy = args.securitypolicy
// o.tags = self.db.tags_get(args.tags)!
// o.comments = self.db.comments_get(args.comments)!
// o.updated_at = ourtime.now().unix()
// Convert string times to Unix timestamps
mut start_time_obj := ourtime.new(args.start_time)!
o.start_time = start_time_obj.unix()
// // Convert string times to Unix timestamps
// mut start_time_obj := ourtime.new(args.start_time)!
// o.start_time = start_time_obj.unix()
mut end_time_obj := ourtime.new(args.end_time)!
o.end_time = end_time_obj.unix()
// mut end_time_obj := ourtime.new(args.end_time)!
// o.end_time = end_time_obj.unix()
return o
}
// return o
// }
pub fn (mut self DBCalendarEvent) set(mut o CalendarEvent) ! {
// Use db set function which now returns the ID
self.db.set[CalendarEvent](mut o)!
}
// pub fn (mut self DBCalendarEvent) set(mut o CalendarEvent) ! {
// // Use db set function which now returns the ID
// self.db.set[CalendarEvent](mut o)!
// }
pub fn (mut self DBCalendarEvent) delete(id u32) ! {
self.db.delete[CalendarEvent](id)!
}
// pub fn (mut self DBCalendarEvent) delete(id u32) ! {
// self.db.delete[CalendarEvent](id)!
// }
pub fn (mut self DBCalendarEvent) exist(id u32) !bool {
return self.db.exists[CalendarEvent](id)!
}
// pub fn (mut self DBCalendarEvent) exist(id u32) !bool {
// return self.db.exists[CalendarEvent](id)!
// }
pub fn (mut self DBCalendarEvent) get(id u32) !CalendarEvent {
mut o, data := self.db.get_data[CalendarEvent](id)!
mut e_decoder := encoder.decoder_new(data)
self.load(mut o, mut e_decoder)!
return o
}
// pub fn (mut self DBCalendarEvent) get(id u32) !CalendarEvent {
// mut o, data := self.db.get_data[CalendarEvent](id)!
// mut e_decoder := encoder.decoder_new(data)
// self.load(mut o, mut e_decoder)!
// return o
// }
// pub fn (mut self DBCalendarEvent) list() ![]CalendarEvent {
// return self.db.list[CalendarEvent]()!.map(self.get(it)!)
// }
pub fn (mut self DBCalendarEvent) list() ![]CalendarEvent {
return self.db.list[CalendarEvent]()!.map(self.get(it)!)
}

View File

@@ -1,147 +1,147 @@
module heromodels
// import freeflowuniverse.herolib.data.encoder
// import freeflowuniverse.herolib.data.ourtime
// import freeflowuniverse.herolib.hero.db
import freeflowuniverse.herolib.data.encoder
import freeflowuniverse.herolib.data.ourtime
import freeflowuniverse.herolib.hero.db
// // ChatGroup represents a chat channel or conversation
// @[heap]
// pub struct ChatGroup {
// db.Base
// pub mut:
// chat_type ChatType
// last_activity i64
// is_archived bool
// }
// ChatGroup represents a chat channel or conversation
@[heap]
pub struct ChatGroup {
db.Base
pub mut:
chat_type ChatType
last_activity i64
is_archived bool
}
// pub enum ChatType {
// public_channel
// private_channel
// direct_message
// group_message
// }
pub enum ChatType {
public_channel
private_channel
direct_message
group_message
}
// pub struct DBChatGroup {
// pub mut:
// db &db.DB @[skip; str: skip]
// }
pub struct DBChatGroup {
pub mut:
db &db.DB @[skip; str: skip]
}
// pub fn (self ChatGroup) type_name() string {
// return 'chat_group'
// }
pub fn (self ChatGroup) type_name() string {
return 'chat_group'
}
// // return example rpc call and result for each methodname
// pub fn (self ChatGroup) description(methodname string) string {
// match methodname {
// 'set' {
// return 'Create or update a chat group. Returns the ID of the chat group.'
// }
// 'get' {
// return 'Retrieve a chat group by ID. Returns the chat group object.'
// }
// 'delete' {
// return 'Delete a chat group by ID. Returns true if successful.'
// }
// 'exist' {
// return 'Check if a chat group exists by ID. Returns true or false.'
// }
// 'list' {
// return 'List all chat groups. Returns an array of chat group 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 ChatGroup) description(methodname string) string {
match methodname {
'set' {
return 'Create or update a chat group. Returns the ID of the chat group.'
}
'get' {
return 'Retrieve a chat group by ID. Returns the chat group object.'
}
'delete' {
return 'Delete a chat group by ID. Returns true if successful.'
}
'exist' {
return 'Check if a chat group exists by ID. Returns true or false.'
}
'list' {
return 'List all chat groups. Returns an array of chat group 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 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 '{}', '{}'
// }
// }
// }
// 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)
// }
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) ! {
// // o.chat_type = unsafe { ChatType(e.get_u8()!) }
// // o.last_activity = e.get_i64()!
// // o.is_archived = e.get_bool()!
// }
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()!
}
// @[params]
// pub struct ChatGroupArg {
// pub mut:
// name string
// description string
// chat_type ChatType
// last_activity i64
// is_archived bool
// securitypolicy u32
// tags []string
// comments []db.CommentArg
// }
@[params]
pub struct ChatGroupArg {
pub mut:
name string
description string
chat_type ChatType
last_activity i64
is_archived bool
securitypolicy u32
tags []string
comments []db.CommentArg
}
// // get new chat group, not from the DB
// pub fn (mut self DBChatGroup) new(args ChatGroupArg) !ChatGroup {
// mut o := ChatGroup{
// chat_type: args.chat_type
// last_activity: args.last_activity
// is_archived: args.is_archived
// }
// get new chat group, not from the DB
pub fn (mut self DBChatGroup) new(args ChatGroupArg) !ChatGroup {
mut o := ChatGroup{
chat_type: args.chat_type
last_activity: args.last_activity
is_archived: args.is_archived
}
// // Set base fields
// o.name = args.name
// o.description = args.description
// o.securitypolicy = args.securitypolicy
// o.tags = self.db.tags_get(args.tags)!
// o.comments = self.db.comments_get(args.comments)!
// o.updated_at = ourtime.now().unix()
// Set base fields
o.name = args.name
o.description = args.description
o.securitypolicy = args.securitypolicy
o.tags = self.db.tags_get(args.tags)!
o.comments = self.db.comments_get(args.comments)!
o.updated_at = ourtime.now().unix()
// return o
// }
return o
}
// pub fn (mut self DBChatGroup) set(mut o ChatGroup) ! {
// // Use db set function which now returns the ID
// self.db.set[ChatGroup](mut o)!
// }
pub fn (mut self DBChatGroup) set(mut o ChatGroup) ! {
// Use db set function which now returns the ID
self.db.set[ChatGroup](mut o)!
}
// pub fn (mut self DBChatGroup) delete(id u32) ! {
// self.db.delete[ChatGroup](id)!
// }
pub fn (mut self DBChatGroup) delete(id u32) ! {
self.db.delete[ChatGroup](id)!
}
// pub fn (mut self DBChatGroup) exist(id u32) !bool {
// return self.db.exists[ChatGroup](id)!
// }
pub fn (mut self DBChatGroup) exist(id u32) !bool {
return self.db.exists[ChatGroup](id)!
}
// pub fn (mut self DBChatGroup) get(id u32) !ChatGroup {
// mut o, data := self.db.get_data[ChatGroup](id)!
// mut e_decoder := encoder.decoder_new(data)
// self.load(mut o, mut e_decoder)!
// return o
// }
pub fn (mut self DBChatGroup) get(id u32) !ChatGroup {
mut o, data := self.db.get_data[ChatGroup](id)!
mut e_decoder := encoder.decoder_new(data)
self.load(mut o, mut e_decoder)!
return o
}
// pub fn (mut self DBChatGroup) list() ![]ChatGroup {
// return self.db.list[ChatGroup]()!.map(self.get(it)!)
// }
pub fn (mut self DBChatGroup) list() ![]ChatGroup {
return self.db.list[ChatGroup]()!.map(self.get(it)!)
}

View File

@@ -1,251 +1,251 @@
module heromodels
// import freeflowuniverse.herolib.data.encoder
// import freeflowuniverse.herolib.data.ourtime
// import freeflowuniverse.herolib.hero.db
import freeflowuniverse.herolib.data.encoder
import freeflowuniverse.herolib.data.ourtime
import freeflowuniverse.herolib.hero.db
// // ChatMessage represents a message in a chat group
// @[heap]
// pub struct ChatMessage {
// db.Base
// pub mut:
// content string
// chat_group_id u32 // Associated chat group
// sender_id u32 // User ID of sender
// parent_messages []MessageLink // Referenced/replied messages
// fs_files []u32 // IDs of linked files
// message_type MessageType
// status MessageStatus
// reactions []MessageReaction
// mentions []u32 // User IDs mentioned in message
// }
// ChatMessage represents a message in a chat group
@[heap]
pub struct ChatMessage {
db.Base
pub mut:
content string
chat_group_id u32 // Associated chat group
sender_id u32 // User ID of sender
parent_messages []MessageLink // Referenced/replied messages
fs_files []u32 // IDs of linked files
message_type MessageType
status MessageStatus
reactions []MessageReaction
mentions []u32 // User IDs mentioned in message
}
// pub struct MessageLink {
// pub mut:
// message_id u32
// link_type MessageLinkType
// }
pub struct MessageLink {
pub mut:
message_id u32
link_type MessageLinkType
}
// pub enum MessageLinkType {
// reply
// reference
// forward
// quote
// }
pub enum MessageLinkType {
reply
reference
forward
quote
}
// pub enum MessageType {
// text
// image
// file
// voice
// video
// system
// announcement
// }
pub enum MessageType {
text
image
file
voice
video
system
announcement
}
// pub enum MessageStatus {
// sent
// delivered
// read
// failed
// deleted
// }
pub enum MessageStatus {
sent
delivered
read
failed
deleted
}
// pub struct MessageReaction {
// pub mut:
// user_id u32
// emoji string
// timestamp i64
// }
pub struct MessageReaction {
pub mut:
user_id u32
emoji string
timestamp i64
}
// pub struct DBChatMessage {
// pub mut:
// db &db.DB @[skip; str: skip]
// }
pub struct DBChatMessage {
pub mut:
db &db.DB @[skip; str: skip]
}
// pub fn (self ChatMessage) type_name() string {
// return 'chat_message'
// }
pub fn (self ChatMessage) type_name() string {
return 'chat_message'
}
// // return example rpc call and result for each methodname
// pub fn (self ChatMessage) description(methodname string) string {
// match methodname {
// 'set' {
// return 'Create or update a chat message. Returns the ID of the message.'
// }
// 'get' {
// return 'Retrieve a chat message by ID. Returns the message object.'
// }
// 'delete' {
// return 'Delete a chat message by ID. Returns true if successful.'
// }
// 'exist' {
// return 'Check if a chat message exists by ID. Returns true or false.'
// }
// 'list' {
// return 'List all chat messages. Returns an array of message 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 ChatMessage) description(methodname string) string {
match methodname {
'set' {
return 'Create or update a chat message. Returns the ID of the message.'
}
'get' {
return 'Retrieve a chat message by ID. Returns the message object.'
}
'delete' {
return 'Delete a chat message by ID. Returns true if successful.'
}
'exist' {
return 'Check if a chat message exists by ID. Returns true or false.'
}
'list' {
return 'List all chat messages. Returns an array of message 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 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 '{}', '{}'
// }
// }
// }
// 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)
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)
// // // Encode parent_messages array
// // e.add_u16(u16(self.parent_messages.len))
// // for link in self.parent_messages {
// // e.add_u32(link.message_id)
// // e.add_u8(u8(link.link_type))
// // }
// Encode parent_messages array
e.add_u16(u16(self.parent_messages.len))
for link in self.parent_messages {
e.add_u32(link.message_id)
e.add_u8(u8(link.link_type))
}
// // e.add_list_u32(self.fs_files)
// // e.add_u8(u8(self.message_type))
// // e.add_u8(u8(self.status))
e.add_list_u32(self.fs_files)
e.add_u8(u8(self.message_type))
e.add_u8(u8(self.status))
// // // Encode reactions array
// // e.add_u16(u16(self.reactions.len))
// // for reaction in self.reactions {
// // e.add_u32(reaction.user_id)
// // e.add_string(reaction.emoji)
// // e.add_i64(reaction.timestamp)
// // }
// Encode reactions array
e.add_u16(u16(self.reactions.len))
for reaction in self.reactions {
e.add_u32(reaction.user_id)
e.add_string(reaction.emoji)
e.add_i64(reaction.timestamp)
}
// // e.add_list_u32(self.mentions)
// }
e.add_list_u32(self.mentions)
}
// 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()!
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()!
// // // Decode parent_messages array
// // parent_messages_len := e.get_u16()!
// // mut parent_messages := []MessageLink{}
// // for _ in 0 .. parent_messages_len {
// // message_id := e.get_u32()!
// // link_type := unsafe { MessageLinkType(e.get_u8()!) }
// // parent_messages << MessageLink{
// // message_id: message_id
// // link_type: link_type
// // }
// // }
// // o.parent_messages = parent_messages
// Decode parent_messages array
parent_messages_len := e.get_u16()!
mut parent_messages := []MessageLink{}
for _ in 0 .. parent_messages_len {
message_id := e.get_u32()!
link_type := unsafe { MessageLinkType(e.get_u8()!) }
parent_messages << MessageLink{
message_id: message_id
link_type: link_type
}
}
o.parent_messages = parent_messages
// // o.fs_files = e.get_list_u32()!
// // o.message_type = unsafe { MessageType(e.get_u8()!) }
// // o.status = unsafe { MessageStatus(e.get_u8()!) }
o.fs_files = e.get_list_u32()!
o.message_type = unsafe { MessageType(e.get_u8()!) }
o.status = unsafe { MessageStatus(e.get_u8()!) }
// // // Decode reactions array
// // reactions_len := e.get_u16()!
// // mut reactions := []MessageReaction{}
// // for _ in 0 .. reactions_len {
// // user_id := e.get_u32()!
// // emoji := e.get_string()!
// // timestamp := e.get_i64()!
// // reactions << MessageReaction{
// // user_id: user_id
// // emoji: emoji
// // timestamp: timestamp
// // }
// // }
// // o.reactions = reactions
// Decode reactions array
reactions_len := e.get_u16()!
mut reactions := []MessageReaction{}
for _ in 0 .. reactions_len {
user_id := e.get_u32()!
emoji := e.get_string()!
timestamp := e.get_i64()!
reactions << MessageReaction{
user_id: user_id
emoji: emoji
timestamp: timestamp
}
}
o.reactions = reactions
// // o.mentions = e.get_list_u32()!
// }
o.mentions = e.get_list_u32()!
}
// @[params]
// pub struct ChatMessageArg {
// pub mut:
// name string
// description string
// content string
// chat_group_id u32
// sender_id u32
// parent_messages []MessageLink
// fs_files []u32
// message_type MessageType
// status MessageStatus
// reactions []MessageReaction
// mentions []u32
// securitypolicy u32
// tags []string
// comments []db.CommentArg
// }
@[params]
pub struct ChatMessageArg {
pub mut:
name string
description string
content string
chat_group_id u32
sender_id u32
parent_messages []MessageLink
fs_files []u32
message_type MessageType
status MessageStatus
reactions []MessageReaction
mentions []u32
securitypolicy u32
tags []string
comments []db.CommentArg
}
// // get new chat message, not from the DB
// pub fn (mut self DBChatMessage) new(args ChatMessageArg) !ChatMessage {
// mut o := ChatMessage{
// content: args.content
// chat_group_id: args.chat_group_id
// sender_id: args.sender_id
// parent_messages: args.parent_messages
// fs_files: args.fs_files
// message_type: args.message_type
// status: args.status
// reactions: args.reactions
// mentions: args.mentions
// }
// get new chat message, not from the DB
pub fn (mut self DBChatMessage) new(args ChatMessageArg) !ChatMessage {
mut o := ChatMessage{
content: args.content
chat_group_id: args.chat_group_id
sender_id: args.sender_id
parent_messages: args.parent_messages
fs_files: args.fs_files
message_type: args.message_type
status: args.status
reactions: args.reactions
mentions: args.mentions
}
// // Set base fields
// o.name = args.name
// o.description = args.description
// o.securitypolicy = args.securitypolicy
// o.tags = self.db.tags_get(args.tags)!
// o.comments = self.db.comments_get(args.comments)!
// o.updated_at = ourtime.now().unix()
// Set base fields
o.name = args.name
o.description = args.description
o.securitypolicy = args.securitypolicy
o.tags = self.db.tags_get(args.tags)!
o.comments = self.db.comments_get(args.comments)!
o.updated_at = ourtime.now().unix()
// return o
// }
return o
}
// pub fn (mut self DBChatMessage) set(mut o ChatMessage) ! {
// // Use db set function which now returns the ID
// self.db.set[ChatMessage](mut o)!
// }
pub fn (mut self DBChatMessage) set(mut o ChatMessage) ! {
// Use db set function which now returns the ID
self.db.set[ChatMessage](mut o)!
}
// pub fn (mut self DBChatMessage) delete(id u32) ! {
// self.db.delete[ChatMessage](id)!
// }
pub fn (mut self DBChatMessage) delete(id u32) ! {
self.db.delete[ChatMessage](id)!
}
// pub fn (mut self DBChatMessage) exist(id u32) !bool {
// return self.db.exists[ChatMessage](id)!
// }
pub fn (mut self DBChatMessage) exist(id u32) !bool {
return self.db.exists[ChatMessage](id)!
}
// pub fn (mut self DBChatMessage) get(id u32) !ChatMessage {
// mut o, data := self.db.get_data[ChatMessage](id)!
// mut e_decoder := encoder.decoder_new(data)
// self.load(mut o, mut e_decoder)!
// return o
// }
pub fn (mut self DBChatMessage) get(id u32) !ChatMessage {
mut o, data := self.db.get_data[ChatMessage](id)!
mut e_decoder := encoder.decoder_new(data)
self.load(mut o, mut e_decoder)!
return o
}
// pub fn (mut self DBChatMessage) list() ![]ChatMessage {
// return self.db.list[ChatMessage]()!.map(self.get(it)!)
// }
pub fn (mut self DBChatMessage) list() ![]ChatMessage {
return self.db.list[ChatMessage]()!.map(self.get(it)!)
}

View File

@@ -4,46 +4,46 @@ import freeflowuniverse.herolib.hero.db
pub struct ModelsFactory {
pub mut:
comments DBComments
// calendar DBCalendar
// calendar_event DBCalendarEvent
// group DBGroup
// user DBUser
// project DBProject
// project_issue DBProjectIssue
// chat_group DBChatGroup
// chat_message DBChatMessage
comments DBComments
calendar DBCalendar
calendar_event DBCalendarEvent
group DBGroup
user DBUser
project DBProject
project_issue DBProjectIssue
chat_group DBChatGroup
chat_message DBChatMessage
}
pub fn new() !ModelsFactory {
mut mydb := db.new()!
return ModelsFactory{
comments: DBComments{
comments: DBComments{
db: &mydb
}
calendar: DBCalendar{
db: &mydb
}
calendar_event: DBCalendarEvent{
db: &mydb
}
group: DBGroup{
db: &mydb
}
user: DBUser{
db: &mydb
}
project: DBProject{
db: &mydb
}
project_issue: DBProjectIssue{
db: &mydb
}
chat_group: DBChatGroup{
db: &mydb
}
chat_message: DBChatMessage{
db: &mydb
}
// calendar: DBCalendar{
// db: &mydb
// }
// calendar_event: DBCalendarEvent{
// db: &mydb
// }
// group: DBGroup{
// db: &mydb
// }
// user: DBUser{
// db: &mydb
// }
// project: DBProject{
// db: &mydb
// }
// project_issue: DBProjectIssue{
// db: &mydb
// }
// chat_group: DBChatGroup{
// db: &mydb
// }
// chat_message: DBChatMessage{
// db: &mydb
// }
}
}

View File

@@ -1,182 +1,182 @@
module heromodels
// import freeflowuniverse.herolib.data.encoder
// import freeflowuniverse.herolib.data.ourtime
// import freeflowuniverse.herolib.hero.db
import freeflowuniverse.herolib.data.encoder
import freeflowuniverse.herolib.data.ourtime
import freeflowuniverse.herolib.hero.db
// // Group represents a collection of users with roles and permissions
// @[heap]
// pub struct Group {
// db.Base
// pub mut:
// members []GroupMember
// subgroups []u32 // IDs of child groups
// parent_group u32 // ID of parent group
// is_public bool
// }
// Group represents a collection of users with roles and permissions
@[heap]
pub struct Group {
db.Base
pub mut:
members []GroupMember
subgroups []u32 // IDs of child groups
parent_group u32 // ID of parent group
is_public bool
}
// pub struct GroupMember {
// pub mut:
// user_id u32
// role GroupRole
// joined_at i64
// }
pub struct GroupMember {
pub mut:
user_id u32
role GroupRole
joined_at i64
}
// pub enum GroupRole {
// reader
// writer
// admin
// owner
// }
pub enum GroupRole {
reader
writer
admin
owner
}
// pub fn (self Group) type_name() string {
// return 'group'
// }
pub fn (self Group) type_name() string {
return 'group'
}
// // return example rpc call and result for each methodname
// pub fn (self Group) description(methodname string) string {
// match methodname {
// 'set' {
// return 'Create or update a group. Returns the ID of the group.'
// }
// 'get' {
// return 'Retrieve a group by ID. Returns the group object.'
// }
// 'delete' {
// return 'Delete a group by ID. Returns true if successful.'
// }
// 'exist' {
// return 'Check if a group exists by ID. Returns true or false.'
// }
// 'list' {
// return 'List all groups. Returns an array of group 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 Group) description(methodname string) string {
match methodname {
'set' {
return 'Create or update a group. Returns the ID of the group.'
}
'get' {
return 'Retrieve a group by ID. Returns the group object.'
}
'delete' {
return 'Delete a group by ID. Returns true if successful.'
}
'exist' {
return 'Check if a group exists by ID. Returns true or false.'
}
'list' {
return 'List all groups. Returns an array of group 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 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 '{}', '{}'
// }
// }
// }
// 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)
// // e.add_u8(u8(member.role))
// // e.add_i64(member.joined_at)
// // }
// // e.add_list_u32(self.subgroups)
// // e.add_u32(self.parent_group)
// // e.add_bool(self.is_public)
// }
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)
e.add_u8(u8(member.role))
e.add_i64(member.joined_at)
}
e.add_list_u32(self.subgroups)
e.add_u32(self.parent_group)
e.add_bool(self.is_public)
}
// 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 {
// // user_id := e.get_u32()!
// // role := unsafe { GroupRole(e.get_u8()!) }
// // joined_at := e.get_i64()!
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 {
user_id := e.get_u32()!
role := unsafe { GroupRole(e.get_u8()!) }
joined_at := e.get_i64()!
// // members << GroupMember{
// // user_id: user_id
// // role: role
// // joined_at: joined_at
// // }
// // }
// // o.members = members
members << GroupMember{
user_id: user_id
role: role
joined_at: joined_at
}
}
o.members = members
// // o.subgroups = e.get_list_u32()!
// // o.parent_group = e.get_u32()!
// // o.is_public = e.get_bool()!
// }
o.subgroups = e.get_list_u32()!
o.parent_group = e.get_u32()!
o.is_public = e.get_bool()!
}
// @[params]
// pub struct GroupArg {
// pub mut:
// name string
// description string
// members []GroupMember
// subgroups []u32
// parent_group u32
// is_public bool
// }
@[params]
pub struct GroupArg {
pub mut:
name string
description string
members []GroupMember
subgroups []u32
parent_group u32
is_public bool
}
// pub struct DBGroup {
// pub mut:
// db &db.DB @[skip; str: skip]
// }
pub struct DBGroup {
pub mut:
db &db.DB @[skip; str: skip]
}
// // get new group, not from the DB
// pub fn (mut self DBGroup) new(args GroupArg) !Group {
// mut o := Group{
// members: args.members
// subgroups: args.subgroups
// parent_group: args.parent_group
// is_public: args.is_public
// }
// get new group, not from the DB
pub fn (mut self DBGroup) new(args GroupArg) !Group {
mut o := Group{
members: args.members
subgroups: args.subgroups
parent_group: args.parent_group
is_public: args.is_public
}
// // Set base fields
// o.name = args.name
// o.description = args.description
// o.updated_at = ourtime.now().unix()
// Set base fields
o.name = args.name
o.description = args.description
o.updated_at = ourtime.now().unix()
// return o
// }
return o
}
// pub fn (mut self DBGroup) set(mut o Group) ! {
// self.db.set[Group](mut o)!
// }
pub fn (mut self DBGroup) set(mut o Group) ! {
self.db.set[Group](mut o)!
}
// pub fn (mut self DBGroup) delete(id u32) ! {
// self.db.delete[Group](id)!
// }
pub fn (mut self DBGroup) delete(id u32) ! {
self.db.delete[Group](id)!
}
// pub fn (mut self DBGroup) exist(id u32) !bool {
// return self.db.exists[Group](id)!
// }
pub fn (mut self DBGroup) exist(id u32) !bool {
return self.db.exists[Group](id)!
}
// pub fn (mut self DBGroup) get(id u32) !Group {
// mut o, data := self.db.get_data[Group](id)!
// mut e_decoder := encoder.decoder_new(data)
// self.load(mut o, mut e_decoder)!
// return o
// }
pub fn (mut self DBGroup) get(id u32) !Group {
mut o, data := self.db.get_data[Group](id)!
mut e_decoder := encoder.decoder_new(data)
self.load(mut o, mut e_decoder)!
return o
}
// pub fn (mut self DBGroup) list() ![]Group {
// return self.db.list[Group]()!.map(self.get(it)!)
// }
pub fn (mut self DBGroup) list() ![]Group {
return self.db.list[Group]()!.map(self.get(it)!)
}
// pub fn (mut self Group) add_member(user_id u32, role GroupRole) {
// mut member := GroupMember{
// user_id: user_id
// role: role
// joined_at: ourtime.now().unix()
// }
// self.members << member
// }
pub fn (mut self Group) add_member(user_id u32, role GroupRole) {
mut member := GroupMember{
user_id: user_id
role: role
joined_at: ourtime.now().unix()
}
self.members << member
}
// // CUSTOM FEATURES FOR GROUP
// CUSTOM FEATURES FOR GROUP

View File

@@ -1,242 +1,242 @@
module heromodels
// import freeflowuniverse.herolib.data.encoder
// import freeflowuniverse.herolib.data.ourtime
// import freeflowuniverse.herolib.hero.db
import freeflowuniverse.herolib.data.encoder
import freeflowuniverse.herolib.data.ourtime
import freeflowuniverse.herolib.hero.db
// // Project represents a collection of issues organized in swimlanes
// @[heap]
// pub struct Project {
// db.Base
// pub mut:
// swimlanes []Swimlane
// milestones []Milestone
// issues []string // IDs of project issues
// fs_files []u32 // IDs of linked files or dirs
// status ProjectStatus
// start_date i64
// end_date i64
// }
// Project represents a collection of issues organized in swimlanes
@[heap]
pub struct Project {
db.Base
pub mut:
swimlanes []Swimlane
milestones []Milestone
issues []string // IDs of project issues
fs_files []u32 // IDs of linked files or dirs
status ProjectStatus
start_date i64
end_date i64
}
// pub struct Swimlane {
// pub mut:
// name string // allways to to_lower and trim_space
// description string
// order int
// color string
// is_done bool
// }
pub struct Swimlane {
pub mut:
name string // allways to to_lower and trim_space
description string
order int
color string
is_done bool
}
// pub struct Milestone {
// pub mut:
// name string // allways to to_lower and trim_space
// description string
// due_date i64
// completed bool
// issues []u32 // IDs of issues in this milestone
// }
pub struct Milestone {
pub mut:
name string // allways to to_lower and trim_space
description string
due_date i64
completed bool
issues []u32 // IDs of issues in this milestone
}
// pub enum ProjectStatus {
// planning
// active
// on_hold
// completed
// cancelled
// }
pub enum ProjectStatus {
planning
active
on_hold
completed
cancelled
}
// pub struct DBProject {
// pub mut:
// db &db.DB @[skip; str: skip]
// }
pub struct DBProject {
pub mut:
db &db.DB @[skip; str: skip]
}
// pub fn (self Project) type_name() string {
// return 'project'
// }
pub fn (self Project) type_name() string {
return 'project'
}
// // return example rpc call and result for each methodname
// pub fn (self Project) description(methodname string) string {
// match methodname {
// 'set' {
// return 'Create or update a project. Returns the ID of the project.'
// }
// 'get' {
// return 'Retrieve a project by ID. Returns the project object.'
// }
// 'delete' {
// return 'Delete a project by ID. Returns true if successful.'
// }
// 'exist' {
// return 'Check if a project exists by ID. Returns true or false.'
// }
// 'list' {
// return 'List all projects. Returns an array of project 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 Project) description(methodname string) string {
match methodname {
'set' {
return 'Create or update a project. Returns the ID of the project.'
}
'get' {
return 'Retrieve a project by ID. Returns the project object.'
}
'delete' {
return 'Delete a project by ID. Returns true if successful.'
}
'exist' {
return 'Check if a project exists by ID. Returns true or false.'
}
'list' {
return 'List all projects. Returns an array of project 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 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 '{}', '{}'
// }
// }
// }
// 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)
// // e.add_string(swimlane.description)
// // e.add_int(swimlane.order)
// // e.add_string(swimlane.color)
// // e.add_bool(swimlane.is_done)
// // }
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)
e.add_string(swimlane.description)
e.add_int(swimlane.order)
e.add_string(swimlane.color)
e.add_bool(swimlane.is_done)
}
// // e.add_u16(u16(self.milestones.len))
// // for milestone in self.milestones {
// // e.add_string(milestone.name)
// // e.add_string(milestone.description)
// // e.add_i64(milestone.due_date)
// // e.add_bool(milestone.completed)
// // e.add_list_u32(milestone.issues)
// // }
e.add_u16(u16(self.milestones.len))
for milestone in self.milestones {
e.add_string(milestone.name)
e.add_string(milestone.description)
e.add_i64(milestone.due_date)
e.add_bool(milestone.completed)
e.add_list_u32(milestone.issues)
}
// // e.add_list_string(self.issues)
// // e.add_list_u32(self.fs_files)
// // e.add_u8(u8(self.status))
// // e.add_i64(self.start_date)
// // e.add_i64(self.end_date)
// }
e.add_list_string(self.issues)
e.add_list_u32(self.fs_files)
e.add_u8(u8(self.status))
e.add_i64(self.start_date)
e.add_i64(self.end_date)
}
// 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 {
// // name := e.get_string()!
// // description := e.get_string()!
// // order := e.get_int()!
// // color := e.get_string()!
// // is_done := e.get_bool()!
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 {
name := e.get_string()!
description := e.get_string()!
order := e.get_int()!
color := e.get_string()!
is_done := e.get_bool()!
// // swimlanes << Swimlane{
// // name: name
// // description: description
// // order: order
// // color: color
// // is_done: is_done
// // }
// // }
// // o.swimlanes = swimlanes
swimlanes << Swimlane{
name: name
description: description
order: order
color: color
is_done: is_done
}
}
o.swimlanes = swimlanes
// // milestones_len := e.get_u16()!
// // mut milestones := []Milestone{}
// // for _ in 0 .. milestones_len {
// // name := e.get_string()!
// // description := e.get_string()!
// // due_date := e.get_i64()!
// // completed := e.get_bool()!
// // issues := e.get_list_u32()!
milestones_len := e.get_u16()!
mut milestones := []Milestone{}
for _ in 0 .. milestones_len {
name := e.get_string()!
description := e.get_string()!
due_date := e.get_i64()!
completed := e.get_bool()!
issues := e.get_list_u32()!
// // milestones << Milestone{
// // name: name
// // description: description
// // due_date: due_date
// // completed: completed
// // issues: issues
// // }
// // }
// // o.milestones = milestones
milestones << Milestone{
name: name
description: description
due_date: due_date
completed: completed
issues: issues
}
}
o.milestones = milestones
// // o.issues = e.get_list_string()!
// // o.fs_files = e.get_list_u32()!
// // o.status = unsafe { ProjectStatus(e.get_u8()!) }
// // o.start_date = e.get_i64()!
// // o.end_date = e.get_i64()!
// }
o.issues = e.get_list_string()!
o.fs_files = e.get_list_u32()!
o.status = unsafe { ProjectStatus(e.get_u8()!) }
o.start_date = e.get_i64()!
o.end_date = e.get_i64()!
}
// @[params]
// pub struct ProjectArg {
// pub mut:
// name string
// description string
// swimlanes []Swimlane
// milestones []Milestone
// issues []string
// fs_files []u32
// status 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 ProjectArg {
pub mut:
name string
description string
swimlanes []Swimlane
milestones []Milestone
issues []string
fs_files []u32
status 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
}
// // get new project, not from the DB
// pub fn (mut self DBProject) new(args ProjectArg) !Project {
// mut o := Project{
// swimlanes: args.swimlanes
// milestones: args.milestones
// issues: args.issues
// fs_files: args.fs_files
// status: args.status
// }
// get new project, not from the DB
pub fn (mut self DBProject) new(args ProjectArg) !Project {
mut o := Project{
swimlanes: args.swimlanes
milestones: args.milestones
issues: args.issues
fs_files: args.fs_files
status: args.status
}
// // Set base fields
// o.name = args.name
// o.description = args.description
// o.securitypolicy = args.securitypolicy
// o.tags = self.db.tags_get(args.tags)!
// o.comments = self.db.comments_get(args.comments)!
// o.updated_at = ourtime.now().unix()
// Set base fields
o.name = args.name
o.description = args.description
o.securitypolicy = args.securitypolicy
o.tags = self.db.tags_get(args.tags)!
o.comments = self.db.comments_get(args.comments)!
o.updated_at = ourtime.now().unix()
// // Convert string dates to Unix timestamps
// mut start_time_obj := ourtime.new(args.start_date)!
// o.start_date = start_time_obj.unix()
// Convert string dates to Unix timestamps
mut start_time_obj := ourtime.new(args.start_date)!
o.start_date = start_time_obj.unix()
// mut end_time_obj := ourtime.new(args.end_date)!
// o.end_date = end_time_obj.unix()
mut end_time_obj := ourtime.new(args.end_date)!
o.end_date = end_time_obj.unix()
// return o
// }
return o
}
// pub fn (mut self DBProject) set(mut o Project) ! {
// self.db.set[Project](mut o)!
// }
pub fn (mut self DBProject) set(mut o Project) ! {
self.db.set[Project](mut o)!
}
// pub fn (mut self DBProject) delete(id u32) ! {
// self.db.delete[Project](id)!
// }
pub fn (mut self DBProject) delete(id u32) ! {
self.db.delete[Project](id)!
}
// pub fn (mut self DBProject) exist(id u32) !bool {
// return self.db.exists[Project](id)!
// }
pub fn (mut self DBProject) exist(id u32) !bool {
return self.db.exists[Project](id)!
}
// pub fn (mut self DBProject) get(id u32) !Project {
// mut o, data := self.db.get_data[Project](id)!
// mut e_decoder := encoder.decoder_new(data)
// self.load(mut o, mut e_decoder)!
// return o
// }
pub fn (mut self DBProject) get(id u32) !Project {
mut o, data := self.db.get_data[Project](id)!
mut e_decoder := encoder.decoder_new(data)
self.load(mut o, mut e_decoder)!
return o
}
// pub fn (mut self DBProject) list() ![]Project {
// return self.db.list[Project]()!.map(self.get(it)!)
// }
pub fn (mut self DBProject) list() ![]Project {
return self.db.list[Project]()!.map(self.get(it)!)
}

View File

@@ -1,260 +1,260 @@
module heromodels
// import freeflowuniverse.herolib.data.encoder
// import freeflowuniverse.herolib.data.ourtime
// import freeflowuniverse.herolib.hero.db
import freeflowuniverse.herolib.data.encoder
import freeflowuniverse.herolib.data.ourtime
import freeflowuniverse.herolib.hero.db
// // ProjectIssue represents a task, story, bug, or question in a project
// @[heap]
// pub struct ProjectIssue {
// db.Base
// pub mut:
// title string
// project_id u32 // Associated project
// issue_type IssueType
// priority IssuePriority
// status IssueStatus
// swimlane string // Current swimlane, is string corresponds to name, need to be to_lower and trim_space
// assignees []u32 // User IDs
// reporter u32 // User ID who created the issue
// milestone string // Associated milestone, is string corresponds to name, need to be to_lower and trim_space
// deadline i64 // Unix timestamp
// estimate int // Story points or hours
// fs_files []u32 // IDs of linked files
// parent_id u32 // Parent issue ID (for sub-tasks)
// children []u32 // Child issue IDs
// }
// ProjectIssue represents a task, story, bug, or question in a project
@[heap]
pub struct ProjectIssue {
db.Base
pub mut:
title string
project_id u32 // Associated project
issue_type IssueType
priority IssuePriority
status IssueStatus
swimlane string // Current swimlane, is string corresponds to name, need to be to_lower and trim_space
assignees []u32 // User IDs
reporter u32 // User ID who created the issue
milestone string // Associated milestone, is string corresponds to name, need to be to_lower and trim_space
deadline i64 // Unix timestamp
estimate int // Story points or hours
fs_files []u32 // IDs of linked files
parent_id u32 // Parent issue ID (for sub-tasks)
children []u32 // Child issue IDs
}
// pub enum IssueType {
// task
// story
// bug
// question
// epic
// subtask
// }
pub enum IssueType {
task
story
bug
question
epic
subtask
}
// pub enum IssuePriority {
// lowest
// low
// medium
// high
// highest
// critical
// }
pub enum IssuePriority {
lowest
low
medium
high
highest
critical
}
// pub enum IssueStatus {
// open
// in_progress
// blocked
// review
// testing
// done
// closed
// }
pub enum IssueStatus {
open
in_progress
blocked
review
testing
done
closed
}
// pub struct DBProjectIssue {
// pub mut:
// db &db.DB @[skip; str: skip]
// }
pub struct DBProjectIssue {
pub mut:
db &db.DB @[skip; str: skip]
}
// pub fn (self ProjectIssue) type_name() string {
// return 'project_issue'
// }
pub fn (self ProjectIssue) type_name() string {
return 'project_issue'
}
// // return example rpc call and result for each methodname
// pub fn (self ProjectIssue) description(methodname string) string {
// match methodname {
// 'set' {
// return 'Create or update a project issue. Returns the ID of the issue.'
// }
// 'get' {
// return 'Retrieve a project issue by ID. Returns the issue object.'
// }
// 'delete' {
// return 'Delete a project issue by ID. Returns true if successful.'
// }
// 'exist' {
// return 'Check if a project issue exists by ID. Returns true or false.'
// }
// 'list' {
// return 'List all project issues. Returns an array of issue 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 ProjectIssue) description(methodname string) string {
match methodname {
'set' {
return 'Create or update a project issue. Returns the ID of the issue.'
}
'get' {
return 'Retrieve a project issue by ID. Returns the issue object.'
}
'delete' {
return 'Delete a project issue by ID. Returns true if successful.'
}
'exist' {
return 'Check if a project issue exists by ID. Returns true or false.'
}
'list' {
return 'List all project issues. Returns an array of issue 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 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 '{}', '{}'
// }
// }
// }
// 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))
// // e.add_u8(u8(self.priority))
// // e.add_u8(u8(self.status))
// // e.add_string(self.swimlane)
// // e.add_list_u32(self.assignees)
// // e.add_u32(self.reporter)
// // e.add_string(self.milestone)
// // e.add_i64(self.deadline)
// // e.add_int(self.estimate)
// // e.add_list_u32(self.fs_files)
// // e.add_u32(self.parent_id)
// // e.add_list_u32(self.children)
// }
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))
e.add_u8(u8(self.priority))
e.add_u8(u8(self.status))
e.add_string(self.swimlane)
e.add_list_u32(self.assignees)
e.add_u32(self.reporter)
e.add_string(self.milestone)
e.add_i64(self.deadline)
e.add_int(self.estimate)
e.add_list_u32(self.fs_files)
e.add_u32(self.parent_id)
e.add_list_u32(self.children)
}
// 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()!) }
// // o.priority = unsafe { IssuePriority(e.get_u8()!) }
// // o.status = unsafe { IssueStatus(e.get_u8()!) }
// // o.swimlane = e.get_string()!
// // o.assignees = e.get_list_u32()!
// // o.reporter = e.get_u32()!
// // o.milestone = e.get_string()!
// // o.deadline = e.get_i64()!
// // o.estimate = e.get_int()!
// // o.fs_files = e.get_list_u32()!
// // o.parent_id = e.get_u32()!
// // o.children = e.get_list_u32()!
// }
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()!) }
o.priority = unsafe { IssuePriority(e.get_u8()!) }
o.status = unsafe { IssueStatus(e.get_u8()!) }
o.swimlane = e.get_string()!
o.assignees = e.get_list_u32()!
o.reporter = e.get_u32()!
o.milestone = e.get_string()!
o.deadline = e.get_i64()!
o.estimate = e.get_int()!
o.fs_files = e.get_list_u32()!
o.parent_id = e.get_u32()!
o.children = e.get_list_u32()!
}
// @[params]
// pub struct ProjectIssueArg {
// pub mut:
// name string
// description string
// title string
// project_id u32
// issue_type IssueType
// priority IssuePriority
// status 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 ProjectIssueArg {
pub mut:
name string
description string
title string
project_id u32
issue_type IssueType
priority IssuePriority
status 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
}
// // get new project issue, not from the DB
// pub fn (mut self DBProjectIssue) new(args ProjectIssueArg) !ProjectIssue {
// mut o := ProjectIssue{
// title: args.title
// project_id: args.project_id
// issue_type: args.issue_type
// priority: args.priority
// status: args.status
// swimlane: args.swimlane.to_lower().trim_space()
// assignees: args.assignees
// reporter: args.reporter
// milestone: args.milestone.to_lower().trim_space()
// estimate: args.estimate
// fs_files: args.fs_files
// parent_id: args.parent_id
// children: args.children
// }
// get new project issue, not from the DB
pub fn (mut self DBProjectIssue) new(args ProjectIssueArg) !ProjectIssue {
mut o := ProjectIssue{
title: args.title
project_id: args.project_id
issue_type: args.issue_type
priority: args.priority
status: args.status
swimlane: args.swimlane.to_lower().trim_space()
assignees: args.assignees
reporter: args.reporter
milestone: args.milestone.to_lower().trim_space()
estimate: args.estimate
fs_files: args.fs_files
parent_id: args.parent_id
children: args.children
}
// // Validate that project_id exists
// mut db_project := DBProject{
// db: self.db
// }
// if !db_project.exist(args.project_id)! {
// return error('Project with ID ${args.project_id} does not exist')
// }
// Validate that project_id exists
mut db_project := DBProject{
db: self.db
}
if !db_project.exist(args.project_id)! {
return error('Project with ID ${args.project_id} does not exist')
}
// // Get the project to validate swimlane and milestone
// project_obj := db_project.get(args.project_id)!
// Get the project to validate swimlane and milestone
project_obj := db_project.get(args.project_id)!
// // Validate swimlane exists in the project
// mut swimlane_exists := false
// for swimlane in project_obj.swimlanes {
// if swimlane.name == o.swimlane {
// swimlane_exists = true
// break
// }
// }
// if !swimlane_exists {
// return error('Swimlane "${args.swimlane}" does not exist in project "${project_obj.name}"')
// }
// Validate swimlane exists in the project
mut swimlane_exists := false
for swimlane in project_obj.swimlanes {
if swimlane.name == o.swimlane {
swimlane_exists = true
break
}
}
if !swimlane_exists {
return error('Swimlane "${args.swimlane}" does not exist in project "${project_obj.name}"')
}
// // Validate milestone exists in the project
// mut milestone_exists := false
// for milestone in project_obj.milestones {
// if milestone.name == o.milestone {
// milestone_exists = true
// break
// }
// }
// if !milestone_exists {
// return error('Milestone "${args.milestone}" does not exist in project "${project_obj.name}"')
// }
// Validate milestone exists in the project
mut milestone_exists := false
for milestone in project_obj.milestones {
if milestone.name == o.milestone {
milestone_exists = true
break
}
}
if !milestone_exists {
return error('Milestone "${args.milestone}" does not exist in project "${project_obj.name}"')
}
// // Set base fields
// o.name = args.name
// o.description = args.description
// o.securitypolicy = args.securitypolicy
// o.tags = self.db.tags_get(args.tags)!
// o.comments = self.db.comments_get(args.comments)!
// o.updated_at = ourtime.now().unix()
// Set base fields
o.name = args.name
o.description = args.description
o.securitypolicy = args.securitypolicy
o.tags = self.db.tags_get(args.tags)!
o.comments = self.db.comments_get(args.comments)!
o.updated_at = ourtime.now().unix()
// // Convert deadline string to Unix timestamp
// mut deadline_obj := ourtime.new(args.deadline)!
// o.deadline = deadline_obj.unix()
// Convert deadline string to Unix timestamp
mut deadline_obj := ourtime.new(args.deadline)!
o.deadline = deadline_obj.unix()
// return o
// }
return o
}
// pub fn (mut self DBProjectIssue) set(mut o ProjectIssue) ! {
// self.db.set[ProjectIssue](mut o)!
// }
pub fn (mut self DBProjectIssue) set(mut o ProjectIssue) ! {
self.db.set[ProjectIssue](mut o)!
}
// pub fn (mut self DBProjectIssue) delete(id u32) ! {
// self.db.delete[ProjectIssue](id)!
// }
pub fn (mut self DBProjectIssue) delete(id u32) ! {
self.db.delete[ProjectIssue](id)!
}
// pub fn (mut self DBProjectIssue) exist(id u32) !bool {
// return self.db.exists[ProjectIssue](id)!
// }
pub fn (mut self DBProjectIssue) exist(id u32) !bool {
return self.db.exists[ProjectIssue](id)!
}
// pub fn (mut self DBProjectIssue) get(id u32) !ProjectIssue {
// mut o, data := self.db.get_data[ProjectIssue](id)!
// mut e_decoder := encoder.decoder_new(data)
// self.load(mut o, mut e_decoder)!
// return o
// }
pub fn (mut self DBProjectIssue) get(id u32) !ProjectIssue {
mut o, data := self.db.get_data[ProjectIssue](id)!
mut e_decoder := encoder.decoder_new(data)
self.load(mut o, mut e_decoder)!
return o
}
// pub fn (mut self DBProjectIssue) list() ![]ProjectIssue {
// return self.db.list[ProjectIssue]()!.map(self.get(it)!)
// }
pub fn (mut self DBProjectIssue) list() ![]ProjectIssue {
return self.db.list[ProjectIssue]()!.map(self.get(it)!)
}

View File

@@ -54,9 +54,9 @@ pub fn calendar_set(request Request) !Response {
events: payload.events
)!
id := mydb.calendar.set(calendar_obj)!
mydb.calendar.set(mut calendar_obj)!
return new_response_u32(request.id, id)
return new_response_u32(request.id, calendar_obj.id)
}
pub fn calendar_delete(request Request) !Response {

View File

@@ -1,171 +1,171 @@
module heromodels
// import freeflowuniverse.herolib.data.encoder
// import freeflowuniverse.herolib.data.ourtime
// import freeflowuniverse.herolib.hero.db
import freeflowuniverse.herolib.data.encoder
import freeflowuniverse.herolib.data.ourtime
import freeflowuniverse.herolib.hero.db
// // User represents a person in the system
// @[heap]
// pub struct User {
// db.Base
// pub mut:
// email string
// public_key string // for encryption/signing
// phone string
// address string
// avatar_url string
// bio string
// timezone string
// status UserStatus
// }
// User represents a person in the system
@[heap]
pub struct User {
db.Base
pub mut:
email string
public_key string // for encryption/signing
phone string
address string
avatar_url string
bio string
timezone string
status UserStatus
}
// pub enum UserStatus {
// active
// inactive
// suspended
// pending
// }
pub enum UserStatus {
active
inactive
suspended
pending
}
// pub fn (self User) type_name() string {
// return 'user'
// }
pub fn (self User) type_name() string {
return 'user'
}
// // 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) 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 '{}', '{}'
// }
// }
// }
// 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)
// // e.add_string(self.address)
// // e.add_string(self.avatar_url)
// // e.add_string(self.bio)
// // e.add_string(self.timezone)
// // e.add_u8(u8(self.status))
// }
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)
e.add_string(self.address)
e.add_string(self.avatar_url)
e.add_string(self.bio)
e.add_string(self.timezone)
e.add_u8(u8(self.status))
}
// 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()!
// // o.address = e.get_string()!
// // o.avatar_url = e.get_string()!
// // o.bio = e.get_string()!
// // o.timezone = e.get_string()!
// // o.status = unsafe { UserStatus(e.get_u8()!) }
// }
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()!
o.address = e.get_string()!
o.avatar_url = e.get_string()!
o.bio = e.get_string()!
o.timezone = e.get_string()!
o.status = unsafe { UserStatus(e.get_u8()!) }
}
// @[params]
// pub struct UserArg {
// 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 UserStatus
// securitypolicy u32
// tags u32
// comments []u32
// }
@[params]
pub struct UserArg {
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 UserStatus
securitypolicy u32
tags u32
comments []u32
}
// pub struct DBUser {
// pub mut:
// db &db.DB @[skip; str: skip]
// }
pub struct DBUser {
pub mut:
db &db.DB @[skip; str: skip]
}
// // get new user, not from the DB
// pub fn (mut self DBUser) new(args UserArg) !User {
// mut o := User{
// email: args.email
// public_key: args.public_key
// phone: args.phone
// address: args.address
// avatar_url: args.avatar_url
// bio: args.bio
// timezone: args.timezone
// status: args.status
// }
// get new user, not from the DB
pub fn (mut self DBUser) new(args UserArg) !User {
mut o := User{
email: args.email
public_key: args.public_key
phone: args.phone
address: args.address
avatar_url: args.avatar_url
bio: args.bio
timezone: args.timezone
status: args.status
}
// // Set base fields
// o.name = args.name
// o.description = args.description
// o.securitypolicy = args.securitypolicy
// o.tags = args.tags
// o.comments = args.comments
// o.updated_at = ourtime.now().unix()
// Set base fields
o.name = args.name
o.description = args.description
o.securitypolicy = args.securitypolicy
o.tags = args.tags
o.comments = args.comments
o.updated_at = ourtime.now().unix()
// return o
// }
return o
}
// pub fn (mut self DBUser) set(mut o User) ! {
// self.db.set[User](mut o)!
// }
pub fn (mut self DBUser) set(mut o User) ! {
self.db.set[User](mut o)!
}
// pub fn (mut self DBUser) delete(id u32) ! {
// self.db.delete[User](id)!
// }
pub fn (mut self DBUser) delete(id u32) ! {
self.db.delete[User](id)!
}
// pub fn (mut self DBUser) exist(id u32) !bool {
// return self.db.exists[User](id)!
// }
pub fn (mut self DBUser) exist(id u32) !bool {
return self.db.exists[User](id)!
}
// pub fn (mut self DBUser) get(id u32) !User {
// mut o, data := self.db.get_data[User](id)!
// mut e_decoder := encoder.decoder_new(data)
// self.load(mut o, mut e_decoder)!
// return o
// }
pub fn (mut self DBUser) get(id u32) !User {
mut o, data := self.db.get_data[User](id)!
mut e_decoder := encoder.decoder_new(data)
self.load(mut o, mut e_decoder)!
return o
}
// pub fn (mut self DBUser) list() ![]User {
// return self.db.list[User]()!.map(self.get(it)!)
// }
pub fn (mut self DBUser) list() ![]User {
return self.db.list[User]()!.map(self.get(it)!)
}