feat(sources): finalized model with gorm annotation

Signed-off-by: SoXX <soxx@fenpa.ws>
This commit is contained in:
SoXX 2024-06-04 08:49:46 +02:00
parent 21b43333d0
commit 5a693063bb
7 changed files with 45 additions and 10 deletions

View File

@ -7,8 +7,11 @@ import (
// Post model // Post model
type Post struct { type Post struct {
BaseModel BaseModel
Rating models.Rating `gorm:"type:rating"` Rating models.Rating `gorm:"type:enum('safe','questionable','explicit')"`
Body string `gorm:"type:text"` Body string `gorm:"type:text"`
UserID int `gorm:"index"` UserID int
Status string `gorm:"type:post_status"` Status string
Tags []Tag `gorm:"many2many:post_tags;"`
Favorites []UserFavorite `gorm:"foreignKey:PostID"`
References []PostReference `gorm:"foreignKey:PostID"`
} }

View File

@ -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
}

View File

@ -3,6 +3,8 @@ package pgModels
// Source model // Source model
type Source struct { type Source struct {
BaseModel BaseModel
DisplayName string `gorm:"type:text"` DisplayName string
Domain string `gorm:"type:text;not null;unique"` Domain string `gorm:"not null;unique"`
UserSources []UserSource `gorm:"foreignKey:SourceID"`
References []PostReference `gorm:"foreignKey:SourceID"`
} }

View File

@ -4,18 +4,21 @@ import "git.dragse.it/anthrove/otter-space-sdk/pkg/models"
// Tag models // Tag models
type Tag struct { type Tag struct {
Name string `gorm:"primaryKey"` Name string `gorm:"primaryKey"`
Type models.TagType `gorm:"type:tag_type"` Type models.TagType
Aliases []TagAlias `gorm:"foreignKey:TagID"`
Groups []TagGroup `gorm:"foreignKey:TagID"`
Posts []Post `gorm:"many2many:post_tags;"`
} }
// TagAlias model // TagAlias model
type TagAlias struct { type TagAlias struct {
Name string `gorm:"primaryKey"` Name string `gorm:"primaryKey"`
TagID string `gorm:"index"` TagID string
} }
// TagGroup model // TagGroup model
type TagGroup struct { type TagGroup struct {
Name string `gorm:"primaryKey"` Name string `gorm:"primaryKey"`
TagID string `gorm:"index"` TagID string
} }

View File

@ -3,4 +3,6 @@ package pgModels
// User model // User model
type User struct { type User struct {
BaseModel BaseModel
Favorites []UserFavorite `gorm:"foreignKey:UserID"`
Sources []UserSource `gorm:"foreignKey:UserID"`
} }

View File

@ -0,0 +1,9 @@
package pgModels
import "time"
type UserFavorite struct {
UserID string `gorm:"primaryKey"`
PostID string `gorm:"primaryKey"`
CreatedAt time.Time
}

View File

@ -0,0 +1,8 @@
package pgModels
type UserSource struct {
UserID string `gorm:"primaryKey"`
SourceID string `gorm:"primaryKey"`
AccountUsername string
AccountID string
}