47 lines
1.1 KiB
Go
47 lines
1.1 KiB
Go
package users
|
|
|
|
import (
|
|
"jannex/admin-dashboard-backend/modules/database"
|
|
"jannex/admin-dashboard-backend/modules/structs"
|
|
"jannex/admin-dashboard-backend/socketclients"
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
)
|
|
|
|
func GetUsers(c *fiber.Ctx) error {
|
|
// swagger:operation GET /users users usersGetUsers
|
|
// ---
|
|
// summary: Get all users
|
|
// 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: All users
|
|
// schema:
|
|
// "$ref": "#/definitions/UsersResponse"
|
|
// '401':
|
|
// description: No permissions
|
|
// '500':
|
|
// description: Failed to get users
|
|
|
|
var user structs.User
|
|
|
|
database.DB.Select("role_id").First(&user, "id = ?", c.Locals("userId").(string))
|
|
|
|
var roles []structs.UserRoleShortInfo
|
|
|
|
database.DB.Model(&structs.Role{}).Select("id, master, display_name, sorting_order").Find(&roles)
|
|
|
|
return c.JSON(structs.UsersResponse{
|
|
RoleId: user.RoleId,
|
|
Users: socketclients.GetAllUsers(),
|
|
Roles: roles,
|
|
})
|
|
}
|