Enha: db chat management

This commit is contained in:
Grail Finder
2024-11-20 06:51:40 +03:00
parent f32375488f
commit aaf0566636
6 changed files with 127 additions and 96 deletions

View File

@@ -1,6 +1,9 @@
package models
import "time"
import (
"encoding/json"
"time"
)
type Chat struct {
ID uint32 `db:"id" json:"id"`
@@ -9,3 +12,11 @@ type Chat struct {
CreatedAt time.Time `db:"created_at" json:"created_at"`
UpdatedAt time.Time `db:"updated_at" json:"updated_at"`
}
func (c Chat) ToHistory() ([]MessagesStory, error) {
resp := []MessagesStory{}
if err := json.Unmarshal([]byte(c.Msgs), &resp); err != nil {
return nil, err
}
return resp, nil
}