diff --git a/Post/go.mod b/Post/go.mod new file mode 100644 index 0000000..f32afc6 --- /dev/null +++ b/Post/go.mod @@ -0,0 +1,8 @@ +module Post + +go 1.21.5 + +require ( + github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231229133344-d90169761595 + github.com/rs/xid v1.5.0 +) diff --git a/Post/go.sum b/Post/go.sum new file mode 100644 index 0000000..d0cf754 --- /dev/null +++ b/Post/go.sum @@ -0,0 +1,4 @@ +github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231229133344-d90169761595 h1:vWtkeZPpwlHV55W/PSTbRP8aH37UrbdTAOyB5J1xgDM= +github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231229133344-d90169761595/go.mod h1:J/Mk6+nKeKSW4wygkZQFLQ6SkLOSGX5Ga0RuuuktEag= +github.com/rs/xid v1.5.0 h1:mKX4bl4iPYJtEIxp6CYiUuLQ/8DYMoz0PUdtGgMFRVc= +github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= diff --git a/Post/post_contract.go b/Post/post_contract.go index 4491172..21752c7 100644 --- a/Post/post_contract.go +++ b/Post/post_contract.go @@ -1,49 +1,50 @@ -package Posts +package Post import ( - guuid "github.com/google/uuid" + "strconv" + "github.com/nspcc-dev/neo-go/pkg/interop/native/std" "github.com/nspcc-dev/neo-go/pkg/interop/storage" - //"github.com/nspcc-dev/neo-go/pkg/interop/runtime" + "github.com/rs/xid" ) type Post struct { - threadId string - id string + postName string header string text string authorId string - hashTags []string category string likes int dislikes int + id string } -const storeURLKey = "storeURL" +const ( + lastIndex = "_lastIndex" +) -func _deploy(data interface{}, isUpdate bool) { - if isUpdate { - return +/* + func _deploy(data interface{}, isUpdate bool, userId string) { + 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) { +*/ +func NewPost(authorId string, text string, postName string) { ctx := storage.GetContext() post := Post{ text: text, - hashTags: hashTags, authorId: authorId, dislikes: 0, likes: 0, category: "none", - threadId: threadId, - id: guuid.New(), + postName: postName, + id: xid.New().String(), } storage.Put(ctx, post.id, std.Serialize(post)) + updatePostIndex(authorId) + storage.Put(ctx, authorId+strconv.Itoa(getPostIndex(authorId)), post.id) } func GetPost(postId string) Post { @@ -58,6 +59,7 @@ func GetPost(postId string) Post { } func RatePost(isLike bool, postId string) { + ctx := storage.GetContext() post := GetPost(postId) if isLike { post.likes++ @@ -66,3 +68,16 @@ func RatePost(isLike bool, postId string) { } storage.Put(ctx, post.id, std.Serialize(post)) } + +func getPostIndex(userId string) int { + ctx := storage.GetContext() + index := storage.Get(ctx, userId+lastIndex) + return index.(int) +} + +func updatePostIndex(userId string) { + ctx := storage.GetContext() + index := getPostIndex(userId) + storage.Put(ctx, userId+lastIndex, index+1) + +} diff --git a/go.mod b/go.mod index 2fe0250..805463f 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,5 @@ go 1.21.5 require ( github.com/google/uuid v1.5.0 - github.com/nspcc-dev/neo-go v0.104.0 github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231219060339-de98b39a9502 ) diff --git a/go.sum b/go.sum index b2a997e..a48451d 100644 --- a/go.sum +++ b/go.sum @@ -1,16 +1,4 @@ -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU= github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/nspcc-dev/neo-go v0.104.0 h1:FGj3Z46yABcFIAI1SCLd1jQSoh+B00h/2VAgEgY1JKQ= -github.com/nspcc-dev/neo-go v0.104.0/go.mod h1:omsUK5PAtG2/nQ3/evs95QEg3wtkj3LH53e0NKtXVwQ= github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231219060339-de98b39a9502 h1:HwR9fWkdJXCbsTnrb2Rm92xkDGdEM0VHvZV+7XJUXM0= github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231219060339-de98b39a9502/go.mod h1:J/Mk6+nKeKSW4wygkZQFLQ6SkLOSGX5Ga0RuuuktEag= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc= -golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=