diff --git a/go.mod b/go.mod index a1e68c4..375007b 100644 --- a/go.mod +++ b/go.mod @@ -14,6 +14,7 @@ require ( github.com/golang/snappy v0.0.4 // indirect github.com/google/uuid v1.3.0 // indirect github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed // indirect + github.com/jinzhu/copier v0.3.5 // indirect github.com/klauspost/compress v1.15.15 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.17 // indirect diff --git a/go.sum b/go.sum index 203bcfd..cc6c921 100644 --- a/go.sum +++ b/go.sum @@ -16,6 +16,8 @@ github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed h1:5upAirOpQc1Q53c0bnx2ufif5kANL7bfZWcc6VJWJd8= github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed/go.mod h1:tMWxXQ9wFIaZeTI9F+hmhFiGpFmhOHzyShyFUhRm0H4= +github.com/jinzhu/copier v0.3.5 h1:GlvfUwHk62RokgqVNvYsku0TATCF7bAHVwEXoBh3iJg= +github.com/jinzhu/copier v0.3.5/go.mod h1:DfbEm0FYsaqBcKcFuvmOZb218JkPGtvSHsKg8S8hyyg= github.com/joho/godotenv v1.5.0 h1:C/Vohk/9L1RCoS/UW2gfyi2N0EElSW3yb9zwi3PjosE= github.com/joho/godotenv v1.5.0/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= github.com/klauspost/compress v1.15.9 h1:wKRjX6JRtDdrE9qwa4b/Cip7ACOshUI4smpCQanqjSY= diff --git a/modules/structs/user.go b/modules/structs/user.go index b25fd03..a3aa5bf 100644 --- a/modules/structs/user.go +++ b/modules/structs/user.go @@ -28,6 +28,16 @@ type User struct { 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 diff --git a/modules/utils/definitions.go b/modules/utils/definitions.go new file mode 100644 index 0000000..865f8b8 --- /dev/null +++ b/modules/utils/definitions.go @@ -0,0 +1,3 @@ +package utils + +const LenUserId = 36 diff --git a/routers/api/v1/chats/chats.go b/routers/api/v1/chats/chats.go index aff93ee..5ddf966 100644 --- a/routers/api/v1/chats/chats.go +++ b/routers/api/v1/chats/chats.go @@ -17,7 +17,6 @@ func GetAllChats(c *fiber.Ctx) error { // - application/json // responses: // '200': - // description: List of chats // schema: // "$ref": "#/definitions/ChatsResponse" // '500': diff --git a/routers/api/v1/users/users.go b/routers/api/v1/users/users.go index 03e954b..63d357e 100644 --- a/routers/api/v1/users/users.go +++ b/routers/api/v1/users/users.go @@ -3,7 +3,9 @@ package users import ( "clickandjoin.app/managementsystem/modules/scylladb" "clickandjoin.app/managementsystem/modules/structs" + "clickandjoin.app/managementsystem/modules/utils" "github.com/gofiber/fiber/v2" + "github.com/jinzhu/copier" "github.com/sirupsen/logrus" ) @@ -42,6 +44,45 @@ func GetAllUsers(c *fiber.Ctx) error { return c.JSON(structs.UsersResponse{Users: nUsers}) } +func GetUserProfile(c *fiber.Ctx) error { + // swagger:operation GET /users/:userId users usersGetUserProfile + // --- + // summary: Get the profile from a user + // consumes: + // - application/json + // produces: + // - application/json + // responses: + // '200': + // schema: + // "$ref": "#/definitions/UserResponse" + // '400': + // description: Internal userId specified + // '500': + // description: Internal server error + + userId := c.Params("userId") + + if len(userId) != utils.LenUserId { + return c.SendStatus(fiber.StatusBadRequest) + } + + foundUser := structs.User{Id: userId} + + q := scylladb.Session.Query(scylladb.Users.Get()).BindStruct(foundUser) + + if err := q.GetRelease(&foundUser); err != nil { + logrus.Println("Failed to get user, err:", err) + return c.SendStatus(fiber.StatusUnprocessableEntity) + } + + var resUser structs.UserResponse + + copier.Copy(&resUser, &foundUser) + + return c.JSON(resUser) +} + func GetAllUserSignUpProcesses(c *fiber.Ctx) error { // swagger:operation GET /users/signupprocesses users usersGetAllUserSignUpProcesses // --- diff --git a/routers/router/router.go b/routers/router/router.go index 1ad1c71..c5b1cd9 100644 --- a/routers/router/router.go +++ b/routers/router/router.go @@ -3,6 +3,7 @@ package router import ( "clickandjoin.app/managementsystem/modules/config" "clickandjoin.app/managementsystem/routers/api/v1/chats" + "clickandjoin.app/managementsystem/routers/api/v1/stats" "clickandjoin.app/managementsystem/routers/api/v1/users" "clickandjoin.app/managementsystem/routers/api/v1/wssessions" "github.com/gofiber/fiber/v2" @@ -16,12 +17,16 @@ 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("/:userId", ApiKeyValidation, users.GetUserProfile) wss := v1.Group("/wssessions") wss.Get("/", ApiKeyValidation, wssessions.GetAllWsSessions) c := v1.Group("/chats") c.Get("/", ApiKeyValidation, chats.GetAllChats) + + s := v1.Group("/stats") + s.Get("/", ApiKeyValidation, stats.GetStats) } func ApiKeyValidation(c *fiber.Ctx) error {