Skip to content

Commit

Permalink
feat(model): add url model
Browse files Browse the repository at this point in the history
  • Loading branch information
adhocore committed Oct 2, 2020
1 parent 88b5ecd commit dda5a92
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions model/url.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package model

import (
"time"

"github.com/adhocore/urlsh/common"
)

type Url struct {
ID uint `json:"-" gorm:"primaryKey"`
ShortCode string `json:"short_code" gorm:"size:12;uniqueIndex;not null"`
OriginUrl string `json:"origin_url" gorm:"size:2048;index;not null"`
Hits uint `json:"hits" gorm:"default:0;not null"`
Deleted bool `json:"is_deleted" gorm:"default:false;not null"`
CreatedAt time.Time `json:"-" gorm:"not null"`
UpdatedAt time.Time `json:"-" gorm:"not null"`
ExpiresOn time.Time `json:"expires_on"`
Keywords []Keyword `json:"-" gorm:"many2many:url_keywords"`
}

func (urlModel Url) IsActive() bool {
if urlModel.Deleted {
return false
}

return urlModel.ExpiresOn.In(common.UTC).After(time.Now().In(common.UTC))
}

0 comments on commit dda5a92

Please sign in to comment.