From d83169e9cf124791f69464b9719b43d4d99a0cad Mon Sep 17 00:00:00 2001 From: maksaid Date: Tue, 2 Jan 2024 19:31:11 +0300 Subject: [PATCH 1/3] add: postIndex --- Post/go.mod | 8 +++++++ Post/go.sum | 4 ++++ Post/post_contract.go | 53 +++++++++++++++++++++++++++---------------- go.mod | 1 - go.sum | 12 ---------- 5 files changed, 46 insertions(+), 32 deletions(-) create mode 100644 Post/go.mod create mode 100644 Post/go.sum 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= From 9f162e5363d8e3d773e848899c3c5db1d8595805 Mon Sep 17 00:00:00 2001 From: RustamOper05 Date: Wed, 3 Jan 2024 01:33:48 +0300 Subject: [PATCH 2/3] fix imports --- Post/go.mod | 8 -------- Post/go.sum | 4 ---- go.mod | 2 +- go.sum | 4 ++-- 4 files changed, 3 insertions(+), 15 deletions(-) delete mode 100644 Post/go.mod delete mode 100644 Post/go.sum diff --git a/Post/go.mod b/Post/go.mod deleted file mode 100644 index f32afc6..0000000 --- a/Post/go.mod +++ /dev/null @@ -1,8 +0,0 @@ -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 deleted file mode 100644 index d0cf754..0000000 --- a/Post/go.sum +++ /dev/null @@ -1,4 +0,0 @@ -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/go.mod b/go.mod index 805463f..097051b 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,6 @@ module blog go 1.21.5 require ( - github.com/google/uuid v1.5.0 github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231219060339-de98b39a9502 + github.com/rs/xid v1.5.0 ) diff --git a/go.sum b/go.sum index a48451d..750842c 100644 --- a/go.sum +++ b/go.sum @@ -1,4 +1,4 @@ -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/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/rs/xid v1.5.0 h1:mKX4bl4iPYJtEIxp6CYiUuLQ/8DYMoz0PUdtGgMFRVc= +github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= From 21d14fef3c8fc7a1eb2efa825a3f8f187495670f Mon Sep 17 00:00:00 2001 From: maksaid Date: Mon, 8 Jan 2024 15:56:25 +0300 Subject: [PATCH 3/3] fix: id-s --- Post/post_contract.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Post/post_contract.go b/Post/post_contract.go index 21752c7..5c60bcc 100644 --- a/Post/post_contract.go +++ b/Post/post_contract.go @@ -3,9 +3,9 @@ package Post import ( "strconv" + guuid "github.com/google/uuid" "github.com/nspcc-dev/neo-go/pkg/interop/native/std" "github.com/nspcc-dev/neo-go/pkg/interop/storage" - "github.com/rs/xid" ) type Post struct { @@ -40,7 +40,7 @@ func NewPost(authorId string, text string, postName string) { likes: 0, category: "none", postName: postName, - id: xid.New().String(), + id: guuid.New().String(), } storage.Put(ctx, post.id, std.Serialize(post)) updatePostIndex(authorId)