From 248d1cf11726a4faea691c1da0ef88f0897a50d4 Mon Sep 17 00:00:00 2001 From: Aykhan Shahsuvarov Date: Wed, 28 Feb 2024 17:51:27 +0400 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20count=20increment=20and=20sav?= =?UTF-8?q?e=20in=20GetURL=20method?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/db/postgres.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/db/postgres.go b/app/db/postgres.go index eb97198..321d644 100644 --- a/app/db/postgres.go +++ b/app/db/postgres.go @@ -1,7 +1,6 @@ package db import ( - // "github.com/aykhans/oh-my-url/app/config" "gorm.io/gorm" ) @@ -13,6 +12,7 @@ type url struct { ID uint `gorm:"primaryKey"` Key string `gorm:"unique;not null;size:15;default:null"` URL string `gorm:"not null;default:null"` + Count int `gorm:"not null;default:0"` } func (p *Postgres) Init() { @@ -41,6 +41,8 @@ func (p *Postgres) GetURL(key string) (string, error) { if tx.Error != nil { return "", tx.Error } + result.Count++ + p.gormDB.Save(&result) return result.URL, nil }