added pools #14

Merged
SoXX merged 16 commits from dev/pools into main 2024-10-15 09:03:46 +00:00
5 changed files with 92 additions and 1 deletions
Showing only changes of commit c120c583e3 - Show all commits

View File

@ -0,0 +1,28 @@
-- +migrate Up
CREATE TYPE pool_category AS ENUM ('series', 'collection');
CREATE TABLE "Pool"
(
id CHAR(25) PRIMARY KEY,
name VARCHAR(75),
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
deleted_at TIMESTAMP NULL,
category POOL_CATEGORY NOT NULL
);
CREATE TABLE "PoolPost"
(
pool_id CHAR(25) REFERENCES "Pool" (id),
post_id CHAR(25) REFERENCES "Post" (id),
order_position INT NOT NULL DEFAULT 0,
PRIMARY KEY (pool_id, post_id)
);
CREATE TABLE "PoolReference"
(
pool_id CHAR(25) REFERENCES "Pool" (id),
source_id CHAR(25) REFERENCES "Source" (id),
url TEXT NOT NULL,
PRIMARY KEY (pool_id, source_id, url)
);

View File

@ -6,6 +6,7 @@ type (
UserID string UserID string
PostID string PostID string
PostURL string PostURL string
PoolID string
SourceID string SourceID string
SourceDomain string SourceDomain string

View File

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

35
pkg/models/pools.go Normal file
View File

@ -0,0 +1,35 @@
package models
type Pool struct {
BaseModel[PoolID]
Name string `json:"name" gorm:"type:varchar(25)"`
Category string `json:"category" gorm:"type:pool_category;type:enum('series', 'collection')"`
}
func (Pool) TableName() string {
return "Pool"
}
type PoolPost struct {
Pool Pool `json:"pool" gorm:"foreignKey:ID;references:PoolID"`
PoolID PoolID `json:"pool_id" gorm:""`
Post Post `json:"post" gorm:"foreignKey:ID;references:PostID"`
PostID PostID `json:"post_id" gorm:""`
OrderPosition int `json:"order_position" gorm:"not null;default:0"`
}
func (PoolPost) TableName() string {
return "PoolPost"
}
type PoolReference struct {
Pool Pool `json:"pool" gorm:"foreignKey:ID;references:PoolID"`
PoolID PoolID `json:"pool_id" gorm:""`
Source Source `json:"source" gorm:"foreignKey:ID;references:SourceID"`
SourceID SourceID `json:"source_id" gorm:""`
URL string `json:"url" gorm:"not null"`
}
func (PoolReference) TableName() string {
return "PoolReference"
}

27
pkg/models/pools_test.go Normal file
View File

@ -0,0 +1,27 @@
package models
import "testing"
func TestPool_TableName(t *testing.T) {
post := Pool{}
expectedTableName := "Pool"
if tableName := post.TableName(); tableName != expectedTableName {
t.Fatalf("expected %s, but got %s", expectedTableName, tableName)
}
}
func TestPoolPost_TableName(t *testing.T) {
post := PoolPost{}
expectedTableName := "PoolPost"
if tableName := post.TableName(); tableName != expectedTableName {
t.Fatalf("expected %s, but got %s", expectedTableName, tableName)
}
}
func TestPoolReference_TableName(t *testing.T) {
post := PoolReference{}
expectedTableName := "PoolReference"
if tableName := post.TableName(); tableName != expectedTableName {
t.Fatalf("expected %s, but got %s", expectedTableName, tableName)
}
}