add: postIndex
This commit is contained in:
parent
dd0716d2b8
commit
d83169e9cf
5 changed files with 46 additions and 32 deletions
8
Post/go.mod
Normal file
8
Post/go.mod
Normal file
|
@ -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
|
||||||
|
)
|
4
Post/go.sum
Normal file
4
Post/go.sum
Normal file
|
@ -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=
|
|
@ -1,49 +1,50 @@
|
||||||
package Posts
|
package Post
|
||||||
|
|
||||||
import (
|
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/native/std"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/interop/storage"
|
"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 {
|
type Post struct {
|
||||||
threadId string
|
postName string
|
||||||
id string
|
|
||||||
header string
|
header string
|
||||||
text string
|
text string
|
||||||
authorId string
|
authorId string
|
||||||
hashTags []string
|
|
||||||
category string
|
category string
|
||||||
likes int
|
likes int
|
||||||
dislikes int
|
dislikes int
|
||||||
|
id string
|
||||||
}
|
}
|
||||||
|
|
||||||
const storeURLKey = "storeURL"
|
const (
|
||||||
|
lastIndex = "_lastIndex"
|
||||||
|
)
|
||||||
|
|
||||||
func _deploy(data interface{}, isUpdate bool) {
|
/*
|
||||||
if isUpdate {
|
func _deploy(data interface{}, isUpdate bool, userId string) {
|
||||||
return
|
if isUpdate {
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
ctx := storage.GetContext()
|
func NewPost(authorId string, text string, postName string) {
|
||||||
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()
|
ctx := storage.GetContext()
|
||||||
|
|
||||||
post := Post{
|
post := Post{
|
||||||
text: text,
|
text: text,
|
||||||
hashTags: hashTags,
|
|
||||||
authorId: authorId,
|
authorId: authorId,
|
||||||
dislikes: 0,
|
dislikes: 0,
|
||||||
likes: 0,
|
likes: 0,
|
||||||
category: "none",
|
category: "none",
|
||||||
threadId: threadId,
|
postName: postName,
|
||||||
id: guuid.New(),
|
id: xid.New().String(),
|
||||||
}
|
}
|
||||||
storage.Put(ctx, post.id, std.Serialize(post))
|
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 {
|
func GetPost(postId string) Post {
|
||||||
|
|
||||||
|
@ -58,6 +59,7 @@ func GetPost(postId string) Post {
|
||||||
}
|
}
|
||||||
|
|
||||||
func RatePost(isLike bool, postId string) {
|
func RatePost(isLike bool, postId string) {
|
||||||
|
ctx := storage.GetContext()
|
||||||
post := GetPost(postId)
|
post := GetPost(postId)
|
||||||
if isLike {
|
if isLike {
|
||||||
post.likes++
|
post.likes++
|
||||||
|
@ -66,3 +68,16 @@ func RatePost(isLike bool, postId string) {
|
||||||
}
|
}
|
||||||
storage.Put(ctx, post.id, std.Serialize(post))
|
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)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
1
go.mod
1
go.mod
|
@ -4,6 +4,5 @@ go 1.21.5
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/google/uuid v1.5.0
|
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
|
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231219060339-de98b39a9502
|
||||||
)
|
)
|
||||||
|
|
12
go.sum
12
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 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU=
|
||||||
github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
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 h1:HwR9fWkdJXCbsTnrb2Rm92xkDGdEM0VHvZV+7XJUXM0=
|
||||||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231219060339-de98b39a9502/go.mod h1:J/Mk6+nKeKSW4wygkZQFLQ6SkLOSGX5Ga0RuuuktEag=
|
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=
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue