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
type Post struct {
BaseModel
Rating models.Rating `gorm:"type:rating"`
Rating models.Rating `gorm:"type:enum('safe','questionable','explicit')"`
Body string `gorm:"type:text"`
UserID int `gorm:"index"`
Status string `gorm:"type:post_status"`
UserID int
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
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"`
}

View File

@ -5,17 +5,20 @@ 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"`
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
}

View File

@ -3,4 +3,6 @@ package pgModels
// User model
type User struct {
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
}