/
dto.go
45 lines (37 loc) · 1009 Bytes
/
dto.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package notice
import (
"time"
)
const DEFAULT_CHAIN = "dimension"
const MAX_LIMIT = 30
var DefaultPaginationCond = PaginationCond{
Limit: 0,
Asc: false,
After: ^uint(0) >> 1,
}
type NoticeItem struct {
Id uint `json:"id"`
Chain string `json:"chain"`
Title string `json:"title"`
Description string `json:"description"`
Date time.Time `json:"date" gorm:"index:notice_date_idx type:timestamp without time zone"`
}
// PaginationCond contains pagination conditions
// Limit is the maximum number of items to return
// Asc is the order of items to return (default: descending order)
type PaginationCond struct {
After uint `json:"after,omitempty"`
Limit uint `json:"limit,omitempty"`
Asc bool `json:"asc,omitempty"`
}
func (p *PaginationCond) Trim() {
if p.Limit > MAX_LIMIT {
p.Limit = MAX_LIMIT
}
if p.Asc && p.After == DefaultPaginationCond.After {
p.After = 0
}
if !p.Asc && p.After == 0 {
p.After = DefaultPaginationCond.After
}
}