51 lines
1.4 KiB
Go
51 lines
1.4 KiB
Go
package user
|
|
|
|
import (
|
|
"jannex/admin-dashboard-backend/modules/database"
|
|
"jannex/admin-dashboard-backend/modules/notification"
|
|
"jannex/admin-dashboard-backend/modules/structs"
|
|
"jannex/admin-dashboard-backend/socketclients"
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
)
|
|
|
|
func UserInfo(c *fiber.Ctx) error {
|
|
// swagger:operation GET /user/info user userInfo
|
|
// ---
|
|
// summary: Get user info
|
|
// consumes:
|
|
// - application/json
|
|
// produces:
|
|
// - application/json
|
|
// parameters:
|
|
// - name: X-Api-Key
|
|
// in: header
|
|
// description: You can create a new api key in your user profile
|
|
// responses:
|
|
// '200':
|
|
// description: User info
|
|
// schema:
|
|
// "$ref": "#/definitions/UserInfoResponse"
|
|
// '401':
|
|
// description: No permissions
|
|
// '500':
|
|
// description: Failed to get user info
|
|
|
|
userId := c.Locals("userId").(string)
|
|
var user structs.User
|
|
|
|
database.DB.Select("username, avatar", "role_id").First(&user, "id = ?", userId)
|
|
|
|
categories := socketclients.GetAvailableCategories(userId)
|
|
|
|
return c.JSON(structs.UserInfoResponse{
|
|
UserId: userId,
|
|
Username: user.Username,
|
|
Avatar: user.Avatar,
|
|
Permissions: socketclients.GetPermissionsByRoleId(user.RoleId),
|
|
AvailableCategories: categories,
|
|
Users: socketclients.GetAllUsers(),
|
|
TotalNotifications: notification.GetTotalNotifications(user.Id),
|
|
})
|
|
}
|