Compare commits
1 commit
master
...
testicula_
Author | SHA1 | Date | |
---|---|---|---|
44abe9f823 |
1 changed files with 16 additions and 13 deletions
|
@ -18,21 +18,20 @@ type Comment struct {
|
|||
|
||||
const (
|
||||
comment_prefix = "comment_"
|
||||
post_prefix = "post_"
|
||||
user_comment_count_prefix = "comment_count_"
|
||||
)
|
||||
|
||||
func _deploy(data interface{}, isUpdate bool) {
|
||||
ctx := storage.GetContext()
|
||||
storage.Put(ctx, "index_comment", 0)
|
||||
storage.Put(ctx, "index_comment", "0")
|
||||
}
|
||||
|
||||
func CreateNewComment(userLogin string, postId string, text string) {
|
||||
ctx := storage.GetContext()
|
||||
|
||||
id := storage.Get(ctx, "index_comment").(int)
|
||||
id := std.Atoi10(storage.Get(ctx, "index_comment").(string))
|
||||
id++
|
||||
storage.Put(ctx, "index_comment", id)
|
||||
storage.Put(ctx, "index_comment", std.Itoa10(id))
|
||||
|
||||
if storage.Get(ctx, user_comment_count_prefix+userLogin) == nil {
|
||||
storage.Put(ctx, user_comment_count_prefix+userLogin, 0)
|
||||
|
@ -47,16 +46,16 @@ func CreateNewComment(userLogin string, postId string, text string) {
|
|||
likes: 0,
|
||||
dislikes: 0,
|
||||
}
|
||||
|
||||
comments := GetByPostId(postId)
|
||||
var comments = make([]Comment, 0)
|
||||
comments = GetByPostId(postId)
|
||||
comments = append(comments, newComment)
|
||||
storage.Put(ctx, comment_prefix+postId, std.Serialize(comments)) // добавление комментов в общий список комментов поста
|
||||
storage.Put(ctx, commentId, std.Serialize(newComment)) // добавление коммента отдельно по ключу
|
||||
storage.Put(ctx, comment_prefix+postId, std.Serialize(comments)) // { "comment_post_{i} : comments.json"}
|
||||
storage.Put(ctx, commentId, std.Serialize(newComment)) // { "comment_{i}" : comment.json}
|
||||
|
||||
commentCount := storage.Get(ctx, user_comment_count_prefix+userLogin).(int)
|
||||
commentCount++
|
||||
storage.Put(ctx, user_comment_count_prefix+userLogin, commentCount) // обновление счетчика коммента юзера
|
||||
storage.Put(ctx, userLogin+"_c_"+std.Itoa10(commentCount), commentId) // хранение айдишника коммента по юзеру
|
||||
storage.Put(ctx, user_comment_count_prefix+userLogin, commentCount) // { "comment_count_{login}" : {i} }
|
||||
storage.Put(ctx, userLogin+"_c_"+std.Itoa10(commentCount), commentId) // { "{login}_c_{i} : comment_{i} }
|
||||
|
||||
runtime.Log("Comment created: " + commentId + " ----- " + user_comment_count_prefix + userLogin + " ------ " + userLogin + "_c_" + std.Itoa10(commentCount))
|
||||
}
|
||||
|
@ -83,7 +82,7 @@ func GetByLoginInPost(postId string, login string) []Comment {
|
|||
}
|
||||
|
||||
func GetByLogin(login string) []Comment {
|
||||
var comments []Comment
|
||||
var comments []Comment = make([]Comment, 0)
|
||||
ctx := storage.GetContext()
|
||||
it := storage.Find(ctx, login+"_c_", storage.ValuesOnly|storage.DeserializeValues)
|
||||
for iterator.Next(it) {
|
||||
|
@ -96,7 +95,11 @@ func GetByLogin(login string) []Comment {
|
|||
|
||||
func GetComment(commentId string) Comment {
|
||||
ctx := storage.GetContext()
|
||||
return storage.Get(ctx, commentId).(Comment)
|
||||
comment := storage.Get(ctx, commentId)
|
||||
if comment == nil {
|
||||
panic("comment not found")
|
||||
}
|
||||
return comment.(Comment)
|
||||
}
|
||||
|
||||
func GetCommentInPost(commentId string, postId string) Comment {
|
||||
|
@ -107,7 +110,7 @@ func GetCommentInPost(commentId string, postId string) Comment {
|
|||
}
|
||||
}
|
||||
|
||||
panic("Коммента с таким айдишником нету")
|
||||
panic("comment not found")
|
||||
}
|
||||
|
||||
func RateComment(isLike bool, postId string, commentId string) {
|
||||
|
|
Loading…
Reference in a new issue