Passport/pkg/internal/server/security_api.go

37 lines
907 B
Go
Raw Normal View History

2024-02-01 07:08:40 +00:00
package server
import (
"git.solsynth.dev/hydrogen/passport/pkg/internal/database"
"git.solsynth.dev/hydrogen/passport/pkg/internal/models"
2024-02-01 07:08:40 +00:00
"github.com/gofiber/fiber/v2"
)
2024-04-20 11:04:33 +00:00
func getTickets(c *fiber.Ctx) error {
2024-02-01 07:08:40 +00:00
user := c.Locals("principal").(models.Account)
take := c.QueryInt("take", 0)
offset := c.QueryInt("offset", 0)
var count int64
2024-04-21 04:20:06 +00:00
var tickets []models.AuthTicket
2024-02-01 07:08:40 +00:00
if err := database.C.
2024-04-20 11:04:33 +00:00
Where(&models.AuthTicket{AccountID: user.ID}).
Model(&models.AuthTicket{}).
2024-02-01 07:08:40 +00:00
Count(&count).Error; err != nil {
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
}
if err := database.C.
2024-02-12 04:31:18 +00:00
Order("created_at desc").
2024-04-20 11:04:33 +00:00
Where(&models.AuthTicket{AccountID: user.ID}).
2024-02-01 07:08:40 +00:00
Limit(take).
Offset(offset).
2024-04-21 04:20:06 +00:00
Find(&tickets).Error; err != nil {
2024-02-01 07:08:40 +00:00
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
}
return c.JSON(fiber.Map{
"count": count,
2024-04-21 04:20:06 +00:00
"data": tickets,
2024-02-01 07:08:40 +00:00
})
}