|
|
|
|
@@ -1,130 +1,130 @@
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
// @[heap]
|
|
|
|
|
// pub struct Comment {
|
|
|
|
|
// db.Base
|
|
|
|
|
// pub mut:
|
|
|
|
|
// // id u32
|
|
|
|
|
// comment string
|
|
|
|
|
// parent u32 // id of parent comment if any, 0 means none
|
|
|
|
|
// author u32 // links to user
|
|
|
|
|
// }
|
|
|
|
|
@[heap]
|
|
|
|
|
pub struct Comment {
|
|
|
|
|
db.Base
|
|
|
|
|
pub mut:
|
|
|
|
|
// id u32
|
|
|
|
|
comment string
|
|
|
|
|
parent u32 // id of parent comment if any, 0 means none
|
|
|
|
|
author u32 // links to user
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// //////////TO BE GENERATED BY AI////////////////////////////////
|
|
|
|
|
// ///BASIC CRUD FUNCTIONS
|
|
|
|
|
//////////TO BE GENERATED BY AI////////////////////////////////
|
|
|
|
|
///BASIC CRUD FUNCTIONS
|
|
|
|
|
|
|
|
|
|
// pub struct DBComments {
|
|
|
|
|
// pub mut:
|
|
|
|
|
// db &db.DB @[skip; str: skip]
|
|
|
|
|
// }
|
|
|
|
|
pub struct DBComments {
|
|
|
|
|
pub mut:
|
|
|
|
|
db &db.DB @[skip; str: skip]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// pub fn (self Comment) type_name() string {
|
|
|
|
|
// return 'comments'
|
|
|
|
|
// }
|
|
|
|
|
pub fn (self Comment) type_name() string {
|
|
|
|
|
return 'comments'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// // return example rpc call and result for each methodname
|
|
|
|
|
// pub fn (self Comment) description(methodname string) string {
|
|
|
|
|
// match methodname {
|
|
|
|
|
// 'set' {
|
|
|
|
|
// return 'Create or update a comment. Returns the ID of the comment.'
|
|
|
|
|
// }
|
|
|
|
|
// 'get' {
|
|
|
|
|
// return 'Retrieve a comment by ID. Returns the comment object.'
|
|
|
|
|
// }
|
|
|
|
|
// 'delete' {
|
|
|
|
|
// return 'Delete a comment by ID. Returns true if successful.'
|
|
|
|
|
// }
|
|
|
|
|
// 'exist' {
|
|
|
|
|
// return 'Check if a comment exists by ID. Returns true or false.'
|
|
|
|
|
// }
|
|
|
|
|
// 'list' {
|
|
|
|
|
// return 'List all comments. Returns an array of comment 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 Comment) description(methodname string) string {
|
|
|
|
|
match methodname {
|
|
|
|
|
'set' {
|
|
|
|
|
return 'Create or update a comment. Returns the ID of the comment.'
|
|
|
|
|
}
|
|
|
|
|
'get' {
|
|
|
|
|
return 'Retrieve a comment by ID. Returns the comment object.'
|
|
|
|
|
}
|
|
|
|
|
'delete' {
|
|
|
|
|
return 'Delete a comment by ID. Returns true if successful.'
|
|
|
|
|
}
|
|
|
|
|
'exist' {
|
|
|
|
|
return 'Check if a comment exists by ID. Returns true or false.'
|
|
|
|
|
}
|
|
|
|
|
'list' {
|
|
|
|
|
return 'List all comments. Returns an array of comment 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 Comment) example(methodname string) (string, string) {
|
|
|
|
|
// match methodname {
|
|
|
|
|
// 'set' {
|
|
|
|
|
// return '{"comment": {"comment": "This is a test comment.", "parent": 0, "author": 1}}', '1'
|
|
|
|
|
// }
|
|
|
|
|
// 'get' {
|
|
|
|
|
// return '{"id": 1}', '{"comment": "This is a test comment.", "parent": 0, "author": 1}'
|
|
|
|
|
// }
|
|
|
|
|
// 'delete' {
|
|
|
|
|
// return '{"id": 1}', 'true'
|
|
|
|
|
// }
|
|
|
|
|
// 'exist' {
|
|
|
|
|
// return '{"id": 1}', 'true'
|
|
|
|
|
// }
|
|
|
|
|
// 'list' {
|
|
|
|
|
// return '{}', '[{"comment": "This is a test comment.", "parent": 0, "author": 1}]'
|
|
|
|
|
// }
|
|
|
|
|
// else {
|
|
|
|
|
// return '{}', '{}'
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// return example rpc call and result for each methodname
|
|
|
|
|
pub fn (self Comment) example(methodname string) (string, string) {
|
|
|
|
|
match methodname {
|
|
|
|
|
'set' {
|
|
|
|
|
return '{"comment": {"comment": "This is a test comment.", "parent": 0, "author": 1}}', '1'
|
|
|
|
|
}
|
|
|
|
|
'get' {
|
|
|
|
|
return '{"id": 1}', '{"comment": "This is a test comment.", "parent": 0, "author": 1}'
|
|
|
|
|
}
|
|
|
|
|
'delete' {
|
|
|
|
|
return '{"id": 1}', 'true'
|
|
|
|
|
}
|
|
|
|
|
'exist' {
|
|
|
|
|
return '{"id": 1}', 'true'
|
|
|
|
|
}
|
|
|
|
|
'list' {
|
|
|
|
|
return '{}', '[{"comment": "This is a test comment.", "parent": 0, "author": 1}]'
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return '{}', '{}'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// pub fn (self Comment) dump(mut e encoder.Encoder) ! {
|
|
|
|
|
// // e.add_string(self.comment)
|
|
|
|
|
// // e.add_u32(self.parent)
|
|
|
|
|
// // e.add_u32(self.author)
|
|
|
|
|
// }
|
|
|
|
|
pub fn (self Comment) dump(mut e encoder.Encoder) ! {
|
|
|
|
|
e.add_string(self.comment)
|
|
|
|
|
e.add_u32(self.parent)
|
|
|
|
|
e.add_u32(self.author)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// fn (mut self DBComments) load(mut o Comment, mut e encoder.Decoder) ! {
|
|
|
|
|
// // o.comment = e.get_string()!
|
|
|
|
|
// // o.parent = e.get_u32()!
|
|
|
|
|
// // o.author = e.get_u32()!
|
|
|
|
|
// }
|
|
|
|
|
fn (mut self DBComments) load(mut o Comment, mut e encoder.Decoder) ! {
|
|
|
|
|
o.comment = e.get_string()!
|
|
|
|
|
o.parent = e.get_u32()!
|
|
|
|
|
o.author = e.get_u32()!
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// @[params]
|
|
|
|
|
// pub struct CommentArg {
|
|
|
|
|
// pub mut:
|
|
|
|
|
// comment string @[required]
|
|
|
|
|
// parent u32
|
|
|
|
|
// author u32
|
|
|
|
|
// }
|
|
|
|
|
@[params]
|
|
|
|
|
pub struct CommentArg {
|
|
|
|
|
pub mut:
|
|
|
|
|
comment string @[required]
|
|
|
|
|
parent u32
|
|
|
|
|
author u32
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// // get new comment, not from the DB
|
|
|
|
|
// pub fn (mut self DBComments) new(args CommentArg) !Comment {
|
|
|
|
|
// mut o := Comment{
|
|
|
|
|
// comment: args.comment
|
|
|
|
|
// parent: args.parent
|
|
|
|
|
// updated_at: ourtime.now().unix()
|
|
|
|
|
// author: args.author
|
|
|
|
|
// }
|
|
|
|
|
// return o
|
|
|
|
|
// }
|
|
|
|
|
// get new comment, not from the DB
|
|
|
|
|
pub fn (mut self DBComments) new(args CommentArg) !Comment {
|
|
|
|
|
mut o := Comment{
|
|
|
|
|
comment: args.comment
|
|
|
|
|
parent: args.parent
|
|
|
|
|
updated_at: ourtime.now().unix()
|
|
|
|
|
author: args.author
|
|
|
|
|
}
|
|
|
|
|
return o
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// pub fn (mut self DBComments) set(mut o Comment) ! {
|
|
|
|
|
// // Use openrpcserver set function which now returns the ID
|
|
|
|
|
// self.db.set[Comment](mut o)!
|
|
|
|
|
// }
|
|
|
|
|
pub fn (mut self DBComments) set(mut o Comment) ! {
|
|
|
|
|
// Use openrpcserver set function which now returns the ID
|
|
|
|
|
self.db.set[Comment](mut o)!
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// pub fn (mut self DBComments) delete(id u32) ! {
|
|
|
|
|
// self.db.delete[Comment](id)!
|
|
|
|
|
// }
|
|
|
|
|
pub fn (mut self DBComments) delete(id u32) ! {
|
|
|
|
|
self.db.delete[Comment](id)!
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// pub fn (mut self DBComments) exist(id u32) !bool {
|
|
|
|
|
// return self.db.exists[Comment](id)!
|
|
|
|
|
// }
|
|
|
|
|
pub fn (mut self DBComments) exist(id u32) !bool {
|
|
|
|
|
return self.db.exists[Comment](id)!
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// pub fn (mut self DBComments) get(id u32) !Comment {
|
|
|
|
|
// mut o, data := self.db.get_data[Comment](id)!
|
|
|
|
|
// mut e_decoder := encoder.decoder_new(data)
|
|
|
|
|
// self.load(mut o, mut e_decoder)!
|
|
|
|
|
// return o
|
|
|
|
|
// }
|
|
|
|
|
pub fn (mut self DBComments) get(id u32) !Comment {
|
|
|
|
|
mut o, data := self.db.get_data[Comment](id)!
|
|
|
|
|
mut e_decoder := encoder.decoder_new(data)
|
|
|
|
|
self.load(mut o, mut e_decoder)!
|
|
|
|
|
return o
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// pub fn (mut self DBComments) list() ![]Comment {
|
|
|
|
|
// return self.db.list[Comment]()!.map(self.get(it)!)
|
|
|
|
|
// }
|
|
|
|
|
pub fn (mut self DBComments) list() ![]Comment {
|
|
|
|
|
return self.db.list[Comment]()!.map(self.get(it)!)
|
|
|
|
|
}
|
|
|
|
|
|