feat: use db

This commit is contained in:
Rogee
2024-09-02 18:01:38 +08:00
parent 472fe2ffaf
commit 98cd1a0365
18 changed files with 477 additions and 136 deletions

View File

@@ -1,11 +1,16 @@
package internal
import "fmt"
import (
"encoding/json"
"fmt"
"time"
)
type ChannelMessage struct {
ID int
Message string
Medias []ChannelMessageMedia
ID int
Message string
Medias []ChannelMessageMedia
PublishAt time.Time
}
type ChannelMessageMedia struct {
@@ -13,8 +18,8 @@ type ChannelMessageMedia struct {
Video string
}
func NewChannelMessage(id int) *ChannelMessage {
return &ChannelMessage{ID: id}
func NewChannelMessage(id, ts int) *ChannelMessage {
return &ChannelMessage{ID: id, PublishAt: time.Unix(int64(ts), 0)}
}
func (c *ChannelMessage) WithMessage(message string) *ChannelMessage {
@@ -31,3 +36,8 @@ func (c *ChannelMessage) WithVideo(video string) *ChannelMessage {
c.Medias = append(c.Medias, ChannelMessageMedia{Video: video})
return c
}
func (c *ChannelMessage) GetMedia() string {
b, _ := json.Marshal(c.Medias)
return string(b)
}