-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
} |