Field Date Filter
* Search can be filtered out with ?fromDate=2017-05-01 and ?toDate=2017-05-12
Cette révision appartient à :
Parent
b3f2b7bc8c
révision
f41f2c3a25
3 fichiers modifiés avec 30 ajouts et 0 suppressions
|
@ -162,6 +162,8 @@ type SearchParam struct {
|
|||
Status Status
|
||||
Sort SortMode
|
||||
Category Category
|
||||
FromDate string
|
||||
ToDate string
|
||||
Page int
|
||||
UserID uint
|
||||
Max uint
|
||||
|
|
|
@ -29,6 +29,8 @@ type TorrentParam struct {
|
|||
UserID uint32
|
||||
TorrentID uint32
|
||||
FromID uint32
|
||||
FromDate string
|
||||
ToDate string
|
||||
NotNull string // csv
|
||||
Null string // csv
|
||||
NameLike string // csv
|
||||
|
@ -69,6 +71,9 @@ func (p *TorrentParam) FromRequest(r *http.Request) {
|
|||
var status Status
|
||||
status.Parse(r.URL.Query().Get("s"))
|
||||
|
||||
p.FromDate = r.URL.Query().Get("fromDate")
|
||||
p.ToDate = r.URL.Query().Get("toDate")
|
||||
|
||||
var category Category
|
||||
category.Parse(r.URL.Query().Get("c"))
|
||||
|
||||
|
@ -129,6 +134,15 @@ func (p *TorrentParam) ToFilterQuery() string {
|
|||
if p.FromID != 0 {
|
||||
query += " id:>" + strconv.FormatInt(int64(p.FromID), 10)
|
||||
}
|
||||
|
||||
if p.FromDate != "" && p.ToDate != "" {
|
||||
query += " date: [" + p.FromDate + " " + p.ToDate + "]"
|
||||
} else if p.FromDate != "" {
|
||||
query += " date: [" + p.FromDate + " *]"
|
||||
} else if p.ToDate != "" {
|
||||
query += " date: [* " + p.ToDate + "]"
|
||||
}
|
||||
|
||||
return query
|
||||
}
|
||||
|
||||
|
@ -229,6 +243,8 @@ func (p *TorrentParam) Clone() TorrentParam {
|
|||
UserID: p.UserID,
|
||||
TorrentID: p.TorrentID,
|
||||
FromID: p.FromID,
|
||||
FromDate: p.FromDate,
|
||||
ToDate: p.ToDate,
|
||||
NotNull: p.NotNull,
|
||||
Null: p.Null,
|
||||
NameLike: p.NameLike,
|
||||
|
|
|
@ -86,6 +86,8 @@ func searchByQuery(r *http.Request, pagenum int, countAll bool, withUser bool, d
|
|||
searchParam := common.SearchParam{
|
||||
TorrentID: uint(torrentParam.TorrentID),
|
||||
FromID: uint(torrentParam.FromID),
|
||||
FromDate: torrentParam.FromDate,
|
||||
ToDate: torrentParam.ToDate,
|
||||
Order: torrentParam.Order,
|
||||
Status: torrentParam.Status,
|
||||
Sort: torrentParam.Sort,
|
||||
|
@ -121,6 +123,8 @@ func searchByQueryPostgres(r *http.Request, pagenum int, countAll bool, withUser
|
|||
search.UserID = uint(userID)
|
||||
fromID, _ := strconv.Atoi(r.URL.Query().Get("fromID"))
|
||||
search.FromID = uint(fromID)
|
||||
search.FromDate = r.URL.Query().Get("fromDate")
|
||||
search.ToDate = r.URL.Query().Get("toDate")
|
||||
|
||||
switch s := r.URL.Query().Get("s"); s {
|
||||
case "1":
|
||||
|
@ -224,6 +228,14 @@ func searchByQueryPostgres(r *http.Request, pagenum int, countAll bool, withUser
|
|||
conditions = append(conditions, "torrent_id > ?")
|
||||
parameters.Params = append(parameters.Params, search.FromID)
|
||||
}
|
||||
if search.FromDate != "" {
|
||||
conditions = append(conditions, "date >= ?")
|
||||
parameters.Params = append(parameters.Params, search.FromDate)
|
||||
}
|
||||
if search.ToDate != "" {
|
||||
conditions = append(conditions, "date <= ?")
|
||||
parameters.Params = append(parameters.Params, search.ToDate)
|
||||
}
|
||||
if search.Category.Sub != 0 {
|
||||
conditions = append(conditions, "sub_category = ?")
|
||||
parameters.Params = append(parameters.Params, search.Category.Sub)
|
||||
|
|
Référencer dans un nouveau ticket