Merge pull request 'cringe_branch' (#9) from cringe_branch into master
Reviewed-on: https://codeberg.org/NaMe2te/Blog/pulls/9
This commit is contained in:
commit
792708dd07
3 changed files with 27 additions and 10 deletions
|
@ -96,7 +96,7 @@ func GetByLogin(login string) []Comment {
|
|||
|
||||
func GetComment(commentId string) Comment {
|
||||
ctx := storage.GetContext()
|
||||
return storage.Get(ctx, commentId).(Comment)
|
||||
return std.Deserialize(storage.Get(ctx, commentId).([]byte)).(Comment)
|
||||
}
|
||||
|
||||
func GetCommentInPost(commentId string, postId string) Comment {
|
||||
|
|
|
@ -3,12 +3,12 @@ package Post
|
|||
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"
|
||||
)
|
||||
|
||||
type Post struct {
|
||||
postName string
|
||||
header string
|
||||
text string
|
||||
login string
|
||||
likes int
|
||||
|
@ -40,8 +40,9 @@ func NewPost(login string, text string, postName string) {
|
|||
storage.Put(ctx, post.id, std.Serialize(post))
|
||||
|
||||
updatePostIndex(login)
|
||||
lastPostIndex := storage.Get(ctx, login+lastIndex).(string)
|
||||
storage.Put(ctx, login+"_p_"+lastPostIndex, post.id)
|
||||
lastPostIndex := storage.Get(ctx, login+lastIndex).(int)
|
||||
storage.Put(ctx, login+"_p_"+std.Itoa10(lastPostIndex), post.id)
|
||||
runtime.Log("Post created. Post id: " + post.id + "; User post id" + login + "_p_" + std.Itoa10(lastPostIndex))
|
||||
}
|
||||
|
||||
func GetAllPosts() []Post {
|
||||
|
@ -50,8 +51,10 @@ func GetAllPosts() []Post {
|
|||
it := storage.Find(ctx, "post", storage.ValuesOnly|storage.DeserializeValues)
|
||||
for iterator.Next(it) {
|
||||
post := iterator.Value(it).(Post)
|
||||
runtime.Log(string(std.Serialize(post)))
|
||||
posts = append(posts, post)
|
||||
}
|
||||
|
||||
return posts
|
||||
}
|
||||
|
||||
|
@ -68,11 +71,22 @@ func GetPost(postId string) Post {
|
|||
|
||||
func GetAllPostsByUser(login string) []Post {
|
||||
ctx := storage.GetReadOnlyContext()
|
||||
var postsByUser []Post
|
||||
i := 0
|
||||
var postsByUser []Post = make([]Post, 0)
|
||||
i := 1
|
||||
n := getPostIndex(login)
|
||||
for i < n {
|
||||
post := storage.Get(ctx, login+"_p_"+std.Itoa10(i))
|
||||
for i < n+1 {
|
||||
post_key := storage.Get(ctx, login+"_p_"+std.Itoa10(i))
|
||||
if post_key == nil {
|
||||
panic("post key not found")
|
||||
}
|
||||
|
||||
post_key = post_key.(string)
|
||||
|
||||
post := storage.Get(ctx, post_key)
|
||||
if post == nil {
|
||||
panic("post not found")
|
||||
}
|
||||
|
||||
i++
|
||||
postsByUser = append(postsByUser, std.Deserialize(post.([]byte)).(Post))
|
||||
}
|
||||
|
|
|
@ -21,7 +21,6 @@ const (
|
|||
|
||||
func NewUser(name string, surname string, login string, password string, owner interop.Hash160) {
|
||||
ctx := storage.GetContext()
|
||||
|
||||
existing_login := storage.Get(ctx, login)
|
||||
if existing_login != nil {
|
||||
panic("this login is taken by someone else")
|
||||
|
@ -38,7 +37,11 @@ func NewUser(name string, surname string, login string, password string, owner i
|
|||
saveUser(ctx, login, user)
|
||||
}
|
||||
|
||||
func GetUser(ctx storage.Context, login string) User {
|
||||
func GetUser(login string) User {
|
||||
return getUserTst(storage.GetReadOnlyContext(), login)
|
||||
}
|
||||
|
||||
func getUserTst(ctx storage.Context, login string) User {
|
||||
data := storage.Get(ctx, login)
|
||||
|
||||
if data == nil {
|
||||
|
|
Loading…
Add table
Reference in a new issue