changed db structs to gocnjhelper dbstructs
parent
27dddbe443
commit
3b59f215c8
|
@ -1,100 +0,0 @@
|
||||||
package scylladb
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/scylladb/gocqlx/v2/table"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
Users = table.New(table.Metadata{
|
|
||||||
Name: "users",
|
|
||||||
Columns: []string{
|
|
||||||
"id",
|
|
||||||
"username",
|
|
||||||
"account_name",
|
|
||||||
"account_name_lc",
|
|
||||||
"email",
|
|
||||||
"password",
|
|
||||||
"description",
|
|
||||||
"latitude",
|
|
||||||
"longitude",
|
|
||||||
"xp_level",
|
|
||||||
"xp_points",
|
|
||||||
"followers_count",
|
|
||||||
"following_count",
|
|
||||||
"account_status",
|
|
||||||
"avatar_url",
|
|
||||||
"public_keys",
|
|
||||||
"created_at",
|
|
||||||
"updated_at"},
|
|
||||||
PartKey: []string{"id"},
|
|
||||||
})
|
|
||||||
|
|
||||||
WebSocketSessions = table.New(table.Metadata{
|
|
||||||
Name: "ws_sessions",
|
|
||||||
Columns: []string{
|
|
||||||
"id",
|
|
||||||
"user_id",
|
|
||||||
"user_agent",
|
|
||||||
"ip",
|
|
||||||
"last_used",
|
|
||||||
"created_at"},
|
|
||||||
PartKey: []string{"id"},
|
|
||||||
})
|
|
||||||
|
|
||||||
UserSignUpProcess = table.New(table.Metadata{
|
|
||||||
Name: "user_sign_up_process",
|
|
||||||
Columns: []string{
|
|
||||||
"x_token",
|
|
||||||
"email",
|
|
||||||
"user_agent",
|
|
||||||
"ip",
|
|
||||||
"email_verify_code",
|
|
||||||
"email_verified",
|
|
||||||
"last_email_resend",
|
|
||||||
"created_at",
|
|
||||||
"expires_at",
|
|
||||||
},
|
|
||||||
PartKey: []string{"x_token"},
|
|
||||||
})
|
|
||||||
|
|
||||||
Chats = table.New(table.Metadata{
|
|
||||||
Name: "chats",
|
|
||||||
Columns: []string{
|
|
||||||
"user_first_id",
|
|
||||||
"user_second_id",
|
|
||||||
"sync_count",
|
|
||||||
"last_messages",
|
|
||||||
"blocked_state",
|
|
||||||
"created_at",
|
|
||||||
},
|
|
||||||
PartKey: []string{"user_first_id", "user_second_id"},
|
|
||||||
})
|
|
||||||
|
|
||||||
UserRelationship = table.New(table.Metadata{
|
|
||||||
Name: "user_relationship",
|
|
||||||
Columns: []string{
|
|
||||||
"user_first_id",
|
|
||||||
"user_second_id",
|
|
||||||
"user_first_following_state",
|
|
||||||
"user_second_following_state",
|
|
||||||
"blocked_state",
|
|
||||||
"created_at",
|
|
||||||
"updated_at",
|
|
||||||
},
|
|
||||||
PartKey: []string{"user_first_id", "user_second_id"},
|
|
||||||
})
|
|
||||||
|
|
||||||
UserPrivacySettings = table.New(table.Metadata{
|
|
||||||
Name: "user_privacy_settings",
|
|
||||||
Columns: []string{
|
|
||||||
"user_id",
|
|
||||||
"username",
|
|
||||||
"avatar",
|
|
||||||
"description",
|
|
||||||
"location",
|
|
||||||
"created_at",
|
|
||||||
"updated_at",
|
|
||||||
},
|
|
||||||
PartKey: []string{"user_id"},
|
|
||||||
})
|
|
||||||
)
|
|
|
@ -1,18 +1,8 @@
|
||||||
package structs
|
package structs
|
||||||
|
|
||||||
// TABLE chats
|
import "git.clickandjoin.umbach.dev/ClickandJoin/go-cnj-helper/dbstructs"
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
// swagger:model ChatsResponse
|
// swagger:model ChatsResponse
|
||||||
type ChatsResponse struct {
|
type ChatsResponse struct {
|
||||||
Chats []Chat
|
Chats []dbstructs.Chat
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,111 +1,23 @@
|
||||||
package structs
|
package structs
|
||||||
|
|
||||||
import (
|
import "git.clickandjoin.umbach.dev/ClickandJoin/go-cnj-helper/dbstructs"
|
||||||
"reflect"
|
|
||||||
|
|
||||||
"github.com/gocql/gocql"
|
|
||||||
"github.com/scylladb/gocqlx/v2"
|
|
||||||
)
|
|
||||||
|
|
||||||
type User struct {
|
|
||||||
Id string
|
|
||||||
Username string
|
|
||||||
AccountName string
|
|
||||||
AccountNameLc string
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
// swagger:model UserResponse
|
|
||||||
/*
|
|
||||||
type UserResponse struct {
|
|
||||||
Username string
|
|
||||||
AccountName string
|
|
||||||
Email string
|
|
||||||
Description string
|
|
||||||
AccountStatus uint8
|
|
||||||
AvatarUrl string
|
|
||||||
} */
|
|
||||||
|
|
||||||
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())
|
|
||||||
}
|
|
||||||
|
|
||||||
// swagger:model UsersResponse
|
// swagger:model UsersResponse
|
||||||
type UsersResponse struct {
|
type UsersResponse struct {
|
||||||
Users []User
|
Users []dbstructs.User
|
||||||
}
|
|
||||||
|
|
||||||
type UserSignUpProcess struct {
|
|
||||||
XToken string
|
|
||||||
Email string
|
|
||||||
UserAgent string
|
|
||||||
Ip string
|
|
||||||
EmailVerifyCode string
|
|
||||||
EmailVerified bool
|
|
||||||
LastEmailResend int64
|
|
||||||
CreatedAt int64
|
|
||||||
ExpiresAt int64
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// swagger:model UserSignUpProcessesResponse
|
// swagger:model UserSignUpProcessesResponse
|
||||||
type UserSignUpProcessesResponse struct {
|
type UserSignUpProcessesResponse struct {
|
||||||
UserSignUpProcesses []UserSignUpProcess
|
UserSignUpProcesses []dbstructs.UserSignUpProcess
|
||||||
}
|
|
||||||
|
|
||||||
type UserRelationship struct {
|
|
||||||
UserFirstId string
|
|
||||||
UserSecondId string
|
|
||||||
UserFirstFollowingState uint8
|
|
||||||
UserSecondFollowingState uint8
|
|
||||||
BlockedState uint8
|
|
||||||
CreatedAt int64
|
|
||||||
UpdatedAt int64
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// swagger:model UserRelationshipsResponse
|
// swagger:model UserRelationshipsResponse
|
||||||
type UserRelationshipsResponse struct {
|
type UserRelationshipsResponse struct {
|
||||||
Relationships []UserRelationship
|
Relationships []dbstructs.UserRelationship
|
||||||
}
|
|
||||||
|
|
||||||
// TABLE user_privacy_settings
|
|
||||||
type UserPrivacySettings struct {
|
|
||||||
UserId string
|
|
||||||
Username uint8
|
|
||||||
Avatar uint8
|
|
||||||
Description uint8
|
|
||||||
Location uint8
|
|
||||||
CreatedAt int64
|
|
||||||
UpdatedAt int64
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// swagger:model UserPrivacySettingsResponse
|
// swagger:model UserPrivacySettingsResponse
|
||||||
type UserPrivacySettingsResponse struct {
|
type UserPrivacySettingsResponse struct {
|
||||||
PrivacySettings []UserPrivacySettings
|
PrivacySettings []dbstructs.UserPrivacySettings
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +1,8 @@
|
||||||
package structs
|
package structs
|
||||||
|
|
||||||
// TABLE ws_sessions
|
import "git.clickandjoin.umbach.dev/ClickandJoin/go-cnj-helper/dbstructs"
|
||||||
type UserWebSocketSession struct {
|
|
||||||
Id string
|
|
||||||
UserId string
|
|
||||||
UserAgent string
|
|
||||||
Ip string
|
|
||||||
LastUsed int64
|
|
||||||
CreatedAt int64
|
|
||||||
}
|
|
||||||
|
|
||||||
// swagger:model UserWebSocketSessionsResponse
|
// swagger:model UserWebSocketSessionsResponse
|
||||||
type WebSocketSessionsResponse struct {
|
type WebSocketSessionsResponse struct {
|
||||||
WsSessions []UserWebSocketSession
|
WsSessions []dbstructs.UserWebSocketSession
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"clickandjoin.app/managementsystem/modules/scylladb"
|
"clickandjoin.app/managementsystem/modules/scylladb"
|
||||||
"clickandjoin.app/managementsystem/modules/structs"
|
"clickandjoin.app/managementsystem/modules/structs"
|
||||||
gocnjhelper "git.clickandjoin.umbach.dev/ClickandJoin/go-cnj-helper"
|
gocnjhelper "git.clickandjoin.umbach.dev/ClickandJoin/go-cnj-helper"
|
||||||
|
"git.clickandjoin.umbach.dev/ClickandJoin/go-cnj-helper/dbstructs"
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -22,9 +23,9 @@ func GetAllChats(c *fiber.Ctx) error {
|
||||||
// '500':
|
// '500':
|
||||||
// description: Internal server error
|
// description: Internal server error
|
||||||
|
|
||||||
var chats []structs.Chat
|
var chats []dbstructs.Chat
|
||||||
|
|
||||||
q := scylladb.Session.Query(scylladb.Chats.SelectAll())
|
q := scylladb.Session.Query(gocnjhelper.DbMChats.SelectAll())
|
||||||
|
|
||||||
if err := q.SelectRelease(&chats); err != nil {
|
if err := q.SelectRelease(&chats); err != nil {
|
||||||
gocnjhelper.LogErrorf("Failed to get chats, err: %s", err)
|
gocnjhelper.LogErrorf("Failed to get chats, err: %s", err)
|
||||||
|
|
|
@ -25,27 +25,27 @@ func GetStats(c *fiber.Ctx) error {
|
||||||
|
|
||||||
var stats structs.StatsResponse
|
var stats structs.StatsResponse
|
||||||
|
|
||||||
if count, err := getCount(scylladb.Users.Name()); err == nil {
|
if count, err := getCount(gocnjhelper.DbMUsers.Name()); err == nil {
|
||||||
stats.Users = count
|
stats.Users = count
|
||||||
}
|
}
|
||||||
|
|
||||||
if count, err := getCount(scylladb.Chats.Name()); err == nil {
|
if count, err := getCount(gocnjhelper.DbMChats.Name()); err == nil {
|
||||||
stats.Chats = count
|
stats.Chats = count
|
||||||
}
|
}
|
||||||
|
|
||||||
if count, err := getCount(scylladb.WebSocketSessions.Name()); err == nil {
|
if count, err := getCount(gocnjhelper.DbMWebSocketSessions.Name()); err == nil {
|
||||||
stats.WebSocketSessions = count
|
stats.WebSocketSessions = count
|
||||||
}
|
}
|
||||||
|
|
||||||
if count, err := getCount(scylladb.UserSignUpProcess.Name()); err == nil {
|
if count, err := getCount(gocnjhelper.DbMUserSignUpProcess.Name()); err == nil {
|
||||||
stats.UserSignUpProcesses = count
|
stats.UserSignUpProcesses = count
|
||||||
}
|
}
|
||||||
|
|
||||||
if count, err := getCount(scylladb.UserPrivacySettings.Name()); err == nil {
|
if count, err := getCount(gocnjhelper.DbMUserPrivacySettings.Name()); err == nil {
|
||||||
stats.UserPrivacySettings = count
|
stats.UserPrivacySettings = count
|
||||||
}
|
}
|
||||||
|
|
||||||
if count, err := getCount(scylladb.UserRelationship.Name()); err == nil {
|
if count, err := getCount(gocnjhelper.DbMUserRelationship.Name()); err == nil {
|
||||||
stats.UserRelationships = count
|
stats.UserRelationships = count
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"clickandjoin.app/managementsystem/modules/scylladb"
|
"clickandjoin.app/managementsystem/modules/scylladb"
|
||||||
"clickandjoin.app/managementsystem/modules/structs"
|
"clickandjoin.app/managementsystem/modules/structs"
|
||||||
gocnjhelper "git.clickandjoin.umbach.dev/ClickandJoin/go-cnj-helper"
|
gocnjhelper "git.clickandjoin.umbach.dev/ClickandJoin/go-cnj-helper"
|
||||||
|
"git.clickandjoin.umbach.dev/ClickandJoin/go-cnj-helper/dbstructs"
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -22,15 +23,15 @@ func GetAllUsers(c *fiber.Ctx) error {
|
||||||
// '500':
|
// '500':
|
||||||
// description: Internal server error
|
// description: Internal server error
|
||||||
|
|
||||||
var users []structs.User
|
var users []dbstructs.User
|
||||||
|
|
||||||
q := scylladb.Session.Query(scylladb.Users.SelectAll())
|
q := scylladb.Session.Query(gocnjhelper.DbMUsers.SelectAll())
|
||||||
|
|
||||||
if err := q.SelectRelease(&users); err != nil {
|
if err := q.SelectRelease(&users); err != nil {
|
||||||
gocnjhelper.LogErrorf("Failed to get all users, err: %s", err)
|
gocnjhelper.LogErrorf("Failed to get all users, err: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var nUsers []structs.User
|
var nUsers []dbstructs.User
|
||||||
|
|
||||||
if len(users) > 0 { // remove password value from result
|
if len(users) > 0 { // remove password value from result
|
||||||
for _, user := range users {
|
for _, user := range users {
|
||||||
|
@ -97,9 +98,9 @@ func GetAllUserSignUpProcesses(c *fiber.Ctx) error {
|
||||||
// '500':
|
// '500':
|
||||||
// description: Internal server error
|
// description: Internal server error
|
||||||
|
|
||||||
var userSignUpProcesses []structs.UserSignUpProcess
|
var userSignUpProcesses []dbstructs.UserSignUpProcess
|
||||||
|
|
||||||
q := scylladb.Session.Query(scylladb.UserSignUpProcess.SelectAll())
|
q := scylladb.Session.Query(gocnjhelper.DbMUserSignUpProcess.SelectAll())
|
||||||
|
|
||||||
if err := q.SelectRelease(&userSignUpProcesses); err != nil {
|
if err := q.SelectRelease(&userSignUpProcesses); err != nil {
|
||||||
gocnjhelper.LogErrorf("Failed to get all user sign up processes, err: %s", err)
|
gocnjhelper.LogErrorf("Failed to get all user sign up processes, err: %s", err)
|
||||||
|
@ -123,9 +124,9 @@ func GetAllUserRelationships(c *fiber.Ctx) error {
|
||||||
// '500':
|
// '500':
|
||||||
// description: Internal server error
|
// description: Internal server error
|
||||||
|
|
||||||
var userRelationships []structs.UserRelationship
|
var userRelationships []dbstructs.UserRelationship
|
||||||
|
|
||||||
q := scylladb.Session.Query(scylladb.UserRelationship.SelectAll())
|
q := scylladb.Session.Query(gocnjhelper.DbMUserRelationship.SelectAll())
|
||||||
|
|
||||||
if err := q.SelectRelease(&userRelationships); err != nil {
|
if err := q.SelectRelease(&userRelationships); err != nil {
|
||||||
gocnjhelper.LogErrorf("Failed to get all user relationships, err: %s", err)
|
gocnjhelper.LogErrorf("Failed to get all user relationships, err: %s", err)
|
||||||
|
@ -149,9 +150,9 @@ func GetAllUserPrivacySettings(c *fiber.Ctx) error {
|
||||||
// '500':
|
// '500':
|
||||||
// description: Internal server error
|
// description: Internal server error
|
||||||
|
|
||||||
var userPrivacySettings []structs.UserPrivacySettings
|
var userPrivacySettings []dbstructs.UserPrivacySettings
|
||||||
|
|
||||||
q := scylladb.Session.Query(scylladb.UserPrivacySettings.SelectAll())
|
q := scylladb.Session.Query(gocnjhelper.DbMUserPrivacySettings.SelectAll())
|
||||||
|
|
||||||
if err := q.SelectRelease(&userPrivacySettings); err != nil {
|
if err := q.SelectRelease(&userPrivacySettings); err != nil {
|
||||||
gocnjhelper.LogErrorf("Failed to get all user privacy settings, err: %s", err)
|
gocnjhelper.LogErrorf("Failed to get all user privacy settings, err: %s", err)
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"clickandjoin.app/managementsystem/modules/scylladb"
|
"clickandjoin.app/managementsystem/modules/scylladb"
|
||||||
"clickandjoin.app/managementsystem/modules/structs"
|
"clickandjoin.app/managementsystem/modules/structs"
|
||||||
gocnjhelper "git.clickandjoin.umbach.dev/ClickandJoin/go-cnj-helper"
|
gocnjhelper "git.clickandjoin.umbach.dev/ClickandJoin/go-cnj-helper"
|
||||||
|
"git.clickandjoin.umbach.dev/ClickandJoin/go-cnj-helper/dbstructs"
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -23,9 +24,9 @@ func GetAllWsSessions(c *fiber.Ctx) error {
|
||||||
// '500':
|
// '500':
|
||||||
// description: Internal server error
|
// description: Internal server error
|
||||||
|
|
||||||
var wsSessions []structs.UserWebSocketSession
|
var wsSessions []dbstructs.UserWebSocketSession
|
||||||
|
|
||||||
q := scylladb.Session.Query(scylladb.WebSocketSessions.SelectAll())
|
q := scylladb.Session.Query(gocnjhelper.DbMWebSocketSessions.SelectAll())
|
||||||
|
|
||||||
if err := q.SelectRelease(&wsSessions); err != nil {
|
if err := q.SelectRelease(&wsSessions); err != nil {
|
||||||
gocnjhelper.LogErrorf("Failed to get ws sessions, err: %s", err)
|
gocnjhelper.LogErrorf("Failed to get ws sessions, err: %s", err)
|
||||||
|
|
Loading…
Reference in New Issue