feat: added json notation
Signed-off-by: SoXX <soxx@fenpa.ws>
This commit is contained in:
parent
a9146fb6ab
commit
251611c5a0
@ -1,9 +1,10 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
gonanoid "github.com/matoous/go-nanoid/v2"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
type ID interface {
|
||||
@ -11,10 +12,10 @@ type ID interface {
|
||||
}
|
||||
|
||||
type BaseModel[T ID] struct {
|
||||
ID T `gorm:"primaryKey"`
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
DeletedAt gorm.DeletedAt `gorm:"index"`
|
||||
ID T `json:"id" gorm:"primaryKey"`
|
||||
CreatedAt time.Time `json:"-"`
|
||||
UpdatedAt time.Time `json:"-"`
|
||||
DeletedAt gorm.DeletedAt `json:"-" gorm:"index"`
|
||||
}
|
||||
|
||||
func (base *BaseModel[T]) BeforeCreate(db *gorm.DB) error {
|
||||
|
@ -3,10 +3,10 @@ package models
|
||||
// Post model
|
||||
type Post struct {
|
||||
BaseModel[AnthrovePostID]
|
||||
Rating Rating `gorm:"type:enum('safe','questionable','explicit')"`
|
||||
Tags []Tag `gorm:"many2many:post_tags;"`
|
||||
Favorites []UserFavorites `gorm:"foreignKey:PostID"`
|
||||
References []PostReference `gorm:"foreignKey:PostID"`
|
||||
Rating Rating `json:"rating" gorm:"type:enum('safe','questionable','explicit')"`
|
||||
Tags []Tag `json:"tags" gorm:"many2many:post_tags;"`
|
||||
Favorites []UserFavorites `json:"-" gorm:"foreignKey:PostID"`
|
||||
References []PostReference `json:"-" gorm:"foreignKey:PostID"`
|
||||
}
|
||||
|
||||
func (Post) TableName() string {
|
||||
|
@ -1,17 +1,17 @@
|
||||
package models
|
||||
|
||||
type PostReference struct {
|
||||
PostID string `gorm:"primaryKey"`
|
||||
SourceID string `gorm:"primaryKey"`
|
||||
URL string `gorm:"primaryKey"`
|
||||
PostID string `json:"post_id" gorm:"primaryKey"`
|
||||
SourceID string `json:"source_id" gorm:"primaryKey"`
|
||||
URL string `json:"url" gorm:"primaryKey"`
|
||||
PostReferenceConfig
|
||||
}
|
||||
|
||||
type PostReferenceConfig struct {
|
||||
SourcePostID string
|
||||
FullFileURL string
|
||||
PreviewFileURL string
|
||||
SampleFileURL string
|
||||
SourcePostID string `json:"source_post_id"`
|
||||
FullFileURL string `json:"full_file_url"`
|
||||
PreviewFileURL string `json:"preview_file_url"`
|
||||
SampleFileURL string `json:"sample_file_url"`
|
||||
}
|
||||
|
||||
func (PostReference) TableName() string {
|
||||
|
@ -3,11 +3,11 @@ package models
|
||||
// Source model
|
||||
type Source struct {
|
||||
BaseModel[AnthroveSourceID]
|
||||
DisplayName string
|
||||
Domain string `gorm:"not null;unique"`
|
||||
Icon string `gorm:"not null"`
|
||||
UserSources []UserSource `gorm:"foreignKey:SourceID"`
|
||||
References []PostReference `gorm:"foreignKey:SourceID"`
|
||||
DisplayName string `json:"display_name" `
|
||||
Domain string `json:"domain" gorm:"not null;unique"`
|
||||
Icon string `json:"icon" gorm:"not null"`
|
||||
UserSources []UserSource `json:"-" gorm:"foreignKey:SourceID"`
|
||||
References []PostReference `json:"references" gorm:"foreignKey:SourceID"`
|
||||
}
|
||||
|
||||
func (Source) TableName() string {
|
||||
|
@ -2,11 +2,11 @@ package models
|
||||
|
||||
// Tag models
|
||||
type Tag struct {
|
||||
Name string `gorm:"primaryKey"`
|
||||
Type TagType `gorm:"column:tag_type"`
|
||||
Aliases []TagAlias `gorm:"foreignKey:TagID"`
|
||||
Groups []TagGroup `gorm:"foreignKey:TagID"`
|
||||
Posts []Post `gorm:"many2many:post_tags;"`
|
||||
Name string `json:"name" gorm:"primaryKey"`
|
||||
Type TagType `json:"type" gorm:"column:tag_type"`
|
||||
Aliases []TagAlias `json:"aliases" gorm:"foreignKey:TagID"`
|
||||
Groups []TagGroup `json:"groups" gorm:"foreignKey:TagID"`
|
||||
Posts []Post `json:"posts" gorm:"many2many:post_tags;"`
|
||||
}
|
||||
|
||||
func (Tag) TableName() string {
|
||||
@ -15,8 +15,8 @@ func (Tag) TableName() string {
|
||||
|
||||
// TagAlias model
|
||||
type TagAlias struct {
|
||||
Name string `gorm:"primaryKey"`
|
||||
TagID string
|
||||
Name string `json:"name" gorm:"primaryKey"`
|
||||
TagID string `json:"tag_id"`
|
||||
}
|
||||
|
||||
func (TagAlias) TableName() string {
|
||||
@ -25,8 +25,8 @@ func (TagAlias) TableName() string {
|
||||
|
||||
// TagGroup model
|
||||
type TagGroup struct {
|
||||
Name string `gorm:"primaryKey"`
|
||||
TagID string
|
||||
Name string `json:"name" gorm:"primaryKey"`
|
||||
TagID string `json:"tag_id"`
|
||||
}
|
||||
|
||||
func (TagGroup) TableName() string {
|
||||
|
@ -3,8 +3,8 @@ package models
|
||||
// User model
|
||||
type User struct {
|
||||
BaseModel[AnthroveUserID]
|
||||
Favorites []UserFavorites `gorm:"foreignKey:UserID"`
|
||||
Sources []UserSource `gorm:"foreignKey:UserID"`
|
||||
Favorites []UserFavorites `json:"-" gorm:"foreignKey:UserID"`
|
||||
Sources []UserSource `json:"-" gorm:"foreignKey:UserID"`
|
||||
}
|
||||
|
||||
func (User) TableName() string {
|
||||
|
@ -3,9 +3,9 @@ package models
|
||||
import "time"
|
||||
|
||||
type UserFavorites struct {
|
||||
UserID string `gorm:"primaryKey"`
|
||||
PostID string `gorm:"primaryKey"`
|
||||
CreatedAt time.Time
|
||||
UserID string `json:"user_id" gorm:"primaryKey"`
|
||||
PostID string `json:"post_id" gorm:"primaryKey"`
|
||||
CreatedAt time.Time `json:"-"`
|
||||
}
|
||||
|
||||
func (UserFavorites) TableName() string {
|
||||
|
@ -3,16 +3,16 @@ package models
|
||||
import "time"
|
||||
|
||||
type UserSource struct {
|
||||
User User `gorm:"foreignKey:ID;references:UserID"`
|
||||
UserID string `gorm:"primaryKey"`
|
||||
Source Source `gorm:"foreignKey:ID;references:SourceID"`
|
||||
SourceID string `gorm:"primaryKey"`
|
||||
ScrapeTimeInterval string
|
||||
AccountUsername string
|
||||
AccountID string
|
||||
LastScrapeTime time.Time
|
||||
AccountValidate bool
|
||||
AccountValidationKey string
|
||||
User User `json:"user" gorm:"foreignKey:ID;references:UserID"`
|
||||
UserID string `json:"user_id" gorm:"primaryKey"`
|
||||
Source Source `json:"source" gorm:"foreignKey:ID;references:SourceID"`
|
||||
SourceID string `json:"source_id" gorm:"primaryKey"`
|
||||
ScrapeTimeInterval string `json:"scrape_time_interval"`
|
||||
AccountUsername string `json:"account_username"`
|
||||
AccountID string `json:"account_id"`
|
||||
LastScrapeTime time.Time `json:"last_scrape_time"`
|
||||
AccountValidate bool `json:"account_validate"`
|
||||
AccountValidationKey string `json:"-"`
|
||||
}
|
||||
|
||||
func (UserSource) TableName() string {
|
||||
|
Reference in New Issue
Block a user