Documentation ¶
Overview ¶
(Web)Push notifications and subscriptions routes and controllers logic package for the backend.
Index ¶
- Constants
- Variables
- func GetSubscriptionByID(userID string, cache db.Cacher) (*[]models.Device, error)
- func NewPushRouter(pushController *PushController) chi.Router
- func NewSubscriptionRepository(cache db.Cacher) models.SubscriptionRepositoryInterface
- func SendNotificationToDevices(opts *NotificationOpts)
- type NotificationOpts
- type NotificationRequest
- type PushController
- type SubscriptionRepository
- type SubscriptionService
- func (s *SubscriptionService) Create(ctx context.Context, device *models.Device) error
- func (s *SubscriptionService) Delete(ctx context.Context, uuid string) error
- func (s *SubscriptionService) SendNotification(ctx context.Context, postID string) error
- func (s *SubscriptionService) Update(ctx context.Context, uuid, tagName string) error
- type SubscriptionUpdateRequest
Constants ¶
View Source
const (
LOGGER_WORKER_NAME string = "pushController"
)
Variables ¶
View Source
var (
ErrSubscriptionNotFound error = errors.New("could not find requested Subscription")
)
Functions ¶
func GetSubscriptionByID ¶ added in v0.44.32
GetSubscriptionByID is a static function to export to other services.
func NewPushRouter ¶ added in v0.45.27
func NewPushRouter(pushController *PushController) chi.Router
func NewSubscriptionRepository ¶ added in v0.44.32
func NewSubscriptionRepository(cache db.Cacher) models.SubscriptionRepositoryInterface
func SendNotificationToDevices ¶
func SendNotificationToDevices(opts *NotificationOpts)
Types ¶
type NotificationOpts ¶ added in v0.43.0
type NotificationRequest ¶ added in v0.45.27
type NotificationRequest struct {
PostID string `json:"post_id" example:"123456789000"`
}
type PushController ¶ added in v0.45.27
type PushController struct {
// contains filtered or unexported fields
}
func NewPushController ¶ added in v0.45.27
func NewPushController( subscriptionService models.SubscriptionServiceInterface, ) *PushController
func (*PushController) Create ¶ added in v0.45.27
func (c *PushController) Create(w http.ResponseWriter, r *http.Request)
Create is the handler function to ensure that a sent device has been subscribed to notifications.
@Summary Create the notifications subscription @Description This function call takes in a device specification and creates a new user subscription to webpush notifications. @Tags push @Accept json @Produce json @Param request body models.Device true "A device to create the notification subscription for." @Success 201 {object} common.APIResponse{data=models.Stub} "The subscription has been created successfully." @Failure 400 {object} common.APIResponse{data=models.Stub} "Invalid data input." @Failure 401 {object} common.APIResponse{data=models.Stub} "User unauthorized.." @Failure 409 {object} common.APIResponse{data=models.Stub} "Conflict: a subscription for such device already exists." @Failure 429 {object} common.APIResponse{data=models.Stub} "Too many requests, try again later." @Failure 500 {object} common.APIResponse{data=models.Stub} "A serious internal server problem occurred." @Router /push/subscriptions [post]
func (*PushController) Delete ¶ added in v0.45.27
func (c *PushController) Delete(w http.ResponseWriter, r *http.Request)
Delete is the handler function to ensure a given subscription deleted from the database.
@Summary Delete a subscription @Description This function call takes an UUID as parameter to fetch and purge a device associated with such ID from the subscribed devices list. @Tags push @Produce json @Param uuid path string true "An UUID of a device to delete." @Success 200 {object} common.APIResponse{data=models.Stub} "Requested device has been purged from the subscribed devices list." @Failure 400 {object} common.APIResponse{data=models.Stub} "Invalid data input." @Failure 401 {object} common.APIResponse{data=models.Stub} "User unauthorized." @Failure 404 {object} common.APIResponse{data=models.Stub} "The requested device to delete not found." @Failure 429 {object} common.APIResponse{data=models.Stub} "Too many requests, try again later." @Failure 500 {object} common.APIResponse{data=models.Stub} "A serious internal problem occurred while processing the delete request." @Router /push/subscriptions/{uuid} [delete]
func (*PushController) SendNotification ¶ added in v0.45.27
func (c *PushController) SendNotification(w http.ResponseWriter, r *http.Request)
SendNotification is the handler function for sending new notification(s).
@Summary Send a notification @Description This function call handles the procedure of a new webpush notification creation and firing. @Tags push @Produce json @Param request body push.NotificationRequest true "An original post which is to fire a notification to its author." @Success 200 {object} common.APIResponse{data=models.Stub} "The notification has been created and sent to the webpush gateway." @Success 400 {object} common.APIResponse{data=models.Stub} "Invalid data input." @Failure 401 {object} common.APIResponse{data=models.Stub} "User unauthorized." @Failure 404 {object} common.APIResponse{data=models.Stub} "The requested device to use not found." @Failure 429 {object} common.APIResponse{data=models.Stub} "Too many requests, try again later." @Failure 500 {object} common.APIResponse{data=models.Stub} "A serious internal problem occurred while preparing the notification for firing." @Router /push [post]
func (*PushController) Update ¶ added in v0.45.27
func (c *PushController) Update(w http.ResponseWriter, r *http.Request)
Update is the handler function used to update an existing subscription.
@Summary Update the notification subscription tag @Description This function call handles a request to change an user's (caller's) notifications subscription for a device specified by UUID param. @Tags push @Accept json @Produce json @Param uuid path string true "An UUID of a device to update." @Param request body push.SubscriptionUpdateRequest true "The request's body containing fields to modify." @Success 200 {object} common.APIResponse{data=models.Stub} "The subscription has been updated successfully." @Failure 400 {object} common.APIResponse{data=models.Stub} "Invalid input data." @Failure 401 {object} common.APIResponse{data=models.Stub} "User unauthorized." @Failure 404 {object} common.APIResponse{data=models.Stub} "The requested device to update not found." @Failure 429 {object} common.APIResponse{data=models.Stub} "Too many requests, try again later." @Failure 500 {object} common.APIResponse{data=models.Stub} "A serious internal problem occurred while the update procedure was processing the data." @Router /push/subscriptions/{uuid} [patch]
type SubscriptionRepository ¶ added in v0.44.32
type SubscriptionRepository struct {
// contains filtered or unexported fields
}
The implementation of pkg/models.SubscriptionRepositoryInterface.
func (*SubscriptionRepository) Delete ¶ added in v0.44.32
func (r *SubscriptionRepository) Delete(userID string) error
func (*SubscriptionRepository) GetByUserID ¶ added in v0.45.27
func (r *SubscriptionRepository) GetByUserID(userID string) (*[]models.Device, error)
type SubscriptionService ¶ added in v0.45.27
type SubscriptionService struct {
// contains filtered or unexported fields
}
func NewSubscriptionService ¶ added in v0.45.27
func NewSubscriptionService( postRepository models.PostRepositoryInterface, subscriptionRepository models.SubscriptionRepositoryInterface, ) *SubscriptionService
func (*SubscriptionService) Delete ¶ added in v0.45.27
func (s *SubscriptionService) Delete(ctx context.Context, uuid string) error
func (*SubscriptionService) SendNotification ¶ added in v0.45.27
func (s *SubscriptionService) SendNotification(ctx context.Context, postID string) error
type SubscriptionUpdateRequest ¶ added in v0.45.27
type SubscriptionUpdateRequest struct {
Tags []string `json:"tags" example:"reply,mention"`
}
Click to show internal directories.
Click to hide internal directories.