mirror of
https://github.com/aykhans/oh-my-url.git
synced 2025-04-17 02:23:13 +00:00
✨ Add count increment and save in GetURL method
This commit is contained in:
parent
7a771dba79
commit
248d1cf117
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user