fix comment

This commit is contained in:
RustamOper05 2024-01-16 17:30:21 +03:00
parent d1d6b51c80
commit e334c3fb9d
2 changed files with 10 additions and 2 deletions

View file

@ -3,6 +3,7 @@ package Comment
import (
"github.com/nspcc-dev/neo-go/pkg/interop/iterator"
"github.com/nspcc-dev/neo-go/pkg/interop/native/std"
"github.com/nspcc-dev/neo-go/pkg/interop/runtime"
"github.com/nspcc-dev/neo-go/pkg/interop/storage"
)
@ -56,10 +57,16 @@ func CreateNewComment(userLogin string, postId string, text string) {
commentCount++
storage.Put(ctx, user_comment_count_prefix+userLogin, commentCount) // обновление счетчика коммента юзера
storage.Put(ctx, userLogin+"_c_"+std.Itoa10(commentCount), commentId) // хранение айдишника коммента по юзеру
runtime.Log("Comment created: " + commentId + " ----- " + user_comment_count_prefix + userLogin + " ------ " + userLogin + "_c_" + std.Itoa10(commentCount))
}
func GetByPostId(postId string) []Comment {
ctx := storage.GetContext()
comments := storage.Get(ctx, comment_prefix+postId)
if comments == nil {
storage.Put(ctx, comment_prefix+postId, std.Serialize(make([]Comment, 0)))
}
return std.Deserialize(storage.Get(ctx, comment_prefix+postId).([]byte)).([]Comment)
}

View file

@ -17,8 +17,9 @@ type Post struct {
}
const (
lastIndex = "user_post_index"
id = "current_post_id"
lastIndex = "user_post_index"
id = "current_post_id"
comment_prefix = "comment_"
)
func NewPost(login string, text string, postName string) {