mirror of
https://github.com/1f349/go-webdav.git
synced 2024-12-22 16:24:14 +00:00
caldav: add support for time filters in client
This commit is contained in:
parent
57df6bf316
commit
4eb8396edb
@ -24,8 +24,15 @@ type CalendarCompRequest struct {
|
|||||||
Comps []CalendarCompRequest
|
Comps []CalendarCompRequest
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CompFilter struct {
|
||||||
|
Name string
|
||||||
|
Start, End time.Time
|
||||||
|
Comps []CompFilter
|
||||||
|
}
|
||||||
|
|
||||||
type CalendarQuery struct {
|
type CalendarQuery struct {
|
||||||
Comp CalendarCompRequest
|
CompRequest CalendarCompRequest
|
||||||
|
CompFilter CompFilter
|
||||||
}
|
}
|
||||||
|
|
||||||
type CalendarObject struct {
|
type CalendarObject struct {
|
||||||
|
@ -141,6 +141,20 @@ func encodeCalendarReq(c *CalendarCompRequest) (*internal.Prop, error) {
|
|||||||
return internal.EncodeProp(&calDataReq, getLastModReq, getETagReq)
|
return internal.EncodeProp(&calDataReq, getLastModReq, getETagReq)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func encodeCompFilter(filter *CompFilter) *compFilter {
|
||||||
|
encoded := compFilter{Name: filter.Name}
|
||||||
|
if !filter.Start.IsZero() || !filter.End.IsZero() {
|
||||||
|
encoded.TimeRange = &timeRange{
|
||||||
|
Start: dateWithUTCTime(filter.Start),
|
||||||
|
End: dateWithUTCTime(filter.End),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, child := range filter.Comps {
|
||||||
|
encoded.CompFilters = append(encoded.CompFilters, *encodeCompFilter(&child))
|
||||||
|
}
|
||||||
|
return &encoded
|
||||||
|
}
|
||||||
|
|
||||||
func decodeCalendarObjectList(ms *internal.Multistatus) ([]CalendarObject, error) {
|
func decodeCalendarObjectList(ms *internal.Multistatus) ([]CalendarObject, error) {
|
||||||
addrs := make([]CalendarObject, 0, len(ms.Responses))
|
addrs := make([]CalendarObject, 0, len(ms.Responses))
|
||||||
for _, resp := range ms.Responses {
|
for _, resp := range ms.Responses {
|
||||||
@ -176,12 +190,13 @@ func decodeCalendarObjectList(ms *internal.Multistatus) ([]CalendarObject, error
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) QueryCalendar(calendar string, query *CalendarQuery) ([]CalendarObject, error) {
|
func (c *Client) QueryCalendar(calendar string, query *CalendarQuery) ([]CalendarObject, error) {
|
||||||
propReq, err := encodeCalendarReq(&query.Comp)
|
propReq, err := encodeCalendarReq(&query.CompRequest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
calendarQuery := calendarQuery{Prop: propReq}
|
calendarQuery := calendarQuery{Prop: propReq}
|
||||||
|
calendarQuery.Filter.CompFilter = *encodeCompFilter(&query.CompFilter)
|
||||||
req, err := c.ic.NewXMLRequest("REPORT", calendar, &calendarQuery)
|
req, err := c.ic.NewXMLRequest("REPORT", calendar, &calendarQuery)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -63,7 +63,7 @@ type calendarQuery struct {
|
|||||||
// https://tools.ietf.org/html/rfc4791#section-9.7
|
// https://tools.ietf.org/html/rfc4791#section-9.7
|
||||||
type filter struct {
|
type filter struct {
|
||||||
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:caldav filter"`
|
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:caldav filter"`
|
||||||
Comp compFilter `xml:"comp-filter"`
|
CompFilter compFilter `xml:"comp-filter"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://tools.ietf.org/html/rfc4791#section-9.7.1
|
// https://tools.ietf.org/html/rfc4791#section-9.7.1
|
||||||
@ -72,14 +72,15 @@ type compFilter struct {
|
|||||||
Name string `xml:"name,attr"`
|
Name string `xml:"name,attr"`
|
||||||
IsNotDefined *struct{} `xml:"is-not-defined,omitempty"`
|
IsNotDefined *struct{} `xml:"is-not-defined,omitempty"`
|
||||||
TimeRange *timeRange `xml:"time-range,omitempty"`
|
TimeRange *timeRange `xml:"time-range,omitempty"`
|
||||||
// TODO: prop-filter, comp-filter
|
CompFilters []compFilter `xml:"comp-filter,omitempty"`
|
||||||
|
// TODO: prop-filter
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://tools.ietf.org/html/rfc4791#section-9.9
|
// https://tools.ietf.org/html/rfc4791#section-9.9
|
||||||
type timeRange struct {
|
type timeRange struct {
|
||||||
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:caldav time-range"`
|
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:caldav time-range"`
|
||||||
Start dateWithUTCTime `xml:"start,attr"`
|
Start dateWithUTCTime `xml:"start,attr,omitempty"`
|
||||||
End dateWithUTCTime `xml:"end,attr"`
|
End dateWithUTCTime `xml:"end,attr,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
const dateWithUTCTimeLayout = "20060102T150405Z"
|
const dateWithUTCTimeLayout = "20060102T150405Z"
|
||||||
|
Loading…
Reference in New Issue
Block a user