fix: added update comment method

This commit is contained in:
NaMe2te 2024-01-05 18:07:07 +03:00
parent eadfefe4a5
commit a3df37d7c2
3 changed files with 5 additions and 11 deletions

View file

@ -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) {

View file

@ -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}
{"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}

Binary file not shown.