admin-dashboard-backend/routers/router/api/v1/notification/notification.go

89 lines
2.2 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
// - name: page
// in: query
// description: Page number
// responses:
// '200':
// description: Notifications
// schema:
// "$ref": "#/definitions/NotificationsResponse"
// '401':
// description: No permissions
// '500':
// description: Failed to get notifications
var query structs.PageQuery
if err := utils.QueryParserHelper(c, &query); err != nil {
return c.SendStatus(fiber.StatusBadRequest)
}
userId := c.Locals("userId").(string)
return c.JSON(structs.NotificationsResponse{
Notifications: notification.GetNotifications(query, userId),
TotalPages: utils.GetTotalPages(utils.NotificationsPaginationLimit,
[]structs.Notification{},
"user_id = ?",
userId),
})
}