added db structs

alpha v1.0.38
alex 2023-02-17 20:51:31 +01:00
parent c5e4a93b51
commit 3b388b644e
4 changed files with 232 additions and 0 deletions

View File

@ -65,6 +65,14 @@ var (
PartKey: []string{"id"},
})
DbMSessionsHelper = table.New(table.Metadata{
Name: "sessions",
Columns: []string{
"id",
"user_id"},
PartKey: []string{"id"},
})
DbMWebSocketSessions = table.New(table.Metadata{
Name: "ws_sessions",
Columns: []string{

202
dbstructs/dbstructs.go Normal file
View File

@ -0,0 +1,202 @@
package dbstructs
import (
"reflect"
"github.com/gocql/gocql"
"github.com/scylladb/gocqlx/v2"
)
// Representation of the user model
// TABLE users
type User struct {
Id string
Username string
AccountName string
AccountNameLc string // Account name as lowercase format to search for it in the database, because the account name may only exist once, regardless of the spelling of the individual letters
Email string
Password string
Description string
Latitude float64
Longitude float64
XpLevel int
XpPoints int
FollowersCount int
FollowingCount int
AccountStatus uint8
AvatarUrl string
PublicKeys []UserPublicKeys
CreatedAt int64
UpdatedAt int64
}
type UserPublicKeys struct {
gocqlx.UDT
Id string
PublicKey string
}
// needed to store into database
func (u UserPublicKeys) MarshalUDT(name string, info gocql.TypeInfo) ([]byte, error) {
f := gocqlx.DefaultMapper.FieldByName(reflect.ValueOf(u), name)
return gocql.Marshal(info, f.Interface())
}
// needed to take from database
func (u *UserPublicKeys) UnmarshalUDT(name string, info gocql.TypeInfo, data []byte) error {
f := gocqlx.DefaultMapper.FieldByName(reflect.ValueOf(u), name)
return gocql.Unmarshal(info, data, f.Addr().Interface())
}
// TABLE user_sign_up_process
type UserSignUpProcess struct {
XToken string
Email string
UserAgent string
Ip string
EmailVerifyCode string
EmailVerified bool
LastEmailResend int64
CreatedAt int64
ExpiresAt int64
}
// TABLE chats
type Chat struct {
UserFirstId string
UserSecondId string
// Represents the current number of message activities in a chat. This includes reactions to messages, replying to messages, deleting messages, and more
SyncCount int
// Contains number X of last message activities. Needed e.g. for web
LastMessages []string
BlockedState uint8
CreatedAt int64
}
// Representation of the event model
// Used for get requests
// TABLE EVENTS
type Event struct {
Id string
UserId string
AnalyticsID string
Type uint8
AccessionType uint8
Name string
Tags []string
Description string
Latitude float64
Longitude float64
AuthenticationType uint8
Voting EventVoting
InvitedParticipants []string
Participants []string
ParticipantsCount int
MaxParticipants int
StartOfEvent int64
EndOfEvent int64
CreatedAt int64
UpdatedAt int64
}
type EventVoting struct {
gocqlx.UDT
Credible int
NotCredible int
Unknown int
}
// TABLE EVENT_FAQS
type EventFaq struct {
Id string
EventId string
UserId string
Question string
CreatedAt int64
UpdatedAt int64
}
// TABLE EVENT_FAQ_ANWERS
type EventFaqAnswer struct {
Id string
FaqId string
UserId string
Answer string
Votes int
CreatedAt int64
UpdatedAt int64
}
// TABLE sessions
type UserSession struct {
Id string
UserId string
FcmToken string
EncryptionKey string
UserAgent string
AppVersion string
Ip string
LastUsed int64
CreatedAt int64
}
// TABLE ws_sessions
type UserWebSocketSession struct {
Id string
UserId string
UserAgent string
Ip string
LastUsed int64
CreatedAt int64
}
// TABLE user_mails
/*type UserMail struct {
Id string
UserId string
Status uint8
CreatedAt int64
ExpiresAt int64
} */
// TABLE user_privacy_settings
type UserPrivacySettings struct {
UserId string
Username uint8
Avatar uint8
Description uint8
Location uint8
CreatedAt int64
UpdatedAt int64
}
/*
Represents relationship between two user
TABLE user_relationship
column: UserFirstFollowingState
not_following
requested_following = set to following when user accept follow request
following
column: UserSecondFollowingState
not_following
requested_following = set to following when user accept follow request
following
column: BlockedState
not_blocked
blocked_first_second = set UserFirstFollowingState to not_following
blocked_second_first = set UserSecondFollowingState to not_following
blocked_both = set both to not_following
*/
type UserRelationship struct {
UserFirstId string
UserSecondId string
UserFirstFollowingState uint8
UserSecondFollowingState uint8
BlockedState uint8
CreatedAt int64
UpdatedAt int64
}

6
go.mod
View File

@ -8,7 +8,13 @@ require (
)
require (
github.com/gocql/gocql v0.0.0-20211015133455-b225f9b53fa1 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/scylladb/go-reflectx v1.0.1 // indirect
github.com/scylladb/gocqlx/v2 v2.8.0 // indirect
golang.org/x/sys v0.5.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
)

16
go.sum
View File

@ -1,6 +1,15 @@
github.com/bitly/go-hostpool v0.0.0-20171023180738-a3a6125de932/go.mod h1:NOuUCSz6Q9T7+igc/hlvDOUdtWKryOrtFyIVABv/p7k=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4=
github.com/coreos/go-systemd/v22 v22.3.3-0.20220203105225-a9a7ef127534/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gocql/gocql v0.0.0-20211015133455-b225f9b53fa1 h1:px9qUCy/RNJNsfCam4m2IxWGxNuimkrioEF0vrrbPsg=
github.com/gocql/gocql v0.0.0-20211015133455-b225f9b53fa1/go.mod h1:3gM2c4D3AnkISwBxGnMMsS8Oy4y2lhbPRsH4xnJrHG8=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed h1:5upAirOpQc1Q53c0bnx2ufif5kANL7bfZWcc6VJWJd8=
github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed/go.mod h1:tMWxXQ9wFIaZeTI9F+hmhFiGpFmhOHzyShyFUhRm0H4=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
@ -18,7 +27,12 @@ github.com/rabbitmq/amqp091-go v1.5.0/go.mod h1:JsV0ofX5f1nwOGafb8L5rBItt9GyhfQf
github.com/rs/xid v1.4.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/rs/zerolog v1.29.0 h1:Zes4hju04hjbvkVkOhdl2HpZa+0PmVwigmo8XoORE5w=
github.com/rs/zerolog v1.29.0/go.mod h1:NILgTygv/Uej1ra5XxGf82ZFSLk58MFGAUS2o6usyD0=
github.com/scylladb/go-reflectx v1.0.1 h1:b917wZM7189pZdlND9PbIJ6NQxfDPfBvUaQ7cjj1iZQ=
github.com/scylladb/go-reflectx v1.0.1/go.mod h1:rWnOfDIRWBGN0miMLIcoPt/Dhi2doCMZqwMCJ3KupFc=
github.com/scylladb/gocqlx/v2 v2.8.0 h1:f/oIgoEPjKDKd+RIoeHqexsIQVIbalVmT+axwvUqQUg=
github.com/scylladb/gocqlx/v2 v2.8.0/go.mod h1:4/+cga34PVqjhgSoo5Nr2fX1MQIqZB5eCE5DK4xeDig=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
go.uber.org/goleak v1.1.12 h1:gZAh5/EyT/HQwlpkCy6wTpqfH9H8Lz8zbm3dZh+OyzA=
@ -55,4 +69,6 @@ golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8T
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc=
gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=