Merge pull request 'add user entity' () from user_contract into master

Reviewed-on: https://codeberg.org/NaMe2te/Blog/pulls/1
This commit is contained in:
RustamOper05 2023-12-23 11:27:19 +00:00
commit c51d1311b4
5 changed files with 87 additions and 8 deletions

58
User/user.go Normal file
View file

@ -0,0 +1,58 @@
package Users
import (
"github.com/nspcc-dev/neo-go/pkg/interop"
"github.com/nspcc-dev/neo-go/pkg/interop/native/std"
"github.com/nspcc-dev/neo-go/pkg/interop/storage"
)
type User struct {
name string
surname string
login string
password string
ownerHash interop.Hash160
likes int
}
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")
}
user := User{
name: name,
surname: surname,
login: login,
password: password,
ownerHash: owner,
likes: 0,
}
saveUser(ctx, login, user)
}
func GetUser(ctx storage.Context, login string) User {
data := storage.Get(ctx, login)
if data == nil {
panic("User does not exist")
}
return std.Deserialize(data.([]byte)).(User)
}
func saveUser(ctx storage.Context, userLogin string, user User) {
storage.Put(ctx, userLogin, std.Serialize(user))
}
//TODO ну тит типа будет там ну типа число пистов типа да типо число комментов и типо тд типо
// func CountUserStatistic(User user) map[string]string {
// return userStats
// }
//TODO ну я хз как пойдет но мб надо написать сохранение поста через юзера, если варик с кринж конкатом строк не залетит
//func AddPostToUsersPostList(string postHash){}

4
User/user.yml Normal file
View file

@ -0,0 +1,4 @@
name: user
safemethods: []
supportedstandards: []
events: []

View file

@ -1,8 +0,0 @@
package Users
type User struct {
name string
surname string
login string
password string
}

9
go.mod Normal file
View file

@ -0,0 +1,9 @@
module blog
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
)

16
go.sum Normal file
View file

@ -0,0 +1,16 @@
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=