diff --git a/examples/hero/heromodels/heroserver_example.vsh b/examples/hero/heromodels/heroserver_example.vsh index 408d6ef2..01cb77f0 100755 --- a/examples/hero/heromodels/heroserver_example.vsh +++ b/examples/hero/heromodels/heroserver_example.vsh @@ -10,7 +10,7 @@ fn main() { heromodels.new(reset: true, name: 'test')! heromodels.server_start( name: 'test' - port: 8086 + port: 8080 auth_enabled: false // Disable auth for testing cors_enabled: true reset: true diff --git a/examples/hero/heroserver/heroserver.vsh b/examples/hero/heroserver/heroserver.vsh index f650f2fc..f10a1946 100755 --- a/examples/hero/heroserver/heroserver.vsh +++ b/examples/hero/heroserver/heroserver.vsh @@ -5,7 +5,7 @@ import freeflowuniverse.herolib.schemas.openrpc import os // 1. Create a new server instance -mut server := heroserver.new(port: 8086)! +mut server := heroserver.new(port: 8080)! // 2. Create and register your OpenRPC handlers // These handlers must conform to the `openrpc.OpenRPCHandler` interface. @@ -14,8 +14,8 @@ openrpc_path := os.join_path(script_dir, 'openrpc.json') handler := openrpc.new_handler(openrpc_path)! server.register_handler('comments', handler)! -println('Server starting on http://localhost:8086') -println('Documentation available at: http://localhost:8086/doc/comments/') -println('Comments API available at: http://localhost:8086/api/comments') +println('Server starting on http://localhost:8080') +println('Documentation available at: http://localhost:8080/doc/comments/') +println('Comments API available at: http://localhost:8080/api/comments') server.start()! diff --git a/lib/core/logger/log.v b/lib/core/logger/log.v index 2f70ffeb..776e117c 100644 --- a/lib/core/logger/log.v +++ b/lib/core/logger/log.v @@ -3,6 +3,7 @@ module logger import os import freeflowuniverse.herolib.core.texttools import freeflowuniverse.herolib.data.ourtime +import freeflowuniverse.herolib.ui.console @[params] pub struct LogItemArgs { @@ -77,10 +78,10 @@ fn (mut l Logger) write_to_console(args LogItemArgs, t ourtime.OurTime) ! { for i, line in lines { if i == 0 { - println('${timestamp} [${error_indicator}] [${category}] ${line}') + console.print_info('${timestamp} [${error_indicator}] [${category}] ${line}') } else { // Indent continuation lines - println('${timestamp} [${error_indicator}] [${category}] ${line}') + console.print_info('${timestamp} [${error_indicator}] [${category}] ${line}') } } } diff --git a/lib/hero/db/decode.v b/lib/hero/db/decode.v index 5a86ce30..e9464a17 100644 --- a/lib/hero/db/decode.v +++ b/lib/hero/db/decode.v @@ -16,10 +16,6 @@ pub fn decode_bool(data string) !bool { } pub fn decode_generic[T](data string) !T { - mut r := json.decode(T, data) or { - println('Failed to decode T: \n***\n${data}\n***\n${err}') - println(T{}) - return error('Failed to decode T: ${data}\n${err}') - } + mut r := json.decode(T, data) or { return error('Failed to decode T: ${data}\n${err}') } return r } diff --git a/lib/hero/heromodels/calendar.v b/lib/hero/heromodels/calendar.v index 283aaca6..c6911d82 100644 --- a/lib/hero/heromodels/calendar.v +++ b/lib/hero/heromodels/calendar.v @@ -3,8 +3,9 @@ module heromodels import freeflowuniverse.herolib.data.encoder import freeflowuniverse.herolib.data.ourtime import freeflowuniverse.herolib.hero.db -import freeflowuniverse.herolib.schemas.jsonrpc { Response, new_error, new_response, new_response_false, new_response_ok, new_response_true, new_response_int } +import freeflowuniverse.herolib.schemas.jsonrpc { Response, new_error, new_response, new_response_false, new_response_int, new_response_ok, new_response_true } import freeflowuniverse.herolib.hero.user { UserRef } +import freeflowuniverse.herolib.ui.console import json // Calendar represents a collection of events @@ -138,9 +139,7 @@ pub fn (mut self DBCalendar) get(id u32) !Calendar { } pub fn (mut self DBCalendar) list() ![]Calendar { - r := self.db.list[Calendar]()!.map(self.get(it)!) - println(r) - return r + return self.db.list[Calendar]()!.map(self.get(it)!) } pub fn calendar_handle(mut f ModelsFactory, rpcid int, servercontext map[string]string, userref UserRef, method string, params string) !Response { @@ -152,8 +151,8 @@ pub fn calendar_handle(mut f ModelsFactory, rpcid int, servercontext map[string] } 'set' { mut o := db.decode_generic[Calendar](params)! - o=f.calendar.set(o)! - return new_response_int(rpcid,int(o.id)) + o = f.calendar.set(o)! + return new_response_int(rpcid, int(o.id)) } 'delete' { id := db.decode_u32(params)! @@ -174,8 +173,7 @@ pub fn calendar_handle(mut f ModelsFactory, rpcid int, servercontext map[string] return new_response(req.id, json.encode(res)) } else { - println('Method not found on calendar: ${method}') - $dbg; + console.print_stderr('Method not found on calendar: ${method}') return new_error(rpcid, code: 32601 message: 'Method ${method} not found on calendar' diff --git a/lib/hero/heromodels/calendar_event.v b/lib/hero/heromodels/calendar_event.v index 420eccf6..539a4482 100644 --- a/lib/hero/heromodels/calendar_event.v +++ b/lib/hero/heromodels/calendar_event.v @@ -2,7 +2,7 @@ module heromodels import freeflowuniverse.herolib.data.encoder import freeflowuniverse.herolib.data.ourtime -import freeflowuniverse.herolib.schemas.jsonrpc { Response, new_error, new_response, new_response_false, new_response_ok, new_response_true, new_response_int } +import freeflowuniverse.herolib.schemas.jsonrpc { Response, new_error, new_response, new_response_false, new_response_int, new_response_ok, new_response_true } import freeflowuniverse.herolib.hero.user { UserRef } import json import freeflowuniverse.herolib.hero.db @@ -13,24 +13,23 @@ pub struct CalendarEvent { db.Base pub mut: title string - start_time i64 // Unix timestamp - end_time i64 // Unix timestamp - registration_desks []u32 //link to registration mechanism, is where we track invitees, are not attendee unless accepted + start_time i64 // Unix timestamp + end_time i64 // Unix timestamp + registration_desks []u32 // link to registration mechanism, is where we track invitees, are not attendee unless accepted attendees []Attendee - docs []EventDoc // link to docs - calendar_id u32 // Associated calendar + docs []EventDoc // link to docs + calendar_id u32 // Associated calendar status EventStatus is_all_day bool - reminder_mins []int // Minutes before event for reminders - color string // Hex color code + reminder_mins []int // Minutes before event for reminders + color string // Hex color code timezone string priority EventPriority public bool - locations []EventLocation - is_template bool //not to be shown as real event, serves as placeholder e.g. for planning + locations []EventLocation + is_template bool // not to be shown as real event, serves as placeholder e.g. for planning } - pub struct Attendee { pub mut: user_id u32 @@ -39,7 +38,7 @@ pub mut: admin bool // if set can manage the main elements of the event = description, can accept invitee... organizer bool // if set means others can ask for support, doesn't mean is admin log []AttendeeLog - location string //optional if user wants to select a location + location string // optional if user wants to select a location } pub enum EventPriority { @@ -76,14 +75,12 @@ pub mut: public bool // everyone can see the file, otherwise only the organizers, attendees } - - pub struct EventLocation { pub mut: - name string + name string description string - cat EventLocationCat - docs []EventDoc + cat EventLocationCat + docs []EventDoc } pub enum EventLocationCat { @@ -326,16 +323,16 @@ pub mut: 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 - attendees []u32 // IDs of user groups - docs []u32 // IDs of linked files or dirs - calendar_id u32 // Associated calendar + attendees []u32 // IDs of user groups + docs []u32 // IDs of linked files or dirs + calendar_id u32 // Associated calendar status EventStatus is_all_day bool reminder_mins []int // Minutes before event for reminders color string // Hex color code timezone string priority EventPriority // Added missing priority field - is_template bool // Added missing is_template field + is_template bool // Added missing is_template field securitypolicy u32 tags []string messages []db.MessageArg @@ -356,14 +353,14 @@ pub fn (mut self DBCalendarEvent) new(args CalendarEventArg) !CalendarEvent { mut o := CalendarEvent{ title: args.title attendees: []Attendee{} - docs: fs_attachments + docs: fs_attachments calendar_id: args.calendar_id status: args.status is_all_day: args.is_all_day reminder_mins: args.reminder_mins color: args.color timezone: args.timezone - priority: args.priority // Added missing priority field + priority: args.priority // Added missing priority field is_template: args.is_template // Added missing is_template field public: false } @@ -456,7 +453,8 @@ pub fn (mut self DBCalendarEvent) list(args CalendarEventListArg) ![]CalendarEve return filtered_events } -pub fn calendar_event_handle(mut f ModelsFactory, rpcid int, servercontext map[string]string, userref UserRef, method string, params string) !jsonrpc.Response { + +pub fn calendar_event_handle(mut f ModelsFactory, rpcid int, servercontext map[string]string, userref UserRef, method string, params string) !Response { match method { 'get' { id := db.decode_u32(params)! @@ -465,8 +463,8 @@ pub fn calendar_event_handle(mut f ModelsFactory, rpcid int, servercontext map[s } 'set' { mut o := db.decode_generic[CalendarEvent](params)! - o=f.calendar_event.set(o)! - return new_response_int(rpcid,int(o.id)) + o = f.calendar_event.set(o)! + return new_response_int(rpcid, int(o.id)) } 'delete' { id := db.decode_u32(params)! @@ -495,4 +493,4 @@ pub fn calendar_event_handle(mut f ModelsFactory, rpcid int, servercontext map[s ) } } -} \ No newline at end of file +} diff --git a/lib/hero/heroserver/api_handler.v b/lib/hero/heroserver/api_handler.v index 88378e17..a39f08d6 100644 --- a/lib/hero/heroserver/api_handler.v +++ b/lib/hero/heroserver/api_handler.v @@ -102,8 +102,11 @@ pub fn (mut server HeroServer) api_handler(mut ctx Context, handler_type string) return ctx.request_error('Invalid method format, too many dots. ${ctx.req.method}') } } - console.print_debug('Handling request: ${request.method} with params: ${request.params}') - // $dbg; + + // Log the request + server.log( + message: 'Handling request: ${request.method} with params: ${request.params}' + ) // Handle the request using the OpenRPC handler response := handler.handle(request) or { return ctx.server_error('Handler error: ${err}') } diff --git a/lib/hero/heroserver/model.v b/lib/hero/heroserver/model.v index 61df90ae..6a587067 100644 --- a/lib/hero/heroserver/model.v +++ b/lib/hero/heroserver/model.v @@ -3,6 +3,7 @@ module heroserver import freeflowuniverse.herolib.crypt.herocrypt import freeflowuniverse.herolib.schemas.openrpc import freeflowuniverse.herolib.core.logger +import freeflowuniverse.herolib.ui.console import time import veb @@ -59,7 +60,7 @@ pub fn (mut server HeroServer) log(params ServerLogParams) { logtype: params.level ) or { // Fallback to console if logging fails - println('[${params.cat}] ${params.message}') + console.print_info('[${params.cat}] ${params.message}') } } diff --git a/lib/schemas/jsonrpc/model_request.v b/lib/schemas/jsonrpc/model_request.v index 49fd0a99..06a6be10 100644 --- a/lib/schemas/jsonrpc/model_request.v +++ b/lib/schemas/jsonrpc/model_request.v @@ -60,7 +60,7 @@ pub fn decode_request(data string) !Request { jsonrpc: a method: b params: c - id: d + id: d } return r4 } diff --git a/lib/ui/console/console.v b/lib/ui/console/console.v index 2593a48b..eb4a6922 100644 --- a/lib/ui/console/console.v +++ b/lib/ui/console/console.v @@ -99,5 +99,16 @@ pub fn print_green(txt string) { c.reset() } +// Print info in blue color +pub fn print_info(txt string) { + mut c := get() + if c.prev_title || c.prev_item { + lf() + } + txt2 := trim(texttools.indent(txt, ' . ')) + cprintln(foreground: .blue, text: txt2) + c.reset() +} + // import freeflowuniverse.herolib.ui.console // console.print_header()