31 lines
611 B
Go
31 lines
611 B
Go
package domain
|
|
|
|
import (
|
|
"encoding/json"
|
|
"time"
|
|
)
|
|
|
|
type Chat struct {
|
|
ID string `json:"id"`
|
|
Title string `json:"title"`
|
|
MemberIDs []string `json:"member_ids"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
}
|
|
|
|
func (c Chat) MarshalJSON() ([]byte, error) {
|
|
type Alias Chat
|
|
members := c.MemberIDs
|
|
if members == nil {
|
|
members = []string{}
|
|
}
|
|
return json.Marshal(&struct {
|
|
Alias
|
|
MemberIDs []string `json:"member_ids"`
|
|
CreatedAt string `json:"created_at"`
|
|
}{
|
|
Alias: Alias(c),
|
|
MemberIDs: members,
|
|
CreatedAt: c.CreatedAt.UTC().Truncate(time.Second).Format(time.RFC3339),
|
|
})
|
|
}
|