added get user profile

alpha
alex 2023-02-12 17:41:54 +01:00
parent 1673f04fd5
commit f9f2df13e7
7 changed files with 62 additions and 1 deletions

1
go.mod
View File

@ -14,6 +14,7 @@ require (
github.com/golang/snappy v0.0.4 // indirect github.com/golang/snappy v0.0.4 // indirect
github.com/google/uuid v1.3.0 // indirect github.com/google/uuid v1.3.0 // indirect
github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed // 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/klauspost/compress v1.15.15 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect github.com/mattn/go-isatty v0.0.17 // indirect

2
go.sum
View File

@ -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/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 h1:5upAirOpQc1Q53c0bnx2ufif5kANL7bfZWcc6VJWJd8=
github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed/go.mod h1:tMWxXQ9wFIaZeTI9F+hmhFiGpFmhOHzyShyFUhRm0H4= 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 h1:C/Vohk/9L1RCoS/UW2gfyi2N0EElSW3yb9zwi3PjosE=
github.com/joho/godotenv v1.5.0/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= github.com/joho/godotenv v1.5.0/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/klauspost/compress v1.15.9 h1:wKRjX6JRtDdrE9qwa4b/Cip7ACOshUI4smpCQanqjSY= github.com/klauspost/compress v1.15.9 h1:wKRjX6JRtDdrE9qwa4b/Cip7ACOshUI4smpCQanqjSY=

View File

@ -28,6 +28,16 @@ type User struct {
UpdatedAt int64 UpdatedAt int64
} }
// swagger:model UserResponse
type UserResponse struct {
Username string
AccountName string
Email string
Description string
AccountStatus uint8
AvatarUrl string
}
type UserPublicKeys struct { type UserPublicKeys struct {
gocqlx.UDT gocqlx.UDT
Id string Id string

View File

@ -0,0 +1,3 @@
package utils
const LenUserId = 36

View File

@ -17,7 +17,6 @@ func GetAllChats(c *fiber.Ctx) error {
// - application/json // - application/json
// responses: // responses:
// '200': // '200':
// description: List of chats
// schema: // schema:
// "$ref": "#/definitions/ChatsResponse" // "$ref": "#/definitions/ChatsResponse"
// '500': // '500':

View File

@ -3,7 +3,9 @@ package users
import ( import (
"clickandjoin.app/managementsystem/modules/scylladb" "clickandjoin.app/managementsystem/modules/scylladb"
"clickandjoin.app/managementsystem/modules/structs" "clickandjoin.app/managementsystem/modules/structs"
"clickandjoin.app/managementsystem/modules/utils"
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
"github.com/jinzhu/copier"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
@ -42,6 +44,45 @@ func GetAllUsers(c *fiber.Ctx) error {
return c.JSON(structs.UsersResponse{Users: nUsers}) 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 { func GetAllUserSignUpProcesses(c *fiber.Ctx) error {
// swagger:operation GET /users/signupprocesses users usersGetAllUserSignUpProcesses // swagger:operation GET /users/signupprocesses users usersGetAllUserSignUpProcesses
// --- // ---

View File

@ -3,6 +3,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/chats"
"clickandjoin.app/managementsystem/routers/api/v1/stats"
"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,12 +17,16 @@ func SetupRoutes(app *fiber.App) {
us.Get("/signupprocesses", ApiKeyValidation, users.GetAllUserSignUpProcesses) us.Get("/signupprocesses", ApiKeyValidation, users.GetAllUserSignUpProcesses)
us.Get("/relationships", ApiKeyValidation, users.GetAllUserRelationships) us.Get("/relationships", ApiKeyValidation, users.GetAllUserRelationships)
us.Get("/privacysettings", ApiKeyValidation, users.GetAllUserPrivacySettings) us.Get("/privacysettings", ApiKeyValidation, users.GetAllUserPrivacySettings)
us.Get("/:userId", ApiKeyValidation, users.GetUserProfile)
wss := v1.Group("/wssessions") wss := v1.Group("/wssessions")
wss.Get("/", ApiKeyValidation, wssessions.GetAllWsSessions) wss.Get("/", ApiKeyValidation, wssessions.GetAllWsSessions)
c := v1.Group("/chats") c := v1.Group("/chats")
c.Get("/", ApiKeyValidation, chats.GetAllChats) c.Get("/", ApiKeyValidation, chats.GetAllChats)
s := v1.Group("/stats")
s.Get("/", ApiKeyValidation, stats.GetStats)
} }
func ApiKeyValidation(c *fiber.Ctx) error { func ApiKeyValidation(c *fiber.Ctx) error {