Compare commits

..

No commits in common. "b547b404106b47b7c5b4ca3fffb3d7028e2b829d" and "a9146fb6ab1a6d3d6e4712dc4e10146aa8a67b48" have entirely different histories.

9 changed files with 45 additions and 46 deletions

View File

@ -1,10 +1,9 @@
package models package models
import ( import (
"time"
gonanoid "github.com/matoous/go-nanoid/v2" gonanoid "github.com/matoous/go-nanoid/v2"
"gorm.io/gorm" "gorm.io/gorm"
"time"
) )
type ID interface { type ID interface {
@ -12,10 +11,10 @@ type ID interface {
} }
type BaseModel[T ID] struct { type BaseModel[T ID] struct {
ID T `json:"id" gorm:"primaryKey"` ID T `gorm:"primaryKey"`
CreatedAt time.Time `json:"-"` CreatedAt time.Time
UpdatedAt time.Time `json:"-"` UpdatedAt time.Time
DeletedAt gorm.DeletedAt `json:"-" gorm:"index"` DeletedAt gorm.DeletedAt `gorm:"index"`
} }
func (base *BaseModel[T]) BeforeCreate(db *gorm.DB) error { func (base *BaseModel[T]) BeforeCreate(db *gorm.DB) error {

View File

@ -3,10 +3,10 @@ package models
// Post model // Post model
type Post struct { type Post struct {
BaseModel[AnthrovePostID] BaseModel[AnthrovePostID]
Rating Rating `json:"rating" gorm:"type:enum('safe','questionable','explicit')"` Rating Rating `gorm:"type:enum('safe','questionable','explicit')"`
Tags []Tag `json:"tags" gorm:"many2many:post_tags;"` Tags []Tag `gorm:"many2many:post_tags;"`
Favorites []UserFavorites `json:"-" gorm:"foreignKey:PostID"` Favorites []UserFavorites `gorm:"foreignKey:PostID"`
References []PostReference `json:"-" gorm:"foreignKey:PostID"` References []PostReference `gorm:"foreignKey:PostID"`
} }
func (Post) TableName() string { func (Post) TableName() string {

View File

@ -1,17 +1,17 @@
package models package models
type PostReference struct { type PostReference struct {
PostID string `json:"post_id" gorm:"primaryKey"` PostID string `gorm:"primaryKey"`
SourceID string `json:"source_id" gorm:"primaryKey"` SourceID string `gorm:"primaryKey"`
URL string `json:"url" gorm:"primaryKey"` URL string `gorm:"primaryKey"`
PostReferenceConfig PostReferenceConfig
} }
type PostReferenceConfig struct { type PostReferenceConfig struct {
SourcePostID string `json:"source_post_id"` SourcePostID string
FullFileURL string `json:"full_file_url"` FullFileURL string
PreviewFileURL string `json:"preview_file_url"` PreviewFileURL string
SampleFileURL string `json:"sample_file_url"` SampleFileURL string
} }
func (PostReference) TableName() string { func (PostReference) TableName() string {

View File

@ -3,11 +3,11 @@ package models
// Source model // Source model
type Source struct { type Source struct {
BaseModel[AnthroveSourceID] BaseModel[AnthroveSourceID]
DisplayName string `json:"display_name" ` DisplayName string
Domain string `json:"domain" gorm:"not null;unique"` Domain string `gorm:"not null;unique"`
Icon string `json:"icon" gorm:"not null"` Icon string `gorm:"not null"`
UserSources []UserSource `json:"-" gorm:"foreignKey:SourceID"` UserSources []UserSource `gorm:"foreignKey:SourceID"`
References []PostReference `json:"references" gorm:"foreignKey:SourceID"` References []PostReference `gorm:"foreignKey:SourceID"`
} }
func (Source) TableName() string { func (Source) TableName() string {

View File

@ -2,11 +2,11 @@ package models
// Tag models // Tag models
type Tag struct { type Tag struct {
Name string `json:"name" gorm:"primaryKey"` Name string `gorm:"primaryKey"`
Type TagType `json:"type" gorm:"column:tag_type"` Type TagType `gorm:"column:tag_type"`
Aliases []TagAlias `json:"aliases" gorm:"foreignKey:TagID"` Aliases []TagAlias `gorm:"foreignKey:TagID"`
Groups []TagGroup `json:"groups" gorm:"foreignKey:TagID"` Groups []TagGroup `gorm:"foreignKey:TagID"`
Posts []Post `json:"posts" gorm:"many2many:post_tags;"` Posts []Post `gorm:"many2many:post_tags;"`
} }
func (Tag) TableName() string { func (Tag) TableName() string {
@ -15,8 +15,8 @@ func (Tag) TableName() string {
// TagAlias model // TagAlias model
type TagAlias struct { type TagAlias struct {
Name string `json:"name" gorm:"primaryKey"` Name string `gorm:"primaryKey"`
TagID string `json:"tag_id"` TagID string
} }
func (TagAlias) TableName() string { func (TagAlias) TableName() string {
@ -25,8 +25,8 @@ func (TagAlias) TableName() string {
// TagGroup model // TagGroup model
type TagGroup struct { type TagGroup struct {
Name string `json:"name" gorm:"primaryKey"` Name string `gorm:"primaryKey"`
TagID string `json:"tag_id"` TagID string
} }
func (TagGroup) TableName() string { func (TagGroup) TableName() string {

View File

@ -3,8 +3,8 @@ package models
// User model // User model
type User struct { type User struct {
BaseModel[AnthroveUserID] BaseModel[AnthroveUserID]
Favorites []UserFavorites `json:"-" gorm:"foreignKey:UserID"` Favorites []UserFavorites `gorm:"foreignKey:UserID"`
Sources []UserSource `json:"-" gorm:"foreignKey:UserID"` Sources []UserSource `gorm:"foreignKey:UserID"`
} }
func (User) TableName() string { func (User) TableName() string {

View File

@ -3,9 +3,9 @@ package models
import "time" import "time"
type UserFavorites struct { type UserFavorites struct {
UserID string `json:"user_id" gorm:"primaryKey"` UserID string `gorm:"primaryKey"`
PostID string `json:"post_id" gorm:"primaryKey"` PostID string `gorm:"primaryKey"`
CreatedAt time.Time `json:"-"` CreatedAt time.Time
} }
func (UserFavorites) TableName() string { func (UserFavorites) TableName() string {

View File

@ -3,16 +3,16 @@ package models
import "time" import "time"
type UserSource struct { type UserSource struct {
User User `json:"user" gorm:"foreignKey:ID;references:UserID"` User User `gorm:"foreignKey:ID;references:UserID"`
UserID string `json:"user_id" gorm:"primaryKey"` UserID string `gorm:"primaryKey"`
Source Source `json:"source" gorm:"foreignKey:ID;references:SourceID"` Source Source `gorm:"foreignKey:ID;references:SourceID"`
SourceID string `json:"source_id" gorm:"primaryKey"` SourceID string `gorm:"primaryKey"`
ScrapeTimeInterval string `json:"scrape_time_interval"` ScrapeTimeInterval string
AccountUsername string `json:"account_username"` AccountUsername string
AccountID string `json:"account_id"` AccountID string
LastScrapeTime time.Time `json:"last_scrape_time"` LastScrapeTime time.Time
AccountValidate bool `json:"account_validate"` AccountValidate bool
AccountValidationKey string `json:"-"` AccountValidationKey string
} }
func (UserSource) TableName() string { func (UserSource) TableName() string {