mirror of
https://gitlab.bertha.cloud/partitio/Nextcloud-Partitio/gonextcloud
synced 2025-07-15 01:18:28 +00:00
Moved all methods inside sub Interfaces and structs
This commit is contained in:
@ -8,12 +8,28 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
//NotificationsList returns all the notifications
|
||||
func (c *Client) NotificationsList() ([]types.Notification, error) {
|
||||
if err := c.notificationsAvailable(); err != nil {
|
||||
//NotificationsI available methods
|
||||
type NotificationsI interface {
|
||||
List() ([]types.Notification, error)
|
||||
Get(id int) (types.Notification, error)
|
||||
Delete(id int) error
|
||||
DeleteAll() error
|
||||
Create(userID, title, message string) error
|
||||
AdminAvailable() error
|
||||
Available() error
|
||||
}
|
||||
|
||||
//Notifications contains all Notifications available actions
|
||||
type Notifications struct {
|
||||
c *Client
|
||||
}
|
||||
|
||||
//List returns all the notifications
|
||||
func (n *Notifications) List() ([]types.Notification, error) {
|
||||
if err := n.Available(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
res, err := c.baseRequest(http.MethodGet, routes.notifications, nil)
|
||||
res, err := n.c.baseRequest(http.MethodGet, routes.notifications, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -22,12 +38,12 @@ func (c *Client) NotificationsList() ([]types.Notification, error) {
|
||||
return r.Ocs.Data, nil
|
||||
}
|
||||
|
||||
//Notifications returns the notification corresponding to the id
|
||||
func (c *Client) Notifications(id int) (types.Notification, error) {
|
||||
if err := c.notificationsAvailable(); err != nil {
|
||||
//Get returns the notification corresponding to the id
|
||||
func (n *Notifications) Get(id int) (types.Notification, error) {
|
||||
if err := n.Available(); err != nil {
|
||||
return types.Notification{}, err
|
||||
}
|
||||
res, err := c.baseRequest(http.MethodGet, routes.notifications, nil, strconv.Itoa(id))
|
||||
res, err := n.c.baseRequest(http.MethodGet, routes.notifications, nil, strconv.Itoa(id))
|
||||
if err != nil {
|
||||
return types.Notification{}, err
|
||||
}
|
||||
@ -36,27 +52,27 @@ func (c *Client) Notifications(id int) (types.Notification, error) {
|
||||
return r.Ocs.Data, nil
|
||||
}
|
||||
|
||||
//NotificationsDelete deletes the notification corresponding to the id
|
||||
func (c *Client) NotificationsDelete(id int) error {
|
||||
if err := c.notificationsAvailable(); err != nil {
|
||||
//Delete deletes the notification corresponding to the id
|
||||
func (n *Notifications) Delete(id int) error {
|
||||
if err := n.Available(); err != nil {
|
||||
return err
|
||||
}
|
||||
_, err := c.baseRequest(http.MethodDelete, routes.notifications, nil, strconv.Itoa(id))
|
||||
_, err := n.c.baseRequest(http.MethodDelete, routes.notifications, nil, strconv.Itoa(id))
|
||||
return err
|
||||
}
|
||||
|
||||
//NotificationsDeleteAll deletes all notifications
|
||||
func (c *Client) NotificationsDeleteAll() error {
|
||||
if err := c.notificationsAvailable(); err != nil {
|
||||
//DeleteAll deletes all notifications
|
||||
func (n *Notifications) DeleteAll() error {
|
||||
if err := n.Available(); err != nil {
|
||||
return err
|
||||
}
|
||||
_, err := c.baseRequest(http.MethodDelete, routes.notifications, nil)
|
||||
_, err := n.c.baseRequest(http.MethodDelete, routes.notifications, nil)
|
||||
return err
|
||||
}
|
||||
|
||||
//NotificationsCreate creates a notification (if the user is an admin)
|
||||
func (c *Client) NotificationsCreate(userID, title, message string) error {
|
||||
if err := c.adminNotificationsAvailable(); err != nil {
|
||||
//Create creates a notification (if the user is an admin)
|
||||
func (n *Notifications) Create(userID, title, message string) error {
|
||||
if err := n.AdminAvailable(); err != nil {
|
||||
return err
|
||||
}
|
||||
ro := &req.RequestOptions{
|
||||
@ -65,18 +81,21 @@ func (c *Client) NotificationsCreate(userID, title, message string) error {
|
||||
"longMessage": message,
|
||||
},
|
||||
}
|
||||
_, err := c.baseRequest(http.MethodPost, routes.adminNotifications, ro, userID)
|
||||
_, err := n.c.baseRequest(http.MethodPost, routes.adminNotifications, ro, userID)
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *Client) adminNotificationsAvailable() error {
|
||||
if len(c.capabilities.Notifications.AdminNotifications) == 0 {
|
||||
//AdminAvailable returns an error if the admin-notifications app is not installed
|
||||
func (n *Notifications) AdminAvailable() error {
|
||||
if len(n.c.capabilities.Notifications.AdminNotifications) == 0 {
|
||||
return errors.New("'admin notifications' not available on this instance")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (c *Client) notificationsAvailable() error {
|
||||
if len(c.capabilities.Notifications.OcsEndpoints) == 0 {
|
||||
|
||||
//Available returns an error if the notifications app is not installed
|
||||
func (n *Notifications) Available() error {
|
||||
if len(n.c.capabilities.Notifications.OcsEndpoints) == 0 {
|
||||
return errors.New("notifications not available on this instance")
|
||||
}
|
||||
return nil
|
||||
|
Reference in New Issue
Block a user