68 lines
1.3 KiB
Go
68 lines
1.3 KiB
Go
|
package Posts
|
||
|
|
||
|
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"
|
||
|
)
|
||
|
|
||
|
type Post struct {
|
||
|
threadId string
|
||
|
id string
|
||
|
header string
|
||
|
text string
|
||
|
authorId string
|
||
|
hashTags []string
|
||
|
category string
|
||
|
likes int
|
||
|
dislikes int
|
||
|
}
|
||
|
|
||
|
const storeURLKey = "storeURL"
|
||
|
|
||
|
func _deploy(data interface{}, isUpdate bool) {
|
||
|
if isUpdate {
|
||
|
return
|
||
|
}
|
||
|
|
||
|
ctx := storage.GetContext()
|
||
|
storeURL := "https://codeberg.org/NaMe2te/Blog/src/branch/master/Posts/posts_storage.json"
|
||
|
storage.Put(ctx, storeURLKey, storeURL)
|
||
|
}
|
||
|
func NewPost(authorId string, text string, hashTags []string, threadId string) {
|
||
|
ctx := storage.GetContext()
|
||
|
|
||
|
post := Post{
|
||
|
text: text,
|
||
|
hashTags: hashTags,
|
||
|
authorId: authorId,
|
||
|
dislikes: 0,
|
||
|
Likes: 0,
|
||
|
category: "none",
|
||
|
threadId: threadId,
|
||
|
id: guuid.New(),
|
||
|
}
|
||
|
storage.Put(ctx, post.id, std.Serialize(post))
|
||
|
}
|
||
|
func GetPost(postId string) Post {
|
||
|
|
||
|
ctx := storage.GetReadOnlyContext()
|
||
|
data := storage.Get(ctx, postId)
|
||
|
if data == nil {
|
||
|
panic("player not found")
|
||
|
}
|
||
|
|
||
|
return std.Deserialize(data.([]byte)).(Post)
|
||
|
|
||
|
}
|
||
|
|
||
|
func RatePost(isLike bool, postId string) {
|
||
|
post := GetPost(postId)
|
||
|
if isLike {
|
||
|
post.likes++
|
||
|
} else {
|
||
|
post.dislikes++
|
||
|
}
|
||
|
storage.Put(ctx, post.id, std.Serialize(post))
|
||
|
}
|