From aaf056663628f15bb6e4f23c899b6fd31bac5bf7 Mon Sep 17 00:00:00 2001 From: Grail Finder Date: Wed, 20 Nov 2024 06:51:40 +0300 Subject: Enha: db chat management --- models/db.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'models') diff --git a/models/db.go b/models/db.go index 24bef41..afd4b46 100644 --- a/models/db.go +++ b/models/db.go @@ -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 +} -- cgit v1.2.3