BREAKING CHANGE: V2 of thr SDK #12
@ -59,7 +59,7 @@ func GetPostByAnthroveID(ctx context.Context, db *gorm.DB, anthrovePostID models
|
|||||||
return &post, nil
|
return &post, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetPostByURL(ctx context.Context, db *gorm.DB, sourceURL string) (*models.Post, error) {
|
func GetPostBySourceURL(ctx context.Context, db *gorm.DB, sourceURL string) (*models.Post, error) {
|
||||||
|
|
||||||
if sourceURL == "" {
|
if sourceURL == "" {
|
||||||
return nil, &otterError.EntityValidationFailed{Reason: "sourceURL is not set"}
|
return nil, &otterError.EntityValidationFailed{Reason: "sourceURL is not set"}
|
||||||
|
@ -249,13 +249,13 @@ func TestGetPostBySourceURL(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) {
|
||||||
got, err := GetPostByURL(tt.args.ctx, tt.args.db, tt.args.sourceURL)
|
got, err := GetPostBySourceURL(tt.args.ctx, tt.args.db, tt.args.sourceURL)
|
||||||
if (err != nil) != tt.wantErr {
|
if (err != nil) != tt.wantErr {
|
||||||
t.Errorf("GetPostByURL() error = %v, wantErr %v", err, tt.wantErr)
|
t.Errorf("GetPostBySourceURL() error = %v, wantErr %v", err, tt.wantErr)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !checkPost(got, tt.want) {
|
if !checkPost(got, tt.want) {
|
||||||
t.Errorf("GetPostByURL() got = %v, want %v", got, tt.want)
|
t.Errorf("GetPostBySourceURL() got = %v, want %v", got, tt.want)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ import (
|
|||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
gormPostgres "gorm.io/driver/postgres"
|
gormPostgres "gorm.io/driver/postgres"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
logger2 "gorm.io/gorm/logger"
|
gormLogger "gorm.io/gorm/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:embed migrations/*.sql
|
//go:embed migrations/*.sql
|
||||||
@ -34,6 +34,8 @@ func NewPostgresqlConnection() OtterSpace {
|
|||||||
|
|
||||||
func (p *postgresqlConnection) Connect(_ context.Context, config models.DatabaseConfig) error {
|
func (p *postgresqlConnection) Connect(_ context.Context, config models.DatabaseConfig) error {
|
||||||
var localSSL string
|
var localSSL string
|
||||||
|
var logLevel gormLogger.LogLevel
|
||||||
|
|
||||||
if config.SSL {
|
if config.SSL {
|
||||||
localSSL = "require"
|
localSSL = "require"
|
||||||
} else {
|
} else {
|
||||||
@ -45,9 +47,15 @@ func (p *postgresqlConnection) Connect(_ context.Context, config models.Database
|
|||||||
dsn := fmt.Sprintf("host=%s user=%s password=%s dbname=%s port=%d sslmode=%s TimeZone=%s", config.Endpoint, config.Username, config.Password, config.Database, config.Port, localSSL, config.Timezone)
|
dsn := fmt.Sprintf("host=%s user=%s password=%s dbname=%s port=%d sslmode=%s TimeZone=%s", config.Endpoint, config.Username, config.Password, config.Database, config.Port, localSSL, config.Timezone)
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
dbLogger := logger2.New(log2.New(os.Stdout, "\r\n", log2.LstdFlags), logger2.Config{
|
if p.debug {
|
||||||
|
logLevel = gormLogger.Info
|
||||||
|
} else {
|
||||||
|
logLevel = gormLogger.Silent
|
||||||
|
}
|
||||||
|
|
||||||
|
dbLogger := gormLogger.New(log2.New(os.Stdout, "\r\n", log2.LstdFlags), gormLogger.Config{
|
||||||
SlowThreshold: 200 * time.Millisecond,
|
SlowThreshold: 200 * time.Millisecond,
|
||||||
LogLevel: logger2.Info,
|
LogLevel: logLevel,
|
||||||
IgnoreRecordNotFoundError: true,
|
IgnoreRecordNotFoundError: true,
|
||||||
Colorful: true,
|
Colorful: true,
|
||||||
})
|
})
|
||||||
@ -105,7 +113,7 @@ func (p *postgresqlConnection) GetPostByAnthroveID(ctx context.Context, anthrove
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *postgresqlConnection) GetPostByURL(ctx context.Context, sourceUrl string) (*models.Post, error) {
|
func (p *postgresqlConnection) GetPostByURL(ctx context.Context, sourceUrl string) (*models.Post, error) {
|
||||||
return postgres.GetPostByURL(ctx, p.db, sourceUrl)
|
return postgres.GetPostBySourceURL(ctx, p.db, sourceUrl)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *postgresqlConnection) GetPostBySourceID(ctx context.Context, sourceID models.AnthroveSourceID) (*models.Post, error) {
|
func (p *postgresqlConnection) GetPostBySourceID(ctx context.Context, sourceID models.AnthroveSourceID) (*models.Post, error) {
|
||||||
|
@ -887,11 +887,11 @@ func Test_postgresqlConnection_GetPostByURL(t *testing.T) {
|
|||||||
}
|
}
|
||||||
got, err := p.GetPostByURL(tt.args.ctx, tt.args.sourceUrl)
|
got, err := p.GetPostByURL(tt.args.ctx, tt.args.sourceUrl)
|
||||||
if (err != nil) != tt.wantErr {
|
if (err != nil) != tt.wantErr {
|
||||||
t.Errorf("GetPostByURL() error = %v, wantErr %v", err, tt.wantErr)
|
t.Errorf("GetPostBySourceURL() error = %v, wantErr %v", err, tt.wantErr)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !checkPost(got, tt.want) {
|
if !checkPost(got, tt.want) {
|
||||||
t.Errorf("GetPostByURL() got = %v, want %v", got, tt.want)
|
t.Errorf("GetPostBySourceURL() got = %v, want %v", got, tt.want)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
5
pkg/models/api.go
Normal file
5
pkg/models/api.go
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
type FavoriteList struct {
|
||||||
|
Posts []Post `json:"posts,omitempty"`
|
||||||
|
}
|
@ -11,7 +11,3 @@ type UserFavorites struct {
|
|||||||
func (UserFavorites) TableName() string {
|
func (UserFavorites) TableName() string {
|
||||||
return "UserFavorites"
|
return "UserFavorites"
|
||||||
}
|
}
|
||||||
|
|
||||||
type FavoriteList struct {
|
|
||||||
Posts []Post `json:"posts,omitempty"`
|
|
||||||
}
|
|
||||||
|
Reference in New Issue
Block a user