All checks were successful
Build and Release / release (push) Successful in 1m3s
58 lines
1.3 KiB
Go
58 lines
1.3 KiB
Go
package response
|
|
|
|
import (
|
|
"history-api/pkg/constants"
|
|
|
|
"github.com/golang-jwt/jwt/v5"
|
|
)
|
|
|
|
type CommonResponse struct {
|
|
Status bool `json:"status"`
|
|
Data any `json:"data"`
|
|
Message string `json:"message"`
|
|
}
|
|
|
|
type JWTClaims struct {
|
|
UId string `json:"uid"`
|
|
Roles []constants.Role `json:"roles"`
|
|
TokenVersion int32 `json:"token_version"`
|
|
jwt.RegisteredClaims
|
|
}
|
|
|
|
type PaginationMeta struct {
|
|
CurrentPage int `json:"current_page"`
|
|
PageSize int `json:"page_size"`
|
|
TotalRecords int64 `json:"total_records"`
|
|
TotalPages int `json:"total_pages"`
|
|
}
|
|
|
|
type PaginatedResponse struct {
|
|
Status bool `json:"status"`
|
|
Message string `json:"message"`
|
|
Data any `json:"data"`
|
|
Pagination *PaginationMeta `json:"pagination"`
|
|
}
|
|
|
|
func BuildPaginatedResponse(data any, totalRecords int64, page int, limit int) *PaginatedResponse {
|
|
if page < 1 {
|
|
page = 1
|
|
}
|
|
if limit < 1 {
|
|
limit = 10
|
|
}
|
|
|
|
totalPages := int((totalRecords + int64(limit) - 1) / int64(limit))
|
|
|
|
return &PaginatedResponse{
|
|
Status: true,
|
|
Message: "Success",
|
|
Data: data,
|
|
Pagination: &PaginationMeta{
|
|
CurrentPage: page,
|
|
PageSize: limit,
|
|
TotalRecords: totalRecords,
|
|
TotalPages: totalPages,
|
|
},
|
|
}
|
|
}
|