From a3df37d7c2bb6d7f88040e4766eed6a56aa85698 Mon Sep 17 00:00:00 2001 From: NaMe2te Date: Fri, 5 Jan 2024 18:07:07 +0300 Subject: [PATCH] fix: added update comment method --- comment/comment.go | 14 ++++---------- comment/comment.json | 2 +- comment/comment.nef | Bin 134 -> 526 bytes 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/comment/comment.go b/comment/comment.go index a5c996c..81ecbf5 100644 --- a/comment/comment.go +++ b/comment/comment.go @@ -1,9 +1,9 @@ package comment import ( + guuid "github.com/google/uuid" "github.com/nspcc-dev/neo-go/pkg/interop/native/std" "github.com/nspcc-dev/neo-go/pkg/interop/storage" - "github.com/rs/xid" ) type Comment struct { @@ -18,7 +18,7 @@ type Comment struct { func CreateNewComment(authorId string, postId string, text string) { ctx := storage.GetContext() newComment := Comment{ - id: xid.New().String(), + id: guuid.New().String(), authorId: authorId, postId: postId, text: text, @@ -29,7 +29,6 @@ func CreateNewComment(authorId string, postId string, text string) { comments := GetByPostId(postId) comments = append(comments, newComment) storage.Put(ctx, postId+"_comment", std.Serialize(comments)) - storage.Put(ctx, newComment.id, std.Serialize(newComment)) } func GetByPostId(postId string) []Comment { @@ -57,12 +56,7 @@ func GetComment(commentId string, postId string) Comment { } } - panic("Коммента с таким айдишником нету v poste nety") -} - -func GetComment(commentId string) Comment { - ctx := storage.GetContext() - return std.Deserialize(storage.Get(ctx, commentId).([]byte)).(Comment) + panic("Коммента с таким айдишником нету") } func RateComment(isLike bool, postId string, commentId string) { @@ -86,4 +80,4 @@ func UpdateComment(comment Comment, postId string) { } storage.Put(ctx, postId+"_comment", std.Serialize(comments)) -} +} \ No newline at end of file diff --git a/comment/comment.json b/comment/comment.json index 76f4d83..e876375 100755 --- a/comment/comment.json +++ b/comment/comment.json @@ -1 +1 @@ -{"name":"comment","abi":{"methods":[{"name":"_initialize","offset":0,"parameters":[],"returntype":"Void","safe":false},{"name":"runtimeNotify","offset":21,"parameters":[{"name":"args","type":"Array"}],"returntype":"Void","safe":false}],"events":[{"name":"Hello world!","parameters":[{"name":"args","type":"Array"}]}]},"features":{},"groups":[],"permissions":[{"contract":"*","methods":"*"}],"supportedstandards":[],"trusts":[],"extra":null} \ No newline at end of file +{"name":"comment","abi":{"methods":[{"name":"createNewComment","offset":0,"parameters":[{"name":"authorId","type":"String"},{"name":"postId","type":"String"},{"name":"text","type":"String"}],"returntype":"Void","safe":false},{"name":"getByAuthorId","offset":109,"parameters":[{"name":"postId","type":"String"},{"name":"authorId","type":"String"}],"returntype":"Array","safe":false},{"name":"getByPostId","offset":61,"parameters":[{"name":"postId","type":"String"}],"returntype":"Array","safe":false},{"name":"getComment","offset":157,"parameters":[{"name":"commentId","type":"String"},{"name":"postId","type":"String"}],"returntype":"Array","safe":false},{"name":"rateComment","offset":259,"parameters":[{"name":"isLike","type":"Boolean"},{"name":"postId","type":"String"},{"name":"commentId","type":"String"}],"returntype":"Void","safe":false}],"events":[{"name":"Hello world!","parameters":[{"name":"args","type":"Array"}]}]},"features":{},"groups":[],"permissions":[{"contract":"*","methods":"*"}],"supportedstandards":[],"trusts":[],"extra":null} \ No newline at end of file diff --git a/comment/comment.nef b/comment/comment.nef index 22d6ebdba40089f382826cb61da02cb138c7c7a2..62776e66ec27a3c54275b8cd8f24d1966c87decc 100755 GIT binary patch literal 526 zcmeZsbu-RO&DTxO*EP^HG%(RK)Ga7V)ip8GO;1U+v`8|xOk^MggfmJ?3as??Q!5g4 z3vyERlJj%*8JG^dw>;iAGVD*9|om*F#>J=Zmt;85oK)DtS2K zfwt$S=9P432RlBqmuPVaXJUkC&Zt0=4RD+k`@+!crhy8}ZG*y0b4CWQn+`y>gF`qo zQ-#Ty0`9^LuTuiv-bOM)zTW4GvINgnPFLg2gxZ*OzHpAx6IWN)OrZHpl_qlvpsK|{ zstYp(&Q(lTV+YI6QF;ZWd2BAsy0GuU9w6L$VeiGJ3mX(JHY$MV3%f4txUfe7$k=&d z%Y_{mJ1*=63hV+YRsb@$UTnJ9Y~>Kn%3M_$U^1nkLX9IsE<@lP&>