diff --git a/pkg/models/pgModels/post.go b/pkg/models/pgModels/post.go index a4cf61a..1ba9262 100644 --- a/pkg/models/pgModels/post.go +++ b/pkg/models/pgModels/post.go @@ -7,8 +7,11 @@ import ( // Post model type Post struct { BaseModel - Rating models.Rating `gorm:"type:rating"` - Body string `gorm:"type:text"` - UserID int `gorm:"index"` - Status string `gorm:"type:post_status"` + Rating models.Rating `gorm:"type:enum('safe','questionable','explicit')"` + Body string `gorm:"type:text"` + UserID int + Status string + Tags []Tag `gorm:"many2many:post_tags;"` + Favorites []UserFavorite `gorm:"foreignKey:PostID"` + References []PostReference `gorm:"foreignKey:PostID"` } diff --git a/pkg/models/pgModels/postReference.go b/pkg/models/pgModels/postReference.go new file mode 100644 index 0000000..ae4574c --- /dev/null +++ b/pkg/models/pgModels/postReference.go @@ -0,0 +1,8 @@ +package pgModels + +type PostReference struct { + PostID string `gorm:"primaryKey"` + SourceID string `gorm:"primaryKey"` + URL string `gorm:"not null;unique"` + SourcePostID string +} diff --git a/pkg/models/pgModels/source.go b/pkg/models/pgModels/source.go index 73e2535..22c727f 100644 --- a/pkg/models/pgModels/source.go +++ b/pkg/models/pgModels/source.go @@ -3,6 +3,8 @@ package pgModels // Source model type Source struct { BaseModel - DisplayName string `gorm:"type:text"` - Domain string `gorm:"type:text;not null;unique"` + DisplayName string + Domain string `gorm:"not null;unique"` + UserSources []UserSource `gorm:"foreignKey:SourceID"` + References []PostReference `gorm:"foreignKey:SourceID"` } diff --git a/pkg/models/pgModels/tag.go b/pkg/models/pgModels/tag.go index 4c246a1..406f744 100644 --- a/pkg/models/pgModels/tag.go +++ b/pkg/models/pgModels/tag.go @@ -4,18 +4,21 @@ import "git.dragse.it/anthrove/otter-space-sdk/pkg/models" // Tag models type Tag struct { - Name string `gorm:"primaryKey"` - Type models.TagType `gorm:"type:tag_type"` + Name string `gorm:"primaryKey"` + Type models.TagType + Aliases []TagAlias `gorm:"foreignKey:TagID"` + Groups []TagGroup `gorm:"foreignKey:TagID"` + Posts []Post `gorm:"many2many:post_tags;"` } // TagAlias model type TagAlias struct { Name string `gorm:"primaryKey"` - TagID string `gorm:"index"` + TagID string } // TagGroup model type TagGroup struct { Name string `gorm:"primaryKey"` - TagID string `gorm:"index"` + TagID string } diff --git a/pkg/models/pgModels/user.go b/pkg/models/pgModels/user.go index be072d8..7fe7e73 100644 --- a/pkg/models/pgModels/user.go +++ b/pkg/models/pgModels/user.go @@ -3,4 +3,6 @@ package pgModels // User model type User struct { BaseModel + Favorites []UserFavorite `gorm:"foreignKey:UserID"` + Sources []UserSource `gorm:"foreignKey:UserID"` } diff --git a/pkg/models/pgModels/userFavorite.go b/pkg/models/pgModels/userFavorite.go new file mode 100644 index 0000000..2e194a3 --- /dev/null +++ b/pkg/models/pgModels/userFavorite.go @@ -0,0 +1,9 @@ +package pgModels + +import "time" + +type UserFavorite struct { + UserID string `gorm:"primaryKey"` + PostID string `gorm:"primaryKey"` + CreatedAt time.Time +} diff --git a/pkg/models/pgModels/userSource.go b/pkg/models/pgModels/userSource.go new file mode 100644 index 0000000..7319994 --- /dev/null +++ b/pkg/models/pgModels/userSource.go @@ -0,0 +1,8 @@ +package pgModels + +type UserSource struct { + UserID string `gorm:"primaryKey"` + SourceID string `gorm:"primaryKey"` + AccountUsername string + AccountID string +}