BREAKING CHANGE: V2 of thr SDK #12

Merged
fenpaws merged 124 commits from develop/postgresql into main 2024-07-01 20:46:28 +00:00
6 changed files with 23 additions and 14 deletions
Showing only changes of commit 47fda2994b - Show all commits

View File

@ -59,7 +59,7 @@ func GetPostByAnthroveID(ctx context.Context, db *gorm.DB, anthrovePostID models
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 == "" {
return nil, &otterError.EntityValidationFailed{Reason: "sourceURL is not set"}

View File

@ -249,13 +249,13 @@ func TestGetPostBySourceURL(t *testing.T) {
}
for _, tt := range tests {
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 {
t.Errorf("GetPostByURL() error = %v, wantErr %v", err, tt.wantErr)
t.Errorf("GetPostBySourceURL() error = %v, wantErr %v", err, tt.wantErr)
return
}
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)
}
})
}

View File

@ -15,7 +15,7 @@ import (
log "github.com/sirupsen/logrus"
gormPostgres "gorm.io/driver/postgres"
"gorm.io/gorm"
logger2 "gorm.io/gorm/logger"
gormLogger "gorm.io/gorm/logger"
)
//go:embed migrations/*.sql
@ -34,6 +34,8 @@ func NewPostgresqlConnection() OtterSpace {
func (p *postgresqlConnection) Connect(_ context.Context, config models.DatabaseConfig) error {
var localSSL string
var logLevel gormLogger.LogLevel
if config.SSL {
localSSL = "require"
} 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)
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,
LogLevel: logger2.Info,
LogLevel: logLevel,
IgnoreRecordNotFoundError: 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) {
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) {

View File

@ -887,11 +887,11 @@ func Test_postgresqlConnection_GetPostByURL(t *testing.T) {
}
got, err := p.GetPostByURL(tt.args.ctx, tt.args.sourceUrl)
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
}
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
View File

@ -0,0 +1,5 @@
package models
type FavoriteList struct {
Posts []Post `json:"posts,omitempty"`
}

View File

@ -11,7 +11,3 @@ type UserFavorites struct {
func (UserFavorites) TableName() string {
return "UserFavorites"
}
type FavoriteList struct {
Posts []Post `json:"posts,omitempty"`
}