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 (
|
const (
|
||||||
comment_prefix = "comment_"
|
comment_prefix = "comment_"
|
||||||
post_prefix = "post_"
|
|
||||||
user_comment_count_prefix = "comment_count_"
|
user_comment_count_prefix = "comment_count_"
|
||||||
)
|
)
|
||||||
|
|
||||||
func _deploy(data interface{}, isUpdate bool) {
|
func _deploy(data interface{}, isUpdate bool) {
|
||||||
ctx := storage.GetContext()
|
ctx := storage.GetContext()
|
||||||
storage.Put(ctx, "index_comment", 0)
|
storage.Put(ctx, "index_comment", "0")
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateNewComment(userLogin string, postId string, text string) {
|
func CreateNewComment(userLogin string, postId string, text string) {
|
||||||
ctx := storage.GetContext()
|
ctx := storage.GetContext()
|
||||||
|
|
||||||
id := storage.Get(ctx, "index_comment").(int)
|
id := std.Atoi10(storage.Get(ctx, "index_comment").(string))
|
||||||
id++
|
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 {
|
if storage.Get(ctx, user_comment_count_prefix+userLogin) == nil {
|
||||||
storage.Put(ctx, user_comment_count_prefix+userLogin, 0)
|
storage.Put(ctx, user_comment_count_prefix+userLogin, 0)
|
||||||
|
@ -47,16 +46,16 @@ func CreateNewComment(userLogin string, postId string, text string) {
|
||||||
likes: 0,
|
likes: 0,
|
||||||
dislikes: 0,
|
dislikes: 0,
|
||||||
}
|
}
|
||||||
|
var comments = make([]Comment, 0)
|
||||||
comments := GetByPostId(postId)
|
comments = GetByPostId(postId)
|
||||||
comments = append(comments, newComment)
|
comments = append(comments, newComment)
|
||||||
storage.Put(ctx, comment_prefix+postId, std.Serialize(comments)) // добавление комментов в общий список комментов поста
|
storage.Put(ctx, comment_prefix+postId, std.Serialize(comments)) // { "comment_post_{i} : comments.json"}
|
||||||
storage.Put(ctx, commentId, std.Serialize(newComment)) // добавление коммента отдельно по ключу
|
storage.Put(ctx, commentId, std.Serialize(newComment)) // { "comment_{i}" : comment.json}
|
||||||
|
|
||||||
commentCount := storage.Get(ctx, user_comment_count_prefix+userLogin).(int)
|
commentCount := storage.Get(ctx, user_comment_count_prefix+userLogin).(int)
|
||||||
commentCount++
|
commentCount++
|
||||||
storage.Put(ctx, user_comment_count_prefix+userLogin, commentCount) // обновление счетчика коммента юзера
|
storage.Put(ctx, user_comment_count_prefix+userLogin, commentCount) // { "comment_count_{login}" : {i} }
|
||||||
storage.Put(ctx, userLogin+"_c_"+std.Itoa10(commentCount), commentId) // хранение айдишника коммента по юзеру
|
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))
|
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 {
|
func GetByLogin(login string) []Comment {
|
||||||
var comments []Comment
|
var comments []Comment = make([]Comment, 0)
|
||||||
ctx := storage.GetContext()
|
ctx := storage.GetContext()
|
||||||
it := storage.Find(ctx, login+"_c_", storage.ValuesOnly|storage.DeserializeValues)
|
it := storage.Find(ctx, login+"_c_", storage.ValuesOnly|storage.DeserializeValues)
|
||||||
for iterator.Next(it) {
|
for iterator.Next(it) {
|
||||||
|
@ -96,7 +95,11 @@ func GetByLogin(login string) []Comment {
|
||||||
|
|
||||||
func GetComment(commentId string) Comment {
|
func GetComment(commentId string) Comment {
|
||||||
ctx := storage.GetContext()
|
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 {
|
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) {
|
func RateComment(isLike bool, postId string, commentId string) {
|
||||||
|
|
Loading…
Reference in a new issue