74 lines
1.9 KiB
Go
74 lines
1.9 KiB
Go
package notification
|
|
|
|
import (
|
|
"jannex/admin-dashboard-backend/modules/notification"
|
|
"jannex/admin-dashboard-backend/modules/structs"
|
|
"jannex/admin-dashboard-backend/modules/utils"
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
)
|
|
|
|
func AddNotification(c *fiber.Ctx) error {
|
|
// swagger:operation POST /notifications notifications notificationsAddNotification
|
|
// ---
|
|
// summary: Add a new notification
|
|
// consumes:
|
|
// - application/json
|
|
// produces:
|
|
// - application/json
|
|
// parameters:
|
|
// - name: X-Api-Key
|
|
// in: header
|
|
// description: You can create a new api key in your user profile
|
|
// - name: body
|
|
// in: body
|
|
// schema:
|
|
// "$ref": "#/definitions/AddNotificationRequest"
|
|
// responses:
|
|
// '200':
|
|
// description: New notification added successfully
|
|
// '400':
|
|
// description: Invalid request body
|
|
// '401':
|
|
// description: No permissions
|
|
// '422':
|
|
// description: No users found
|
|
// '500':
|
|
// description: Failed to add notification
|
|
|
|
var body structs.AddNotificationRequest
|
|
|
|
if err := utils.BodyParserHelper(c, &body); err != nil {
|
|
return c.SendStatus(fiber.StatusBadRequest)
|
|
}
|
|
|
|
return notification.AddNotification(c, body)
|
|
}
|
|
|
|
func GetNotifications(c *fiber.Ctx) error {
|
|
// swagger:operation GET /notifications notifications notificationsGetNotifications
|
|
// ---
|
|
// summary: Get notifications
|
|
// consumes:
|
|
// - application/json
|
|
// produces:
|
|
// - application/json
|
|
// parameters:
|
|
// - name: X-Api-Key
|
|
// in: header
|
|
// description: You can create a new api key in your user profile
|
|
// responses:
|
|
// '200':
|
|
// description: Notifications
|
|
// schema:
|
|
// "$ref": "#/definitions/NotificationsResponse"
|
|
// '401':
|
|
// description: No permissions
|
|
// '500':
|
|
// description: Failed to get notifications
|
|
|
|
return c.JSON(structs.NotificationsResponse{
|
|
Notifications: notification.GetNotifications(c.Locals("userId").(string)),
|
|
})
|
|
}
|