apskel-pos-backend/internal/transformer/notification_transformer.go
2026-05-10 10:57:38 +07:00

64 lines
1.7 KiB
Go

package transformer
import (
"apskel-pos-be/internal/contract"
"apskel-pos-be/internal/models"
)
func NotificationModelResponseToContract(m *models.NotificationResponse) *contract.NotificationResponse {
if m == nil {
return nil
}
return &contract.NotificationResponse{
ID: m.ID,
Title: m.Title,
Body: m.Body,
Type: m.Type,
Category: m.Category,
Priority: m.Priority,
ImageURL: m.ImageURL,
ActionURL: m.ActionURL,
NotifiableType: m.NotifiableType,
NotifiableID: m.NotifiableID,
Data: m.Data,
ScheduledAt: m.ScheduledAt,
SentAt: m.SentAt,
ExpiredAt: m.ExpiredAt,
CreatedBy: m.CreatedBy,
CreatedAt: m.CreatedAt,
UpdatedAt: m.UpdatedAt,
}
}
func NotificationReceiverModelResponseToContract(m *models.NotificationReceiverResponse) *contract.NotificationReceiverResponse {
if m == nil {
return nil
}
resp := &contract.NotificationReceiverResponse{
ID: m.ID,
NotificationID: m.NotificationID,
UserID: m.UserID,
IsRead: m.IsRead,
ReadAt: m.ReadAt,
IsDeleted: m.IsDeleted,
DeletedAt: m.DeletedAt,
CreatedAt: m.CreatedAt,
UpdatedAt: m.UpdatedAt,
}
if m.Notification != nil {
resp.Notification = NotificationModelResponseToContract(m.Notification)
}
return resp
}
func NotificationReceiverModelResponsesToContracts(ms []*models.NotificationReceiverResponse) []*contract.NotificationReceiverResponse {
if ms == nil {
return nil
}
result := make([]*contract.NotificationReceiverResponse, len(ms))
for i, m := range ms {
result[i] = NotificationReceiverModelResponseToContract(m)
}
return result
}