add: entities and folders, post entity poorly described
This commit is contained in:
parent
6081a8cd64
commit
b6839536b9
6 changed files with 132 additions and 0 deletions
8
Comments/comment_contract.go
Normal file
8
Comments/comment_contract.go
Normal file
|
@ -0,0 +1,8 @@
|
|||
package Comments
|
||||
|
||||
type Comments struct {
|
||||
authorId string
|
||||
text string
|
||||
likes int
|
||||
dislikes int
|
||||
}
|
5
Forums/forum_contract.go
Normal file
5
Forums/forum_contract.go
Normal file
|
@ -0,0 +1,5 @@
|
|||
package Forums
|
||||
|
||||
type Forum struct {
|
||||
threads []string
|
||||
}
|
44
Models/categories.json
Normal file
44
Models/categories.json
Normal file
|
@ -0,0 +1,44 @@
|
|||
{
|
||||
"categories": [
|
||||
{
|
||||
"id": 1,
|
||||
"category": "travel"
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"category": "technology"
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"category": "business"
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"category": "lifestyle"
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
"category": "personal development"
|
||||
},
|
||||
{
|
||||
"id": 6,
|
||||
"category": "entertainment"
|
||||
},
|
||||
{
|
||||
"id": 7,
|
||||
"category": "health and fitness"
|
||||
},
|
||||
{
|
||||
"id": 8,
|
||||
"category": "food and drink"
|
||||
},
|
||||
{
|
||||
"id": 9,
|
||||
"category": "art and culture"
|
||||
},
|
||||
{
|
||||
"id": 10,
|
||||
"category": "parenting"
|
||||
}
|
||||
]
|
||||
}
|
67
Posts/post_contract.go
Normal file
67
Posts/post_contract.go
Normal file
|
@ -0,0 +1,67 @@
|
|||
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))
|
||||
}
|
0
Posts/posts_storage.json
Normal file
0
Posts/posts_storage.json
Normal file
8
Users/user_contract.go
Normal file
8
Users/user_contract.go
Normal file
|
@ -0,0 +1,8 @@
|
|||
package Users
|
||||
|
||||
type User struct {
|
||||
name string
|
||||
surname string
|
||||
login string
|
||||
password string
|
||||
}
|
Loading…
Reference in a new issue