SDK v3 #8

Merged
SoXX merged 77 commits from dev/issue-5 into main 2024-08-14 13:27:35 +00:00
12 changed files with 52 additions and 38 deletions
Showing only changes of commit 0e6a8fd61e - Show all commits

View File

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

View File

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

View File

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

View File

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

View File

@ -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"`

View File

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

View File

@ -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"`

View File

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

View File

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

View File

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

View File

@ -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"`

View File

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