package user import ( "jannex/admin-dashboard-backend/modules/cache" "jannex/admin-dashboard-backend/modules/database" "jannex/admin-dashboard-backend/modules/notification" "jannex/admin-dashboard-backend/modules/structs" "jannex/admin-dashboard-backend/modules/utils" "jannex/admin-dashboard-backend/socketclients" "slices" "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 var user structs.User database.DB.Select("id, username, avatar", "role_id").First(&user, "id = ?", c.Locals("userId").(string)) var categories []string for _, categoryGroup := range cache.GetCategoryGroups() { if socketclients.HasXYPermission(user.Id, utils.PermissionGroupTasksOverviewXYView, categoryGroup.Category) { categories = append(categories, categoryGroup.Category) } } // sort categories alphabetically slices.Sort(categories) return c.JSON(structs.UserInfoResponse{ UserId: user.Id, Username: user.Username, Avatar: user.Avatar, Permissions: socketclients.GetPermissionsByRoleId(user.RoleId), AvailableCategoryGroups: categories, Users: socketclients.GetAllUsers(), TotalNotifications: notification.GetTotalNotifications(user.Id), }) }