feat(database): added additional columns
added more columns BREAKING-CHANGE: breaks database compatibility to older SDK versions
This commit is contained in:
parent
e62280a416
commit
0e6a8fd61e
@ -2,18 +2,23 @@ package database
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.anthrove.art/Anthrove/otter-space-sdk/v2/pkg/models"
|
||||
)
|
||||
|
||||
type Source interface {
|
||||
|
||||
// CreateSource adds a new source to the database.
|
||||
CreateSource(ctx context.Context, anthroveSource *models.Source) error
|
||||
|
||||
// GetAllSources retrieves all sources.
|
||||
GetAllSources(ctx context.Context) ([]models.Source, error)
|
||||
|
||||
// GetSourceByDomain retrieves a source by its URL.
|
||||
GetSourceByDomain(ctx context.Context, sourceDomain models.AnthroveSourceDomain) (*models.Source, error)
|
||||
func CreateUserSource(ctx context.Context, userSource models.UserSource) (models.UserSource, error) {
|
||||
var user models.UserSource
|
||||
return user, nil
|
||||
}
|
||||
|
||||
func UpdateUserSource(ctx context.Context, userSource models.UserSource) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetUserSourceByID(ctx context.Context, id models.UserSourceID) (models.UserSource, error) {
|
||||
var user models.UserSource
|
||||
return user, nil
|
||||
}
|
||||
|
||||
func DeleteUserSource(ctx context.Context, id models.UserSourceID) error {
|
||||
return nil
|
||||
}
|
||||
|
@ -2,20 +2,25 @@ package models
|
||||
|
||||
import "time"
|
||||
|
||||
type AnthroveUserID string
|
||||
type AnthrovePostID string
|
||||
type AnthroveSourceID string
|
||||
type AnthroveSourceDomain string
|
||||
type AnthrovePostURL string
|
||||
type AnthroveTagGroupName string
|
||||
type AnthroveTagAliasName string
|
||||
type AnthroveTagID string
|
||||
type AnthroveScrapeTimeInterval int
|
||||
type AnthroveUserLastScrapeTime time.Time
|
||||
type AnthroveTagName string
|
||||
type (
|
||||
UserID string
|
||||
PostID string
|
||||
SourceID string
|
||||
SourceDomain string
|
||||
PostURL string
|
||||
TagGroupName string
|
||||
TagAliasName string
|
||||
TagID string
|
||||
ScrapeTimeInterval int
|
||||
UserLastScrapeTime time.Time
|
||||
TagName string
|
||||
|
||||
type Rating string
|
||||
type TagType string
|
||||
Rating string
|
||||
TagType string
|
||||
|
||||
UserSourceID string
|
||||
UserFavoriteID string
|
||||
)
|
||||
|
||||
const (
|
||||
SFW Rating = "safe"
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
type ID interface {
|
||||
AnthroveUserID | AnthroveSourceID | AnthrovePostID
|
||||
UserID | SourceID | PostID | UserSourceID | UserFavoriteID
|
||||
}
|
||||
|
||||
type BaseModel[T ID] struct {
|
||||
|
@ -42,8 +42,8 @@ func TestBaseModel_BeforeCreate(t *testing.T) {
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
base := &BaseModel[AnthrovePostID]{
|
||||
ID: AnthrovePostID(tt.fields.ID),
|
||||
base := &BaseModel[PostID]{
|
||||
ID: PostID(tt.fields.ID),
|
||||
CreatedAt: tt.fields.CreatedAt,
|
||||
UpdatedAt: tt.fields.UpdatedAt,
|
||||
DeletedAt: tt.fields.DeletedAt,
|
||||
|
@ -2,7 +2,7 @@ package models
|
||||
|
||||
// Post model
|
||||
type Post struct {
|
||||
BaseModel[AnthrovePostID]
|
||||
BaseModel[PostID]
|
||||
Rating Rating `json:"rating" gorm:"type:enum('safe','questionable','explicit')"`
|
||||
Tags []Tag `json:"-" gorm:"many2many:post_tags;"`
|
||||
Favorites []UserFavorites `json:"-" gorm:"foreignKey:PostID"`
|
||||
|
@ -4,7 +4,7 @@ import "testing"
|
||||
|
||||
func TestPost_TableName(t *testing.T) {
|
||||
type fields struct {
|
||||
BaseModel BaseModel[AnthrovePostID]
|
||||
BaseModel BaseModel[PostID]
|
||||
Rating Rating
|
||||
Tags []Tag
|
||||
Favorites []UserFavorites
|
||||
|
@ -2,7 +2,7 @@ package models
|
||||
|
||||
// Source model
|
||||
type Source struct {
|
||||
BaseModel[AnthroveSourceID]
|
||||
BaseModel[SourceID]
|
||||
DisplayName string `json:"display_name" `
|
||||
Domain string `json:"domain" gorm:"not null;unique"`
|
||||
Icon string `json:"icon" gorm:"not null"`
|
||||
|
@ -4,7 +4,7 @@ import "testing"
|
||||
|
||||
func TestSource_TableName(t *testing.T) {
|
||||
type fields struct {
|
||||
BaseModel BaseModel[AnthroveSourceID]
|
||||
BaseModel BaseModel[SourceID]
|
||||
DisplayName string
|
||||
Domain string
|
||||
Icon string
|
||||
|
@ -2,7 +2,7 @@ package models
|
||||
|
||||
// User model
|
||||
type User struct {
|
||||
BaseModel[AnthroveUserID]
|
||||
BaseModel[UserID]
|
||||
Favorites []UserFavorites `json:"-" gorm:"foreignKey:UserID"`
|
||||
Sources []UserSource `json:"-" gorm:"foreignKey:UserID"`
|
||||
}
|
||||
|
@ -3,9 +3,12 @@ package models
|
||||
import "time"
|
||||
|
||||
type UserFavorites struct {
|
||||
UserID string `json:"user_id" gorm:"primaryKey"`
|
||||
PostID string `json:"post_id" gorm:"primaryKey"`
|
||||
CreatedAt time.Time `json:"-"`
|
||||
BaseModel[UserFavoriteID]
|
||||
UserID string `json:"user_id"`
|
||||
PostID string `json:"post_id"`
|
||||
UserSourceID UserSourceID `json:"user_source_id"`
|
||||
UserSource UserSource `json:"-" gorm:"foreignKey:ID;references:UserSourceID"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
func (UserFavorites) TableName() string {
|
||||
|
@ -3,10 +3,11 @@ package models
|
||||
import "time"
|
||||
|
||||
type UserSource struct {
|
||||
BaseModel[UserSourceID]
|
||||
User User `json:"user" gorm:"foreignKey:ID;references:UserID"`
|
||||
UserID string `json:"user_id" gorm:"primaryKey"`
|
||||
UserID UserID `json:"user_id"`
|
||||
Source Source `json:"source" gorm:"foreignKey:ID;references:SourceID"`
|
||||
SourceID string `json:"source_id" gorm:"primaryKey"`
|
||||
SourceID SourceID `json:"source_id"`
|
||||
ScrapeTimeInterval string `json:"scrape_time_interval"`
|
||||
AccountUsername string `json:"account_username"`
|
||||
AccountID string `json:"account_id"`
|
||||
|
@ -4,7 +4,7 @@ import "testing"
|
||||
|
||||
func TestUser_TableName(t *testing.T) {
|
||||
type fields struct {
|
||||
BaseModel BaseModel[AnthroveUserID]
|
||||
BaseModel BaseModel[UserID]
|
||||
Favorites []UserFavorites
|
||||
Sources []UserSource
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user