9037cb5917
- Updated the notification handling logic to utilize a new SDK for sending notifications, improving the flexibility and scalability of the notification system. - Introduced new methods in the notification service for sending notifications to users and customers based on various target audience types, enhancing the notification delivery capabilities. - Added a new endpoint to assign companies to a customer, improving customer management functionalities. - Refactored the customer entity and forms to replace 'CompanyIDs' with 'Companies', ensuring consistency across the data model. - Enhanced API documentation with Swagger comments for the new endpoint and updated notification structures, ensuring clarity for API consumers.
54 lines
1.6 KiB
Go
54 lines
1.6 KiB
Go
package notification
|
|
|
|
import (
|
|
"github.com/asaskevich/govalidator"
|
|
"github.com/labstack/echo/v4"
|
|
|
|
"tm/pkg/logger"
|
|
"tm/pkg/response"
|
|
)
|
|
|
|
// NotificationHandler handles HTTP requests for notification operations
|
|
type NotificationHandler struct {
|
|
service Service
|
|
logger logger.Logger
|
|
}
|
|
|
|
// NewNotificationHandler creates a new notification handler
|
|
func NewHandler(service Service, logger logger.Logger) *NotificationHandler {
|
|
return &NotificationHandler{
|
|
service: service,
|
|
logger: logger,
|
|
}
|
|
}
|
|
|
|
// CreateNotification creates a new notification
|
|
// @Summary Create a new notification
|
|
// @Description Create a new notification with the provided information
|
|
// @Tags Admin-Notification
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param notification body NotificationRequest true "Notification information"
|
|
// @Success 201 {object} response.APIResponse "Notification created successfully"
|
|
// @Failure 400 {object} response.APIResponse
|
|
// @Failure 500 {object} response.APIResponse
|
|
// @Router /admin/v1/notifications [post]
|
|
func (h *NotificationHandler) Send(c echo.Context) error {
|
|
var req NotificationRequest
|
|
if err := c.Bind(&req); err != nil {
|
|
return response.BadRequest(c, "Invalid request format", err.Error())
|
|
}
|
|
|
|
// Validate request
|
|
if valid, err := govalidator.ValidateStruct(req); !valid {
|
|
return response.ValidationError(c, "Validation failed", err.Error())
|
|
}
|
|
|
|
// Send notification
|
|
if err := h.service.Send(c.Request().Context(), &req); err != nil {
|
|
return response.InternalServerError(c, "Failed to send notification")
|
|
}
|
|
|
|
return response.Created(c, nil, "Notification sent successfully")
|
|
}
|