diff --git a/go.mod b/go.mod index 96bf459..f14c9bf 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module clickandjoin.app/managementsystem go 1.18 require ( - git.clickandjoin.umbach.dev/ClickandJoin/go-cnj-helper v1.0.67 + git.clickandjoin.umbach.dev/ClickandJoin/go-cnj-helper v1.0.68 github.com/gocql/gocql v0.0.0-20211015133455-b225f9b53fa1 github.com/gofiber/fiber/v2 v2.42.0 github.com/gofiber/websocket/v2 v2.1.4 diff --git a/go.sum b/go.sum index 49c7381..a6ab508 100644 --- a/go.sum +++ b/go.sum @@ -4,6 +4,8 @@ git.clickandjoin.umbach.dev/ClickandJoin/go-cnj-helper v1.0.66 h1:ljNWOs0KDK5Hsv git.clickandjoin.umbach.dev/ClickandJoin/go-cnj-helper v1.0.66/go.mod h1:rnEM9rcZy2dg4SaDCGmSf34fp7ECzdyxxnRut2HBmrs= git.clickandjoin.umbach.dev/ClickandJoin/go-cnj-helper v1.0.67 h1:a5mZBmx5rBgnU9OKQja8eX6QfoaiubWBqsaXWUcidqY= git.clickandjoin.umbach.dev/ClickandJoin/go-cnj-helper v1.0.67/go.mod h1:rnEM9rcZy2dg4SaDCGmSf34fp7ECzdyxxnRut2HBmrs= +git.clickandjoin.umbach.dev/ClickandJoin/go-cnj-helper v1.0.68 h1:krwHGA+GLaK3tEhWT9MlA/X/WssGaHIQZtnVoZMqJrE= +git.clickandjoin.umbach.dev/ClickandJoin/go-cnj-helper v1.0.68/go.mod h1:rnEM9rcZy2dg4SaDCGmSf34fp7ECzdyxxnRut2HBmrs= github.com/andybalholm/brotli v1.0.4 h1:V7DdXeJtZscaqfNuAdSRuRFzuiKlHSC/Zh3zl9qY3JY= github.com/andybalholm/brotli v1.0.4/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig= github.com/bitly/go-hostpool v0.0.0-20171023180738-a3a6125de932 h1:mXoPYz/Ul5HYEDvkta6I8/rnYM5gSdSV2tJ6XbZuEtY= diff --git a/modules/structs/user.go b/modules/structs/user.go index f16ff8c..7591303 100644 --- a/modules/structs/user.go +++ b/modules/structs/user.go @@ -22,6 +22,11 @@ type UserPrivacySettingsResponse struct { PrivacySettings []dbstructs.UserPrivacySettings } +// swagger:model UserSessionsResponse +type UserSessionsResponse struct { + UserSessions []dbstructs.UserSession +} + // swagger:model UpdateUserRequest type UpdateUserRequest struct { Username string diff --git a/routers/api/v1/users/users.go b/routers/api/v1/users/users.go index d9bb47d..4580403 100644 --- a/routers/api/v1/users/users.go +++ b/routers/api/v1/users/users.go @@ -120,3 +120,29 @@ func GetAllUserPrivacySettings(c *fiber.Ctx) error { return c.JSON(structs.UserPrivacySettingsResponse{PrivacySettings: userPrivacySettings}) } + +func GetAllUserSessions(c *fiber.Ctx) error { + // swagger:operation GET /users/sessions users usersGetAllUserSessions + // --- + // summary: List of all user sessions + // consumes: + // - application/json + // produces: + // - application/json + // responses: + // '200': + // schema: + // "$ref": "#/definitions/UserSessionsResponse" + // '500': + // description: Internal server error + + var userSessions []dbstructs.UserSession + + q := scylladb.Session.Query(gocnjhelper.DbMSessions.SelectAll()) + + if err := q.SelectRelease(&userSessions); err != nil { + gocnjhelper.LogErrorf("Failed to get all user sessions, err: %s", err) + } + + return c.JSON(structs.UserSessionsResponse{UserSessions: userSessions}) +} diff --git a/routers/router/router.go b/routers/router/router.go index 02300d6..51f96d6 100644 --- a/routers/router/router.go +++ b/routers/router/router.go @@ -18,6 +18,7 @@ func SetupRoutes(app *fiber.App) { us.Get("/signupprocesses", ApiKeyValidation, users.GetAllUserSignUpProcesses) us.Get("/relationships", ApiKeyValidation, users.GetAllUserRelationships) us.Get("/privacysettings", ApiKeyValidation, users.GetAllUserPrivacySettings) + us.Get("/sessions", ApiKeyValidation, users.GetAllUserSessions) u := v1.Group("/user") u.Patch("/:userId", ApiKeyValidation, user.UpdateUser)