feat(database): added additional columns

added more columns

BREAKING-CHANGE: breaks database compatibility to older SDK versions
This commit is contained in:
SoXX 2024-08-09 21:37:54 +02:00
parent e62280a416
commit 0e6a8fd61e
12 changed files with 52 additions and 38 deletions

View File

@ -2,18 +2,23 @@ package database
import ( import (
"context" "context"
"git.anthrove.art/Anthrove/otter-space-sdk/v2/pkg/models" "git.anthrove.art/Anthrove/otter-space-sdk/v2/pkg/models"
) )
type Source interface { func CreateUserSource(ctx context.Context, userSource models.UserSource) (models.UserSource, error) {
var user models.UserSource
// CreateSource adds a new source to the database. return user, nil
CreateSource(ctx context.Context, anthroveSource *models.Source) error }
// GetAllSources retrieves all sources. func UpdateUserSource(ctx context.Context, userSource models.UserSource) error {
GetAllSources(ctx context.Context) ([]models.Source, error) return nil
}
// GetSourceByDomain retrieves a source by its URL.
GetSourceByDomain(ctx context.Context, sourceDomain models.AnthroveSourceDomain) (*models.Source, error) 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
} }

View File

@ -2,20 +2,25 @@ package models
import "time" import "time"
type AnthroveUserID string type (
type AnthrovePostID string UserID string
type AnthroveSourceID string PostID string
type AnthroveSourceDomain string SourceID string
type AnthrovePostURL string SourceDomain string
type AnthroveTagGroupName string PostURL string
type AnthroveTagAliasName string TagGroupName string
type AnthroveTagID string TagAliasName string
type AnthroveScrapeTimeInterval int TagID string
type AnthroveUserLastScrapeTime time.Time ScrapeTimeInterval int
type AnthroveTagName string UserLastScrapeTime time.Time
TagName string
type Rating string Rating string
type TagType string TagType string
UserSourceID string
UserFavoriteID string
)
const ( const (
SFW Rating = "safe" SFW Rating = "safe"

View File

@ -8,7 +8,7 @@ import (
) )
type ID interface { type ID interface {
AnthroveUserID | AnthroveSourceID | AnthrovePostID UserID | SourceID | PostID | UserSourceID | UserFavoriteID
} }
type BaseModel[T ID] struct { type BaseModel[T ID] struct {

View File

@ -42,8 +42,8 @@ func TestBaseModel_BeforeCreate(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
base := &BaseModel[AnthrovePostID]{ base := &BaseModel[PostID]{
ID: AnthrovePostID(tt.fields.ID), ID: PostID(tt.fields.ID),
CreatedAt: tt.fields.CreatedAt, CreatedAt: tt.fields.CreatedAt,
UpdatedAt: tt.fields.UpdatedAt, UpdatedAt: tt.fields.UpdatedAt,
DeletedAt: tt.fields.DeletedAt, DeletedAt: tt.fields.DeletedAt,

View File

@ -2,7 +2,7 @@ package models
// Post model // Post model
type Post struct { type Post struct {
BaseModel[AnthrovePostID] BaseModel[PostID]
Rating Rating `json:"rating" gorm:"type:enum('safe','questionable','explicit')"` Rating Rating `json:"rating" gorm:"type:enum('safe','questionable','explicit')"`
Tags []Tag `json:"-" gorm:"many2many:post_tags;"` Tags []Tag `json:"-" gorm:"many2many:post_tags;"`
Favorites []UserFavorites `json:"-" gorm:"foreignKey:PostID"` Favorites []UserFavorites `json:"-" gorm:"foreignKey:PostID"`

View File

@ -4,7 +4,7 @@ import "testing"
func TestPost_TableName(t *testing.T) { func TestPost_TableName(t *testing.T) {
type fields struct { type fields struct {
BaseModel BaseModel[AnthrovePostID] BaseModel BaseModel[PostID]
Rating Rating Rating Rating
Tags []Tag Tags []Tag
Favorites []UserFavorites Favorites []UserFavorites

View File

@ -2,7 +2,7 @@ package models
// Source model // Source model
type Source struct { type Source struct {
BaseModel[AnthroveSourceID] BaseModel[SourceID]
DisplayName string `json:"display_name" ` DisplayName string `json:"display_name" `
Domain string `json:"domain" gorm:"not null;unique"` Domain string `json:"domain" gorm:"not null;unique"`
Icon string `json:"icon" gorm:"not null"` Icon string `json:"icon" gorm:"not null"`

View File

@ -4,7 +4,7 @@ import "testing"
func TestSource_TableName(t *testing.T) { func TestSource_TableName(t *testing.T) {
type fields struct { type fields struct {
BaseModel BaseModel[AnthroveSourceID] BaseModel BaseModel[SourceID]
DisplayName string DisplayName string
Domain string Domain string
Icon string Icon string

View File

@ -2,7 +2,7 @@ package models
// User model // User model
type User struct { type User struct {
BaseModel[AnthroveUserID] BaseModel[UserID]
Favorites []UserFavorites `json:"-" gorm:"foreignKey:UserID"` Favorites []UserFavorites `json:"-" gorm:"foreignKey:UserID"`
Sources []UserSource `json:"-" gorm:"foreignKey:UserID"` Sources []UserSource `json:"-" gorm:"foreignKey:UserID"`
} }

View File

@ -3,9 +3,12 @@ package models
import "time" import "time"
type UserFavorites struct { type UserFavorites struct {
UserID string `json:"user_id" gorm:"primaryKey"` BaseModel[UserFavoriteID]
PostID string `json:"post_id" gorm:"primaryKey"` UserID string `json:"user_id"`
CreatedAt time.Time `json:"-"` 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 { func (UserFavorites) TableName() string {

View File

@ -3,10 +3,11 @@ package models
import "time" import "time"
type UserSource struct { type UserSource struct {
BaseModel[UserSourceID]
User User `json:"user" gorm:"foreignKey:ID;references:UserID"` 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"` 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"` ScrapeTimeInterval string `json:"scrape_time_interval"`
AccountUsername string `json:"account_username"` AccountUsername string `json:"account_username"`
AccountID string `json:"account_id"` AccountID string `json:"account_id"`

View File

@ -4,7 +4,7 @@ import "testing"
func TestUser_TableName(t *testing.T) { func TestUser_TableName(t *testing.T) {
type fields struct { type fields struct {
BaseModel BaseModel[AnthroveUserID] BaseModel BaseModel[UserID]
Favorites []UserFavorites Favorites []UserFavorites
Sources []UserSource Sources []UserSource
} }