diff --git a/modules/scylladb/models.go b/modules/scylladb/models.go deleted file mode 100644 index e399d1a..0000000 --- a/modules/scylladb/models.go +++ /dev/null @@ -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"}, - }) -) diff --git a/modules/structs/chat.go b/modules/structs/chat.go index 6a2e7a9..c9db63c 100644 --- a/modules/structs/chat.go +++ b/modules/structs/chat.go @@ -1,18 +1,8 @@ package structs -// 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 -} +import "git.clickandjoin.umbach.dev/ClickandJoin/go-cnj-helper/dbstructs" // swagger:model ChatsResponse type ChatsResponse struct { - Chats []Chat + Chats []dbstructs.Chat } diff --git a/modules/structs/user.go b/modules/structs/user.go index 437e3bb..a26e98d 100644 --- a/modules/structs/user.go +++ b/modules/structs/user.go @@ -1,111 +1,23 @@ package structs -import ( - "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()) -} +import "git.clickandjoin.umbach.dev/ClickandJoin/go-cnj-helper/dbstructs" // swagger:model UsersResponse type UsersResponse struct { - Users []User -} - -type UserSignUpProcess struct { - XToken string - Email string - UserAgent string - Ip string - EmailVerifyCode string - EmailVerified bool - LastEmailResend int64 - CreatedAt int64 - ExpiresAt int64 + Users []dbstructs.User } // swagger:model UserSignUpProcessesResponse type UserSignUpProcessesResponse struct { - UserSignUpProcesses []UserSignUpProcess -} - -type UserRelationship struct { - UserFirstId string - UserSecondId string - UserFirstFollowingState uint8 - UserSecondFollowingState uint8 - BlockedState uint8 - CreatedAt int64 - UpdatedAt int64 + UserSignUpProcesses []dbstructs.UserSignUpProcess } // swagger:model UserRelationshipsResponse type UserRelationshipsResponse struct { - Relationships []UserRelationship -} - -// TABLE user_privacy_settings -type UserPrivacySettings struct { - UserId string - Username uint8 - Avatar uint8 - Description uint8 - Location uint8 - CreatedAt int64 - UpdatedAt int64 + Relationships []dbstructs.UserRelationship } // swagger:model UserPrivacySettingsResponse type UserPrivacySettingsResponse struct { - PrivacySettings []UserPrivacySettings + PrivacySettings []dbstructs.UserPrivacySettings } diff --git a/modules/structs/wssessions.go b/modules/structs/wssessions.go index 9b21de0..4be24b0 100644 --- a/modules/structs/wssessions.go +++ b/modules/structs/wssessions.go @@ -1,16 +1,8 @@ package structs -// TABLE ws_sessions -type UserWebSocketSession struct { - Id string - UserId string - UserAgent string - Ip string - LastUsed int64 - CreatedAt int64 -} +import "git.clickandjoin.umbach.dev/ClickandJoin/go-cnj-helper/dbstructs" // swagger:model UserWebSocketSessionsResponse type WebSocketSessionsResponse struct { - WsSessions []UserWebSocketSession + WsSessions []dbstructs.UserWebSocketSession } diff --git a/routers/api/v1/chats/chats.go b/routers/api/v1/chats/chats.go index 16c7515..02b234f 100644 --- a/routers/api/v1/chats/chats.go +++ b/routers/api/v1/chats/chats.go @@ -4,6 +4,7 @@ import ( "clickandjoin.app/managementsystem/modules/scylladb" "clickandjoin.app/managementsystem/modules/structs" gocnjhelper "git.clickandjoin.umbach.dev/ClickandJoin/go-cnj-helper" + "git.clickandjoin.umbach.dev/ClickandJoin/go-cnj-helper/dbstructs" "github.com/gofiber/fiber/v2" ) @@ -22,9 +23,9 @@ func GetAllChats(c *fiber.Ctx) error { // '500': // 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 { gocnjhelper.LogErrorf("Failed to get chats, err: %s", err) diff --git a/routers/api/v1/stats/stats.go b/routers/api/v1/stats/stats.go index a0620f0..8af27d0 100644 --- a/routers/api/v1/stats/stats.go +++ b/routers/api/v1/stats/stats.go @@ -25,27 +25,27 @@ func GetStats(c *fiber.Ctx) error { 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 } - if count, err := getCount(scylladb.Chats.Name()); err == nil { + if count, err := getCount(gocnjhelper.DbMChats.Name()); err == nil { stats.Chats = count } - if count, err := getCount(scylladb.WebSocketSessions.Name()); err == nil { + if count, err := getCount(gocnjhelper.DbMWebSocketSessions.Name()); err == nil { stats.WebSocketSessions = count } - if count, err := getCount(scylladb.UserSignUpProcess.Name()); err == nil { + if count, err := getCount(gocnjhelper.DbMUserSignUpProcess.Name()); err == nil { stats.UserSignUpProcesses = count } - if count, err := getCount(scylladb.UserPrivacySettings.Name()); err == nil { + if count, err := getCount(gocnjhelper.DbMUserPrivacySettings.Name()); err == nil { stats.UserPrivacySettings = count } - if count, err := getCount(scylladb.UserRelationship.Name()); err == nil { + if count, err := getCount(gocnjhelper.DbMUserRelationship.Name()); err == nil { stats.UserRelationships = count } diff --git a/routers/api/v1/users/users.go b/routers/api/v1/users/users.go index bb73a37..928c086 100644 --- a/routers/api/v1/users/users.go +++ b/routers/api/v1/users/users.go @@ -4,6 +4,7 @@ import ( "clickandjoin.app/managementsystem/modules/scylladb" "clickandjoin.app/managementsystem/modules/structs" gocnjhelper "git.clickandjoin.umbach.dev/ClickandJoin/go-cnj-helper" + "git.clickandjoin.umbach.dev/ClickandJoin/go-cnj-helper/dbstructs" "github.com/gofiber/fiber/v2" ) @@ -22,15 +23,15 @@ func GetAllUsers(c *fiber.Ctx) error { // '500': // 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 { 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 for _, user := range users { @@ -97,9 +98,9 @@ func GetAllUserSignUpProcesses(c *fiber.Ctx) error { // '500': // 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 { gocnjhelper.LogErrorf("Failed to get all user sign up processes, err: %s", err) @@ -123,9 +124,9 @@ func GetAllUserRelationships(c *fiber.Ctx) error { // '500': // 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 { gocnjhelper.LogErrorf("Failed to get all user relationships, err: %s", err) @@ -149,9 +150,9 @@ func GetAllUserPrivacySettings(c *fiber.Ctx) error { // '500': // 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 { gocnjhelper.LogErrorf("Failed to get all user privacy settings, err: %s", err) diff --git a/routers/api/v1/wssessions/wssessions.go b/routers/api/v1/wssessions/wssessions.go index a58899f..1f23a25 100644 --- a/routers/api/v1/wssessions/wssessions.go +++ b/routers/api/v1/wssessions/wssessions.go @@ -4,6 +4,7 @@ import ( "clickandjoin.app/managementsystem/modules/scylladb" "clickandjoin.app/managementsystem/modules/structs" gocnjhelper "git.clickandjoin.umbach.dev/ClickandJoin/go-cnj-helper" + "git.clickandjoin.umbach.dev/ClickandJoin/go-cnj-helper/dbstructs" "github.com/gofiber/fiber/v2" ) @@ -23,9 +24,9 @@ func GetAllWsSessions(c *fiber.Ctx) error { // '500': // 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 { gocnjhelper.LogErrorf("Failed to get ws sessions, err: %s", err)