mirror of
https://github.com/aykhans/oh-my-url.git
synced 2025-04-20 19:33:06 +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
|
package db
|
||||||
|
|
||||||
import (
|
import (
|
||||||
// "github.com/aykhans/oh-my-url/app/config"
|
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -13,6 +12,7 @@ type url struct {
|
|||||||
ID uint `gorm:"primaryKey"`
|
ID uint `gorm:"primaryKey"`
|
||||||
Key string `gorm:"unique;not null;size:15;default:null"`
|
Key string `gorm:"unique;not null;size:15;default:null"`
|
||||||
URL string `gorm:"not null;default:null"`
|
URL string `gorm:"not null;default:null"`
|
||||||
|
Count int `gorm:"not null;default:0"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Postgres) Init() {
|
func (p *Postgres) Init() {
|
||||||
@ -41,6 +41,8 @@ func (p *Postgres) GetURL(key string) (string, error) {
|
|||||||
if tx.Error != nil {
|
if tx.Error != nil {
|
||||||
return "", tx.Error
|
return "", tx.Error
|
||||||
}
|
}
|
||||||
|
result.Count++
|
||||||
|
p.gormDB.Save(&result)
|
||||||
return result.URL, nil
|
return result.URL, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user