diff --git a/internal/db/models.go b/internal/db/models.go index 1be0b03..c96f8eb 100644 --- a/internal/db/models.go +++ b/internal/db/models.go @@ -1,15 +1,20 @@ package db -import "github.com/scylladb/gocqlx/v2/table" +import ( + "time" + + "github.com/scylladb/gocqlx/v2/table" +) var UrlTable = table.New(table.Metadata{ Name: "fivefeeteleven.urls", - Columns: []string{"id", "long_url"}, + Columns: []string{"id", "long_url", "created_at"}, PartKey: []string{"id"}, SortKey: []string{}, }) type UrlModel struct { - ID string - LongUrl string + ID string + LongUrl string + CreatedAt time.Time } diff --git a/internal/db/seed.go b/internal/db/seed.go index b77d7bb..0136603 100644 --- a/internal/db/seed.go +++ b/internal/db/seed.go @@ -15,7 +15,8 @@ func Seed(session gocqlx.Session) error { err = session.ExecStmt(` CREATE TABLE IF NOT EXISTS fivefeeteleven.urls ( id text PRIMARY KEY, - long_url text + long_url text, + created_at timestamp )`) if err != nil { diff --git a/internal/logic/shortenurllogic.go b/internal/logic/shortenurllogic.go index ab9b549..2d144cd 100644 --- a/internal/logic/shortenurllogic.go +++ b/internal/logic/shortenurllogic.go @@ -36,8 +36,9 @@ func (l *ShortenUrlLogic) ShortenUrl(req *types.ShortenReq) (resp *types.Shorten insertUrl := insertBuilder.Query(l.svcCtx.DB) insertUrl.BindStruct(db.UrlModel{ - ID: id, - LongUrl: req.LongUrl, + ID: id, + LongUrl: req.LongUrl, + CreatedAt: time.Now(), }) if err := insertUrl.ExecRelease(); err != nil {