Add paggination to ListNotification functions (#339)

Merge branch 'master' into update-notifications

Merge branch 'master' into update-notifications

rm nonesence - dont know why i put it there

add paggination to ListNotification functions

refactor

Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/339
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Reviewed-by: Andrew Thornton <art27@cantab.net>
This commit is contained in:
6543 2020-05-20 08:26:47 +00:00 committed by Andrew Thornton
parent f224b4e50c
commit bb6248f50d
1 changed files with 6 additions and 5 deletions

View File

@ -31,6 +31,7 @@ type NotificationSubject struct {
// ListNotificationOptions represents the filter options
type ListNotificationOptions struct {
ListOptions
Since time.Time
Before time.Time
}
@ -42,7 +43,7 @@ type MarkNotificationOptions struct {
// QueryEncode encode options to url query
func (opt *ListNotificationOptions) QueryEncode() string {
query := make(url.Values)
query := opt.getURLQuery()
if !opt.Since.IsZero() {
query.Add("since", opt.Since.Format(time.RFC3339))
}
@ -75,10 +76,10 @@ func (c *Client) CheckNotifications() (int64, error) {
// GetNotification get notification thread by ID
func (c *Client) GetNotification(id int64) (*NotificationThread, error) {
thread := new(NotificationThread)
if err := c.CheckServerVersionConstraint(">=1.12.0"); err != nil {
return thread, err
return nil, err
}
thread := new(NotificationThread)
return thread, c.getParsedResponse("GET", fmt.Sprintf("/notifications/threads/%d", id), nil, nil, thread)
}
@ -94,7 +95,7 @@ func (c *Client) ReadNotification(id int64) error {
// ListNotifications list users's notification threads
func (c *Client) ListNotifications(opt ListNotificationOptions) ([]*NotificationThread, error) {
if err := c.CheckServerVersionConstraint(">=1.12.0"); err != nil {
return make([]*NotificationThread, 0, 1), err
return nil, err
}
link, _ := url.Parse("/notifications")
link.RawQuery = opt.QueryEncode()
@ -116,7 +117,7 @@ func (c *Client) ReadNotifications(opt MarkNotificationOptions) error {
// ListRepoNotifications list users's notification threads on a specific repo
func (c *Client) ListRepoNotifications(owner, reponame string, opt ListNotificationOptions) ([]*NotificationThread, error) {
if err := c.CheckServerVersionConstraint(">=1.12.0"); err != nil {
return make([]*NotificationThread, 0, 1), err
return nil, err
}
link, _ := url.Parse(fmt.Sprintf("/repos/%s/%s/notifications", owner, reponame))
link.RawQuery = opt.QueryEncode()