205 lines
4.8 KiB
Go
205 lines
4.8 KiB
Go
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
|
|
AccountNameUpdatedAt int64
|
|
LastAccountName string // Contains the last account name to allow the user to change the account name back to the old name
|
|
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
|
|
}
|