added chats

alpha
alex 2023-02-11 08:57:42 +01:00
parent 67e4be9fd5
commit d036a970eb
4 changed files with 70 additions and 0 deletions

View File

@ -56,4 +56,17 @@ var (
}, },
PartKey: []string{"x_token"}, 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"},
})
) )

18
modules/structs/chat.go Normal file
View File

@ -0,0 +1,18 @@
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
}
// swagger:model ChatsResponse
type ChatsResponse struct {
Chats []Chat
}

View File

@ -0,0 +1,35 @@
package chats
import (
"clickandjoin.app/managementsystem/modules/scylladb"
"clickandjoin.app/managementsystem/modules/structs"
"github.com/gofiber/fiber/v2"
"github.com/sirupsen/logrus"
)
func GetAllChats(c *fiber.Ctx) error {
// swagger:operation GET /chats chats chatsGetAllChats
// ---
// summary: List of chats
// consumes:
// - application/json
// produces:
// - application/json
// responses:
// '200':
// description: List of chats
// schema:
// "$ref": "#/definitions/ChatsResponse"
// '500':
// description: Internal server error
var chats []structs.Chat
q := scylladb.Session.Query(scylladb.Chats.SelectAll())
if err := q.SelectRelease(&chats); err != nil {
logrus.Errorln("Failed to get chats, err:", err)
}
return c.JSON(structs.ChatsResponse{Chats: chats})
}

View File

@ -2,6 +2,7 @@ package router
import ( import (
"clickandjoin.app/managementsystem/modules/config" "clickandjoin.app/managementsystem/modules/config"
"clickandjoin.app/managementsystem/routers/api/v1/chats"
"clickandjoin.app/managementsystem/routers/api/v1/users" "clickandjoin.app/managementsystem/routers/api/v1/users"
"clickandjoin.app/managementsystem/routers/api/v1/wssessions" "clickandjoin.app/managementsystem/routers/api/v1/wssessions"
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
@ -16,6 +17,9 @@ func SetupRoutes(app *fiber.App) {
wss := v1.Group("/wssessions") wss := v1.Group("/wssessions")
wss.Get("/", ApiKeyValidation, wssessions.GetAllWsSessions) wss.Get("/", ApiKeyValidation, wssessions.GetAllWsSessions)
c := v1.Group("/chats")
c.Get("/", ApiKeyValidation, chats.GetAllChats)
} }
func ApiKeyValidation(c *fiber.Ctx) error { func ApiKeyValidation(c *fiber.Ctx) error {