mirror of
https://github.com/snowykami/neo-blog.git
synced 2025-09-03 15:56:22 +00:00
- Renamed `orderedBy` to `orderBy` and `reverse` to `desc` in ListPostsParams interface and related functions. - Updated all usages of the sorting parameters in the post listing logic to reflect the new naming convention. feat: add user-related API functions - Implemented `getLoginUser` and `getUserById` functions in the user API to fetch user details. - Enhanced user model to include `language` property. feat: integrate next-intl for internationalization - Added `next-intl` plugin to Next.js configuration for improved localization support. - Removed previous i18n implementation and replaced it with a new structure using JSON files for translations. - Created locale files for English, Japanese, and Chinese with basic translations. - Implemented a request configuration to handle user locales and messages dynamically. fix: clean up unused imports and code - Removed unused i18n utility functions and language settings from device context. - Cleaned up commented-out code in blog card component and sidebar. chore: update dependencies - Added `deepmerge` for merging locale messages. - Updated package.json and pnpm-lock.yaml to reflect new dependencies.
47 lines
878 B
Go
47 lines
878 B
Go
package ctxutils
|
|
|
|
import (
|
|
"github.com/cloudwego/hertz/pkg/app"
|
|
"strconv"
|
|
)
|
|
|
|
type PaginationParams struct {
|
|
Page uint64
|
|
Size uint64
|
|
OrderBy string
|
|
Desc bool // 默认是从大值到小值
|
|
}
|
|
|
|
func GetPaginationParams(c *app.RequestContext) *PaginationParams {
|
|
page := c.Query("page")
|
|
size := c.Query("size")
|
|
orderBy := c.Query("order_by")
|
|
desc := c.Query("desc")
|
|
if page == "" {
|
|
page = "1"
|
|
}
|
|
if size == "" {
|
|
size = "10"
|
|
}
|
|
var descBool bool
|
|
if desc == "" || desc == "false" || desc == "0" {
|
|
descBool = false
|
|
} else {
|
|
descBool = true
|
|
}
|
|
pageNum, err := strconv.ParseUint(page, 10, 64)
|
|
if err != nil || pageNum < 1 {
|
|
pageNum = 1
|
|
}
|
|
sizeNum, err := strconv.ParseUint(size, 10, 64)
|
|
if err != nil || sizeNum < 1 {
|
|
sizeNum = 10
|
|
}
|
|
return &PaginationParams{
|
|
Page: pageNum,
|
|
Size: sizeNum,
|
|
OrderBy: orderBy,
|
|
Desc: descBool,
|
|
}
|
|
}
|