Mandanten, OAuth, Cleanup von der Main Methode.
This commit is contained in:
@ -1,5 +1,12 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
type OffsetPaginationError struct {
|
||||
Page int
|
||||
Pages int
|
||||
@ -35,3 +42,27 @@ func (p *KeysetPaginationError) Error() string {
|
||||
func NewKeysetPaginationError(key int, next int, previous int) error {
|
||||
return &KeysetPaginationError{Key: key, NextKey: next, PreviousKey: previous}
|
||||
}
|
||||
|
||||
func AddPaginationParams(c *fiber.Ctx) error {
|
||||
err := c.Next()
|
||||
if err != nil {
|
||||
|
||||
var offset *OffsetPaginationError
|
||||
if errors.As(err, &offset) {
|
||||
c.Append("X-Page", strconv.Itoa(offset.Page))
|
||||
c.Append("X-Pages", strconv.Itoa(offset.Pages))
|
||||
c.Append("X-Next-Page", strconv.Itoa(offset.NextPage))
|
||||
c.Append("X-Last-Page", strconv.Itoa(offset.LastPage))
|
||||
return nil
|
||||
}
|
||||
|
||||
var keyset *KeysetPaginationError
|
||||
if errors.As(err, &keyset) {
|
||||
c.Append("X-Key", strconv.Itoa(keyset.Key))
|
||||
c.Append("X-Previous-Key", strconv.Itoa(keyset.PreviousKey))
|
||||
c.Append("X-Next-Key", strconv.Itoa(keyset.NextKey))
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user