Skip to content
113 changes: 103 additions & 10 deletions generated/api.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 49 additions & 19 deletions internal/database/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,66 @@ import (
)

type Notification struct {
ID string `gorm:"type:text;primaryKey"`
Title string `gorm:"type:text;not null"`
Message string `gorm:"type:text;not null"`
URL *string `gorm:"type:text"`
ID string `gorm:"type:text;primaryKey"`

Title string `gorm:"type:text;not null"`
Body string `gorm:"type:text;not null"`
ImageURL *string `gorm:"type:text"`
AnalyticsLabel *string `gorm:"type:text"`
APNsBadge *int `gorm:"type:integer"`
APNsSound *string `gorm:"type:text"`
APNsContentAvailable *bool `gorm:"type:boolean"`
AndroidChannelID *string `gorm:"type:text"`
AndroidPriority *string `gorm:"type:text"`
AndroidTTLSeconds *int `gorm:"type:integer"`
WebpushLink *string `gorm:"type:text"`

URL *string `gorm:"type:text"`

NotifyAfter time.Time `gorm:"type:timestamptz;not null;index"`
NotifyBefore time.Time `gorm:"type:timestamptz;not null;index"`
IsNotified bool `gorm:"type:boolean;not null;default:false;index"`
}

func (n *Notification) ToDomain(targetUserIDs []string) domain.Notification {
return domain.Notification{
ID: n.ID,
Title: n.Title,
Message: n.Message,
URL: n.URL,
NotifyAfter: n.NotifyAfter,
NotifyBefore: n.NotifyBefore,
IsNotified: n.IsNotified,
TargetUserIDs: targetUserIDs,
ID: n.ID,
Title: n.Title,
Body: n.Body,
ImageURL: n.ImageURL,
AnalyticsLabel: n.AnalyticsLabel,
APNsBadge: n.APNsBadge,
APNsSound: n.APNsSound,
APNsContentAvailable: n.APNsContentAvailable,
AndroidChannelID: n.AndroidChannelID,
AndroidPriority: n.AndroidPriority,
AndroidTTLSeconds: n.AndroidTTLSeconds,
WebpushLink: n.WebpushLink,
URL: n.URL,
NotifyAfter: n.NotifyAfter,
NotifyBefore: n.NotifyBefore,
IsNotified: n.IsNotified,
TargetUserIDs: targetUserIDs,
}
}

func NotificationFromDomain(n domain.Notification) Notification {
return Notification{
ID: n.ID,
Title: n.Title,
Message: n.Message,
URL: n.URL,
NotifyAfter: n.NotifyAfter,
NotifyBefore: n.NotifyBefore,
IsNotified: n.IsNotified,
ID: n.ID,
Title: n.Title,
Body: n.Body,
ImageURL: n.ImageURL,
AnalyticsLabel: n.AnalyticsLabel,
APNsBadge: n.APNsBadge,
APNsSound: n.APNsSound,
APNsContentAvailable: n.APNsContentAvailable,
AndroidChannelID: n.AndroidChannelID,
AndroidPriority: n.AndroidPriority,
AndroidTTLSeconds: n.AndroidTTLSeconds,
WebpushLink: n.WebpushLink,
URL: n.URL,
NotifyAfter: n.NotifyAfter,
NotifyBefore: n.NotifyBefore,
IsNotified: n.IsNotified,
}
}
27 changes: 20 additions & 7 deletions internal/domain/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,25 @@ package domain
import "time"

type Notification struct {
ID string
Title string
Message string
URL *string
NotifyAfter time.Time
NotifyBefore time.Time
IsNotified bool
ID string

Title string
Body string
ImageURL *string
AnalyticsLabel *string
APNsBadge *int
APNsSound *string
APNsContentAvailable *bool
AndroidChannelID *string
AndroidPriority *string
AndroidTTLSeconds *int
WebpushLink *string

URL *string

NotifyAfter time.Time
NotifyBefore time.Time
IsNotified bool

TargetUserIDs []string
}
74 changes: 55 additions & 19 deletions internal/handler/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,34 @@ func toDomainFCMToken(req api.FCMTokenRequest) domain.FCMToken {
}

func toAPINotification(n domain.Notification) api.Notification {
return api.Notification{
Id: n.ID,
Title: n.Title,
Message: n.Message,
Url: n.URL,
NotifyAfter: n.NotifyAfter,
NotifyBefore: n.NotifyBefore,
IsNotified: n.IsNotified,
TargetUserIds: n.TargetUserIDs,
}
notification := api.Notification{
Id: n.ID,
Title: n.Title,
Body: n.Body,
ImageUrl: n.ImageURL,
AnalyticsLabel: n.AnalyticsLabel,
ApnsSound: n.APNsSound,
ApnsContentAvailable: n.APNsContentAvailable,
AndroidChannelId: n.AndroidChannelID,
AndroidPriority: n.AndroidPriority,
WebpushLink: n.WebpushLink,
Url: n.URL,
NotifyAfter: n.NotifyAfter,
NotifyBefore: n.NotifyBefore,
IsNotified: n.IsNotified,
TargetUserIds: n.TargetUserIDs,
}

if n.APNsBadge != nil {
badge := int32(*n.APNsBadge)
notification.ApnsBadge = &badge
}
if n.AndroidTTLSeconds != nil {
ttl := int32(*n.AndroidTTLSeconds)
notification.AndroidTtlSeconds = &ttl
}

return notification
}

func toAPINotifications(notifications []domain.Notification) []api.Notification {
Expand All @@ -103,15 +121,33 @@ func toAPINotifications(notifications []domain.Notification) []api.Notification
}

func toDomainNotification(id string, req api.NotificationRequest) domain.Notification {
return domain.Notification{
ID: id,
Title: req.Title,
Message: req.Message,
URL: req.Url,
NotifyAfter: req.NotifyAfter,
NotifyBefore: req.NotifyBefore,
TargetUserIDs: req.TargetUserIds,
}
notification := domain.Notification{
ID: id,
Title: req.Title,
Body: req.Body,
ImageURL: req.ImageUrl,
AnalyticsLabel: req.AnalyticsLabel,
APNsSound: req.ApnsSound,
APNsContentAvailable: req.ApnsContentAvailable,
AndroidChannelID: req.AndroidChannelId,
AndroidPriority: req.AndroidPriority,
WebpushLink: req.WebpushLink,
URL: req.Url,
NotifyAfter: req.NotifyAfter,
NotifyBefore: req.NotifyBefore,
TargetUserIDs: req.TargetUserIds,
}

if req.ApnsBadge != nil {
badge := int(*req.ApnsBadge)
notification.APNsBadge = &badge
}
if req.AndroidTtlSeconds != nil {
ttl := int(*req.AndroidTtlSeconds)
notification.AndroidTTLSeconds = &ttl
}

return notification
}

func toDomainNotificationListFilter(params api.NotificationV1ListParams) domain.NotificationListFilter {
Expand Down
Loading