Compare commits

..

No commits in common. "f66fc6b6d7a19cd0fd152734d85093b25288d211" and "63e74219ed245b6eabe1c5d8baec540d8aba31da" have entirely different histories.

12 changed files with 183 additions and 393 deletions

View File

@ -1,25 +1,19 @@
package errors package error
type EntityAlreadyExists struct{} type EntityAlreadyExists struct{}
type NoDataWritten struct{}
type NoDataFound struct{}
func (e *EntityAlreadyExists) Error() string { func (e *EntityAlreadyExists) Error() string {
return "EntityAlreadyExists error" return "EntityAlreadyExists error"
} }
type NoDataWritten struct{}
func (e *NoDataWritten) Error() string { func (e *NoDataWritten) Error() string {
return "NoDataWritten error" return "NoDataWritten error"
} }
type NoDataFound struct{}
func (e *NoDataFound) Error() string { func (e *NoDataFound) Error() string {
return "NoDataFound error" return "NoDataFound error"
} }
type NoRelationCreated struct{}
func (e *NoRelationCreated) Error() string {
return "relationship creation error"
}

7
error/validation.go Normal file
View File

@ -0,0 +1,7 @@
package error
type MissingAnthrovePostIDError struct{}
func (e *MissingAnthrovePostIDError) Error() string {
return "AnthrovePostID is empty"
}

View File

@ -3,29 +3,24 @@ package postgres
import ( import (
"context" "context"
"errors" "errors"
errors2 "git.dragse.it/anthrove/otter-space-sdk/pkg/errors"
error2 "git.dragse.it/anthrove/otter-space-sdk/error"
"git.dragse.it/anthrove/otter-space-sdk/pkg/models" "git.dragse.it/anthrove/otter-space-sdk/pkg/models"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"gorm.io/gorm" "gorm.io/gorm"
) )
func CreatePost(ctx context.Context, db *gorm.DB, anthrovePost *models.Post) error { func CreatePost(ctx context.Context, db *gorm.DB, anthrovePost *models.Post) error {
if anthrovePost == nil {
return &errors2.EntityValidationFailed{Reason: "anthrovePost is nil"}
}
result := db.WithContext(ctx).Create(&anthrovePost) result := db.WithContext(ctx).Create(&anthrovePost)
if result.Error != nil {
if errors.Is(result.Error, gorm.ErrDuplicatedKey) {
return &errors2.EntityAlreadyExists{}
}
return result.Error
}
if result.RowsAffected == 0 { if result.RowsAffected == 0 {
return &errors2.NoDataWritten{} return &error2.NoDataWritten{}
}
if result.Error != nil {
if errors.Is(result.Error, gorm.ErrDuplicatedKey) {
return &error2.EntityAlreadyExists{}
}
} }
log.WithFields(log.Fields{ log.WithFields(log.Fields{
@ -37,58 +32,44 @@ func CreatePost(ctx context.Context, db *gorm.DB, anthrovePost *models.Post) err
} }
func GetPostByAnthroveID(ctx context.Context, db *gorm.DB, anthrovePostID models.AnthrovePostID) (*models.Post, error) { func GetPostByAnthroveID(ctx context.Context, db *gorm.DB, anthrovePostID models.AnthrovePostID) (*models.Post, error) {
if anthrovePostID == "" { if anthrovePostID == "" {
return nil, &errors2.EntityValidationFailed{Reason: "anthrovePostID is not set"} return nil, &error2.MissingAnthrovePostIDError{}
} }
//TODO maybe check ofor id length too...?
var post models.Post var post models.Post
result := db.WithContext(ctx).First(&post, "id = ?", anthrovePostID) result := db.WithContext(ctx).First(&post, "id = ?", anthrovePostID)
if result.Error != nil { if result.Error != nil {
if errors.Is(result.Error, gorm.ErrRecordNotFound) { if errors.Is(result.Error, gorm.ErrRecordNotFound) {
return nil, &errors2.NoDataFound{} return nil, &error2.NoDataFound{}
} }
return nil, result.Error
} }
return &post, nil return &post, nil
} }
func GetPostByURL(ctx context.Context, db *gorm.DB, sourceURL string) (*models.Post, error) { func GetPostByURL(ctx context.Context, db *gorm.DB, sourceURL string) (*models.Post, error) {
if sourceURL == "" {
return nil, &errors2.EntityValidationFailed{Reason: "sourceURL is not set"}
}
var post models.Post var post models.Post
result := db.WithContext(ctx).Raw(`SELECT p.id AS id, p.rating as rating FROM "Post" AS p INNER JOIN "PostReference" AS pr ON p.id = pr.post_id AND pr.url = $1 LIMIT 1`, sourceURL).First(&post) err := db.WithContext(ctx).Raw(`SELECT p.id AS id, p.rating as rating FROM "Post" AS p INNER JOIN "PostReference" AS pr ON p.id = pr.post_id AND pr.url = $1 LIMIT 1`, sourceURL).First(&post).Error
if result.Error != nil { if err != nil {
if errors.Is(result.Error, gorm.ErrRecordNotFound) { if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, &errors2.NoDataFound{} return nil, nil
} }
return nil, result.Error return nil, err
} }
return &post, nil return &post, nil
} }
func GetPostBySourceID(ctx context.Context, db *gorm.DB, sourceID models.AnthroveSourceID) (*models.Post, error) { func GetPostBySourceID(ctx context.Context, db *gorm.DB, sourceID models.AnthroveSourceID) (*models.Post, error) {
if sourceID == "" {
return nil, &errors2.EntityValidationFailed{Reason: "sourceID is not set"}
}
var post models.Post var post models.Post
result := db.WithContext(ctx).Raw(`SELECT p.id AS id, p.rating as rating FROM "Post" AS p INNER JOIN "PostReference" AS pr ON p.id = pr.post_id AND pr.source_id = $1 LIMIT 1`, sourceID).First(&post) err := db.WithContext(ctx).Raw(`SELECT p.id AS id, p.rating as rating FROM "Post" AS p INNER JOIN "PostReference" AS pr ON p.id = pr.post_id AND pr.source_id = $1 LIMIT 1`, sourceID).First(&post).Error
if result.Error != nil { if err != nil {
if errors.Is(result.Error, gorm.ErrRecordNotFound) { if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, &errors2.NoDataFound{} return nil, nil
} }
return nil, result.Error return nil, err
} }
return &post, nil return &post, nil

View File

@ -223,7 +223,7 @@ func TestGetPostBySourceURL(t *testing.T) {
sourceURL: "1234", sourceURL: "1234",
}, },
want: nil, want: nil,
wantErr: true, wantErr: false,
}, },
{ {
name: "Test 3: No sourceURL", name: "Test 3: No sourceURL",
@ -233,7 +233,7 @@ func TestGetPostBySourceURL(t *testing.T) {
sourceURL: "", sourceURL: "",
}, },
want: nil, want: nil,
wantErr: true, wantErr: false,
}, },
} }
for _, tt := range tests { for _, tt := range tests {
@ -323,7 +323,7 @@ func TestGetPostBySourceID(t *testing.T) {
sourceID: "1234", sourceID: "1234",
}, },
want: nil, want: nil,
wantErr: true, wantErr: false,
}, },
{ {
name: "Test 3: No sourceID", name: "Test 3: No sourceID",
@ -333,7 +333,7 @@ func TestGetPostBySourceID(t *testing.T) {
sourceID: "", sourceID: "",
}, },
want: nil, want: nil,
wantErr: true, wantErr: false,
}, },
} }
for _, tt := range tests { for _, tt := range tests {

View File

@ -2,8 +2,6 @@ package postgres
import ( import (
"context" "context"
"errors"
errors2 "git.dragse.it/anthrove/otter-space-sdk/pkg/errors"
"git.dragse.it/anthrove/otter-space-sdk/pkg/models" "git.dragse.it/anthrove/otter-space-sdk/pkg/models"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"gorm.io/gorm" "gorm.io/gorm"
@ -11,44 +9,23 @@ import (
func CreateReferenceBetweenPostAndSource(ctx context.Context, db *gorm.DB, anthrovePostID models.AnthrovePostID, sourceDomain models.AnthroveSourceDomain) error { func CreateReferenceBetweenPostAndSource(ctx context.Context, db *gorm.DB, anthrovePostID models.AnthrovePostID, sourceDomain models.AnthroveSourceDomain) error {
var source models.Source var source models.Source
var err error
if anthrovePostID == "" {
return &errors2.EntityValidationFailed{Reason: "anthrovePostID cannot be empty"}
}
if len(anthrovePostID) != 25 {
return &errors2.EntityValidationFailed{Reason: "anthrovePostID needs to be 25 characters long"}
}
if sourceDomain == "" {
return &errors2.EntityValidationFailed{Reason: "sourceDomain cannot be empty"}
}
// Find the source // Find the source
result := db.WithContext(ctx).Where("domain = ?", sourceDomain).First(&source) err = db.WithContext(ctx).Where("domain = ?", sourceDomain).First(&source).Error
if result.Error != nil { if err != nil {
if errors.Is(result.Error, gorm.ErrRecordNotFound) { return err
return &errors2.NoDataFound{}
}
return result.Error
} }
// Establish the relationship // Establish the relationship
result = db.WithContext(ctx).Create(models.PostReference{ err = db.WithContext(ctx).Create(models.PostReference{
PostID: string(anthrovePostID), PostID: string(anthrovePostID),
SourceID: string(source.ID), SourceID: string(source.ID),
URL: string(sourceDomain), URL: string(sourceDomain),
}) }).Error
if result.Error != nil { if err != nil {
if errors.Is(result.Error, gorm.ErrDuplicatedKey) { return err
return &errors2.EntityAlreadyExists{}
}
return result.Error
}
if result.RowsAffected == 0 {
return &errors2.NoDataWritten{}
} }
log.WithFields(log.Fields{ log.WithFields(log.Fields{
@ -60,34 +37,14 @@ func CreateReferenceBetweenPostAndSource(ctx context.Context, db *gorm.DB, anthr
} }
func CreateReferenceBetweenUserAndPost(ctx context.Context, db *gorm.DB, anthroveUserID models.AnthroveUserID, anthrovePostID models.AnthrovePostID) error { func CreateReferenceBetweenUserAndPost(ctx context.Context, db *gorm.DB, anthroveUserID models.AnthroveUserID, anthrovePostID models.AnthrovePostID) error {
if anthrovePostID == "" {
return &errors2.EntityValidationFailed{Reason: "anthrovePostID cannot be empty"}
}
if len(anthrovePostID) != 25 {
return &errors2.EntityValidationFailed{Reason: "anthrovePostID needs to be 25 characters long"}
}
if anthroveUserID == "" {
return &errors2.EntityValidationFailed{Reason: "anthroveUserID cannot be empty"}
}
userFavorite := models.UserFavorites{ userFavorite := models.UserFavorites{
UserID: string(anthroveUserID), UserID: string(anthroveUserID),
PostID: string(anthrovePostID), PostID: string(anthrovePostID),
} }
result := db.WithContext(ctx).Create(&userFavorite) err := db.WithContext(ctx).Create(&userFavorite).Error
if result.Error != nil { if err != nil {
if errors.Is(result.Error, gorm.ErrDuplicatedKey) { return err
return &errors2.EntityAlreadyExists{}
}
return result.Error
}
if result.RowsAffected == 0 {
return &errors2.NoDataWritten{}
} }
log.WithFields(log.Fields{ log.WithFields(log.Fields{
@ -100,29 +57,9 @@ func CreateReferenceBetweenUserAndPost(ctx context.Context, db *gorm.DB, anthrov
func CheckReferenceBetweenUserAndPost(ctx context.Context, db *gorm.DB, anthroveUserID models.AnthroveUserID, anthrovePostID models.AnthrovePostID) (bool, error) { func CheckReferenceBetweenUserAndPost(ctx context.Context, db *gorm.DB, anthroveUserID models.AnthroveUserID, anthrovePostID models.AnthrovePostID) (bool, error) {
var count int64 var count int64
err := db.WithContext(ctx).Model(&models.UserFavorites{}).Where("user_id = ? AND post_id = ?", string(anthroveUserID), string(anthrovePostID)).Count(&count).Error
if anthrovePostID == "" { if err != nil {
return false, &errors2.EntityValidationFailed{Reason: "anthrovePostID cannot be empty"} return false, err
}
if len(anthrovePostID) != 25 {
return false, &errors2.EntityValidationFailed{Reason: "anthrovePostID needs to be 25 characters long"}
}
if anthroveUserID == "" {
return false, &errors2.EntityValidationFailed{Reason: "anthroveUserID cannot be empty"}
}
if len(anthroveUserID) != 25 {
return false, &errors2.EntityValidationFailed{Reason: "anthroveUserID needs to be 25 characters long"}
}
result := db.WithContext(ctx).Model(&models.UserFavorites{}).Where("user_id = ? AND post_id = ?", string(anthroveUserID), string(anthrovePostID)).Count(&count)
if result.Error != nil {
if errors.Is(result.Error, gorm.ErrRecordNotFound) {
return false, &errors2.NoDataFound{}
}
return false, result.Error
} }
exists := count > 0 exists := count > 0

View File

@ -20,20 +20,14 @@ func TestCheckUserToPostLink(t *testing.T) {
defer container.Terminate(ctx) defer container.Terminate(ctx)
// Setup Test // Setup Test
err = CreateUser(ctx, gormDB, "1")
validUserID := models.AnthroveUserID(fmt.Sprintf("%025s", "User1"))
invalidUserID := models.AnthroveUserID("XXX")
validPostID := models.AnthrovePostID(fmt.Sprintf("%025s", "Post1"))
err = CreateUser(ctx, gormDB, validUserID)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
post := &models.Post{ post := &models.Post{
BaseModel: models.BaseModel[models.AnthrovePostID]{ BaseModel: models.BaseModel[models.AnthrovePostID]{
ID: validPostID, ID: models.AnthrovePostID(fmt.Sprintf("%025s", "1")),
}, },
Rating: "safe", Rating: "safe",
} }
@ -43,7 +37,7 @@ func TestCheckUserToPostLink(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
err = CreateReferenceBetweenUserAndPost(ctx, gormDB, validUserID, post.ID) err = CreateReferenceBetweenUserAndPost(ctx, gormDB, "1", models.AnthrovePostID(post.ID))
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -66,7 +60,7 @@ func TestCheckUserToPostLink(t *testing.T) {
args: args{ args: args{
ctx: ctx, ctx: ctx,
db: gormDB, db: gormDB,
anthroveUserID: validUserID, anthroveUserID: "1",
anthrovePostID: post.ID, anthrovePostID: post.ID,
}, },
want: true, want: true,
@ -77,33 +71,33 @@ func TestCheckUserToPostLink(t *testing.T) {
args: args{ args: args{
ctx: ctx, ctx: ctx,
db: gormDB, db: gormDB,
anthroveUserID: validUserID, anthroveUserID: "1",
anthrovePostID: "qadw", anthrovePostID: "qadw",
}, },
want: false, want: false,
wantErr: true, wantErr: false,
}, },
{ {
name: "Test 3: Valid AnthrovePostID and invalid AnthroveUserID", name: "Test 3: Valid AnthrovePostID and invalid AnthroveUserID",
args: args{ args: args{
ctx: ctx, ctx: ctx,
db: gormDB, db: gormDB,
anthroveUserID: invalidUserID, anthroveUserID: "123",
anthrovePostID: post.ID, anthrovePostID: post.ID,
}, },
want: false, want: false,
wantErr: true, wantErr: false,
}, },
{ {
name: "Test 4: Invalid AnthrovePostID and invalid AnthroveUserID", name: "Test 4: Invalid AnthrovePostID and invalid AnthroveUserID",
args: args{ args: args{
ctx: ctx, ctx: ctx,
db: gormDB, db: gormDB,
anthroveUserID: invalidUserID, anthroveUserID: "123",
anthrovePostID: "123456", anthrovePostID: "123456",
}, },
want: false, want: false,
wantErr: true, wantErr: false,
}, },
} }
for _, tt := range tests { for _, tt := range tests {
@ -225,20 +219,14 @@ func TestEstablishUserToPostLink(t *testing.T) {
defer container.Terminate(ctx) defer container.Terminate(ctx)
// Setup Test // Setup Test
err = CreateUser(ctx, gormDB, "1")
validUserID := models.AnthroveUserID(fmt.Sprintf("%025s", "User1"))
invalidUserID := models.AnthroveUserID("XXX")
validPostID := models.AnthrovePostID(fmt.Sprintf("%025s", "Post1"))
err = CreateUser(ctx, gormDB, validUserID)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
post := &models.Post{ post := &models.Post{
BaseModel: models.BaseModel[models.AnthrovePostID]{ BaseModel: models.BaseModel[models.AnthrovePostID]{
ID: validPostID, ID: models.AnthrovePostID(fmt.Sprintf("%025s", "1")),
}, },
Rating: "safe", Rating: "safe",
} }
@ -265,7 +253,7 @@ func TestEstablishUserToPostLink(t *testing.T) {
args: args{ args: args{
ctx: ctx, ctx: ctx,
db: gormDB, db: gormDB,
anthroveUserID: validUserID, anthroveUserID: "1",
anthrovePostID: post.ID, anthrovePostID: post.ID,
}, },
wantErr: false, wantErr: false,
@ -275,18 +263,18 @@ func TestEstablishUserToPostLink(t *testing.T) {
args: args{ args: args{
ctx: ctx, ctx: ctx,
db: gormDB, db: gormDB,
anthroveUserID: validUserID, anthroveUserID: "1",
anthrovePostID: "123456", anthrovePostID: "123456",
}, },
wantErr: true, wantErr: true,
}, },
{ {
name: "Test 3: invalid AnthroveUserID and valid AnthrovePostID", name: "Test 3: Valid AnthrovePostID and invalid AnthroveUserID",
args: args{ args: args{
ctx: ctx, ctx: ctx,
db: gormDB, db: gormDB,
anthroveUserID: invalidUserID, anthroveUserID: "123",
anthrovePostID: post.ID, anthrovePostID: "1234",
}, },
wantErr: true, wantErr: true,
}, },
@ -295,7 +283,7 @@ func TestEstablishUserToPostLink(t *testing.T) {
args: args{ args: args{
ctx: ctx, ctx: ctx,
db: gormDB, db: gormDB,
anthroveUserID: invalidUserID, anthroveUserID: "123",
anthrovePostID: "123456", anthrovePostID: "123456",
}, },
wantErr: true, wantErr: true,

View File

@ -2,8 +2,7 @@ package postgres
import ( import (
"context" "context"
"errors" "fmt"
errors2 "git.dragse.it/anthrove/otter-space-sdk/pkg/errors"
"git.dragse.it/anthrove/otter-space-sdk/pkg/models" "git.dragse.it/anthrove/otter-space-sdk/pkg/models"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
@ -14,22 +13,15 @@ import (
func CreateSource(ctx context.Context, db *gorm.DB, anthroveSource *models.Source) error { func CreateSource(ctx context.Context, db *gorm.DB, anthroveSource *models.Source) error {
if anthroveSource.Domain == "" { if anthroveSource.Domain == "" {
return &errors2.EntityValidationFailed{Reason: "Domain is required"} return fmt.Errorf("anthroveSource domain is required")
} }
result := db.WithContext(ctx).Where(models.Source{Domain: anthroveSource.Domain}).FirstOrCreate(anthroveSource) result := db.WithContext(ctx).Where(models.Source{Domain: anthroveSource.Domain}).FirstOrCreate(anthroveSource)
if result.Error != nil { if result.Error != nil {
if errors.Is(result.Error, gorm.ErrDuplicatedKey) {
return &errors2.EntityAlreadyExists{}
}
return result.Error return result.Error
} }
if result.RowsAffected == 0 {
return &errors2.NoDataWritten{}
}
log.WithFields(log.Fields{ log.WithFields(log.Fields{
"node_source_url": anthroveSource.Domain, "node_source_url": anthroveSource.Domain,
"node_source_displayName": anthroveSource.DisplayName, "node_source_displayName": anthroveSource.DisplayName,
@ -46,9 +38,6 @@ func GetAllSource(ctx context.Context, db *gorm.DB) ([]models.Source, error) {
result := db.WithContext(ctx).Find(&sources) result := db.WithContext(ctx).Find(&sources)
if result.Error != nil { if result.Error != nil {
if errors.Is(result.Error, gorm.ErrRecordNotFound) {
return nil, &errors2.NoDataFound{}
} // TODO really...? i don't think this error handling should be here..? / not possible
return nil, result.Error return nil, result.Error
} }
@ -64,15 +53,12 @@ func GetSourceByDomain(ctx context.Context, db *gorm.DB, sourceDomain models.Ant
var sources models.Source var sources models.Source
if sourceDomain == "" { if sourceDomain == "" {
return nil, &errors2.EntityValidationFailed{Reason: "AnthroveSourceDomain is not set"} return nil, fmt.Errorf("domain is required")
} }
result := db.WithContext(ctx).Where("domain = ?", sourceDomain).First(&sources) result := db.WithContext(ctx).Where("domain = ?", sourceDomain).First(&sources)
if result.Error != nil { if result.Error != nil {
if errors.Is(result.Error, gorm.ErrRecordNotFound) {
return nil, &errors2.NoDataFound{}
}
return nil, result.Error return nil, result.Error
} }

View File

@ -2,7 +2,6 @@ package postgres
import ( import (
"context" "context"
"fmt"
"git.dragse.it/anthrove/otter-space-sdk/pkg/models" "git.dragse.it/anthrove/otter-space-sdk/pkg/models"
"git.dragse.it/anthrove/otter-space-sdk/test" "git.dragse.it/anthrove/otter-space-sdk/test"
"gorm.io/gorm" "gorm.io/gorm"
@ -20,10 +19,7 @@ func TestCreateSourceNode(t *testing.T) {
// Setup Test // Setup Test
validPostID := models.AnthroveSourceID(fmt.Sprintf("%025s", "Post1"))
validSource := &models.Source{ validSource := &models.Source{
BaseModel: models.BaseModel[models.AnthroveSourceID]{ID: validPostID},
DisplayName: "e621", DisplayName: "e621",
Domain: "e621.net", Domain: "e621.net",
Icon: "icon.e621.net", Icon: "icon.e621.net",
@ -69,7 +65,7 @@ func TestCreateSourceNode(t *testing.T) {
db: gormDB, db: gormDB,
anthroveSource: validSource, anthroveSource: validSource,
}, },
wantErr: true, wantErr: false,
}, },
} }
for _, tt := range tests { for _, tt := range tests {

View File

@ -2,8 +2,7 @@ package postgres
import ( import (
"context" "context"
"errors" "fmt"
errors2 "git.dragse.it/anthrove/otter-space-sdk/pkg/errors"
"git.dragse.it/anthrove/otter-space-sdk/pkg/models" "git.dragse.it/anthrove/otter-space-sdk/pkg/models"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"gorm.io/gorm" "gorm.io/gorm"
@ -11,20 +10,10 @@ import (
func CreateTag(ctx context.Context, db *gorm.DB, tag *models.Tag) error { func CreateTag(ctx context.Context, db *gorm.DB, tag *models.Tag) error {
if tag == nil { resultTag := db.WithContext(ctx).Where(tag).Create(tag)
return &errors2.EntityValidationFailed{Reason: "Tag is nil"}
}
result := db.WithContext(ctx).Where(tag).Create(tag) if resultTag.Error != nil {
if result.Error != nil { return resultTag.Error
if errors.Is(result.Error, gorm.ErrDuplicatedKey) {
return &errors2.EntityAlreadyExists{}
}
return result.Error
}
if result.RowsAffected == 0 {
return &errors2.NoDataWritten{}
} }
log.WithFields(log.Fields{ log.WithFields(log.Fields{
@ -35,36 +24,30 @@ func CreateTag(ctx context.Context, db *gorm.DB, tag *models.Tag) error {
return nil return nil
} }
func CreateTagAndReferenceToPost(ctx context.Context, db *gorm.DB, anthrovePostID models.AnthrovePostID, tag *models.Tag) error { func CreateTagAndReferenceToPost(ctx context.Context, db *gorm.DB, PostID models.AnthrovePostID, tag *models.Tag) error {
if anthrovePostID == "" { if PostID == "" {
return &errors2.EntityValidationFailed{Reason: "anthrovePostID cannot be empty"} return fmt.Errorf("PostID is empty")
}
if len(anthrovePostID) != 25 {
return &errors2.EntityValidationFailed{Reason: "anthrovePostID needs to be 25 characters long"}
} }
if tag == nil { if tag == nil {
return &errors2.EntityValidationFailed{Reason: "Tag is nil"} return fmt.Errorf("tag is nill")
} }
pgPost := models.Post{ pgPost := models.Post{
BaseModel: models.BaseModel[models.AnthrovePostID]{ BaseModel: models.BaseModel[models.AnthrovePostID]{
ID: anthrovePostID, ID: PostID,
}, },
} }
err := db.WithContext(ctx).Model(&pgPost).Association("Tags").Append(tag) err := db.WithContext(ctx).Model(&pgPost).Association("Tags").Append(tag)
if err != nil { if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) { return err
return &errors2.NoDataFound{}
}
return errors.Join(err, &errors2.NoRelationCreated{})
} }
log.WithFields(log.Fields{ log.WithFields(log.Fields{
"anthrove_post_id": anthrovePostID, "anthrove_post_id": PostID,
"tag_name": tag.Name, "tag_name": tag.Name,
"tag_type": tag.Type, "tag_type": tag.Type,
}).Trace("database: created tag node") }).Trace("database: created tag node")
@ -74,13 +57,8 @@ func CreateTagAndReferenceToPost(ctx context.Context, db *gorm.DB, anthrovePostI
func GetTags(ctx context.Context, db *gorm.DB) ([]models.Tag, error) { func GetTags(ctx context.Context, db *gorm.DB) ([]models.Tag, error) {
var tags []models.Tag var tags []models.Tag
result := db.WithContext(ctx).Find(&tags) result := db.WithContext(ctx).Find(&tags)
if result.Error != nil { if result.Error != nil {
if errors.Is(result.Error, gorm.ErrRecordNotFound) { // TODO really...? i don't think this error handling should be here..? / not possible
return nil, &errors2.NoDataFound{}
}
return nil, result.Error return nil, result.Error
} }

View File

@ -2,8 +2,7 @@ package postgres
import ( import (
"context" "context"
"errors" "fmt"
errors2 "git.dragse.it/anthrove/otter-space-sdk/pkg/errors"
"git.dragse.it/anthrove/otter-space-sdk/pkg/models" "git.dragse.it/anthrove/otter-space-sdk/pkg/models"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"gorm.io/gorm" "gorm.io/gorm"
@ -12,11 +11,7 @@ import (
func CreateUser(ctx context.Context, db *gorm.DB, anthroveUserID models.AnthroveUserID) error { func CreateUser(ctx context.Context, db *gorm.DB, anthroveUserID models.AnthroveUserID) error {
if anthroveUserID == "" { if anthroveUserID == "" {
return &errors2.EntityValidationFailed{Reason: "anthroveUserID cannot be empty"} return fmt.Errorf("anthroveUserID cannot be empty")
}
if len(anthroveUserID) != 25 {
return &errors2.EntityValidationFailed{Reason: "anthroveUserID needs to be 25 characters long"}
} }
user := models.User{ user := models.User{
@ -25,16 +20,12 @@ func CreateUser(ctx context.Context, db *gorm.DB, anthroveUserID models.Anthrove
}, },
} }
result := db.WithContext(ctx).FirstOrCreate(&user) err := db.WithContext(ctx).FirstOrCreate(&user).Error
if result.Error != nil { if err != nil {
if errors.Is(result.Error, gorm.ErrDuplicatedKey) { log.WithFields(log.Fields{
return &errors2.EntityAlreadyExists{} "anthrove_user_id": anthroveUserID,
} }).Error("database: failed to create user")
return result.Error return err
}
if result.RowsAffected == 0 {
return &errors2.NoDataWritten{}
} }
return nil return nil
@ -43,19 +34,15 @@ func CreateUser(ctx context.Context, db *gorm.DB, anthroveUserID models.Anthrove
func CreateUserWithRelationToSource(ctx context.Context, db *gorm.DB, anthroveUserID models.AnthroveUserID, sourceID models.AnthroveSourceID, accountId string, accountUsername string) error { func CreateUserWithRelationToSource(ctx context.Context, db *gorm.DB, anthroveUserID models.AnthroveUserID, sourceID models.AnthroveSourceID, accountId string, accountUsername string) error {
if anthroveUserID == "" { if anthroveUserID == "" {
return &errors2.EntityValidationFailed{Reason: "anthroveUserID cannot be empty"} return fmt.Errorf("anthroveUserID cannot be empty")
}
if len(anthroveUserID) != 25 {
return &errors2.EntityValidationFailed{Reason: "anthroveUserID needs to be 25 characters long"}
} }
if accountId == "" { if accountId == "" {
return &errors2.EntityValidationFailed{Reason: "accountID cannot be empty"} return fmt.Errorf("account_id cannot be empty")
} }
if accountUsername == "" { if accountUsername == "" {
return &errors2.EntityValidationFailed{Reason: "accountUsername cannot be empty"} return fmt.Errorf("account_username cannot be empty")
} }
err := CreateUser(ctx, db, anthroveUserID) err := CreateUser(ctx, db, anthroveUserID)
@ -67,12 +54,11 @@ func CreateUserWithRelationToSource(ctx context.Context, db *gorm.DB, anthroveUs
BaseModel: models.BaseModel[models.AnthroveSourceID]{ID: sourceID}, BaseModel: models.BaseModel[models.AnthroveSourceID]{ID: sourceID},
} }
result := db.WithContext(ctx).Where(&source).First(&source) if err := db.WithContext(ctx).Where(&source).First(&source).Error; err != nil {
if result.Error != nil { log.WithFields(log.Fields{
if errors.Is(result.Error, gorm.ErrRecordNotFound) { "source_id": sourceID,
return &errors2.NoDataFound{} }).Error("database: failed to find source")
} return err
return result.Error
} }
userSource := models.UserSource{ userSource := models.UserSource{
@ -83,13 +69,14 @@ func CreateUserWithRelationToSource(ctx context.Context, db *gorm.DB, anthroveUs
UserID: string(anthroveUserID), UserID: string(anthroveUserID),
} }
result = db.WithContext(ctx).FirstOrCreate(&userSource) if err := db.WithContext(ctx).FirstOrCreate(&userSource).Error; err != nil {
if result.Error != nil { log.WithFields(log.Fields{
return errors.Join(result.Error, &errors2.NoRelationCreated{}) "anthrove_user_id": anthroveUserID,
} "source_id": sourceID,
"account_username": accountUsername,
if result.RowsAffected == 0 { "account_id": accountId,
return &errors2.NoDataWritten{} }).Error("database: failed to create user-source relationship")
return err
} }
log.WithFields(log.Fields{ log.WithFields(log.Fields{
@ -103,22 +90,17 @@ func CreateUserWithRelationToSource(ctx context.Context, db *gorm.DB, anthroveUs
} }
func GetUserFavoritesCount(ctx context.Context, db *gorm.DB, anthroveUserID models.AnthroveUserID) (int64, error) { func GetUserFavoritesCount(ctx context.Context, db *gorm.DB, anthroveUserID models.AnthroveUserID) (int64, error) {
var count int64
if anthroveUserID == "" { if anthroveUserID == "" {
return 0, &errors2.EntityValidationFailed{Reason: "anthroveUserID cannot be empty"} return 0, fmt.Errorf("anthroveUserID cannot be empty")
} }
if len(anthroveUserID) != 25 { var count int64
return 0, &errors2.EntityValidationFailed{Reason: "anthroveUserID needs to be 25 characters long"} err := db.WithContext(ctx).Model(&models.UserFavorites{}).Where("user_id = ?", string(anthroveUserID)).Count(&count).Error
} if err != nil {
log.WithFields(log.Fields{
result := db.WithContext(ctx).Model(&models.UserFavorites{}).Where("user_id = ?", string(anthroveUserID)).Count(&count) "anthrove_user_id": anthroveUserID,
if result.Error != nil { }).Error("database: failed to get user favorites count")
if errors.Is(result.Error, gorm.ErrRecordNotFound) { return 0, err
return 0, &errors2.NoDataFound{}
}
return 0, result.Error
} }
log.WithFields(log.Fields{ log.WithFields(log.Fields{
@ -133,30 +115,22 @@ func GetUserSourceLinks(ctx context.Context, db *gorm.DB, anthroveUserID models.
var userSources []models.UserSource var userSources []models.UserSource
userSourceMap := make(map[string]models.UserSource) userSourceMap := make(map[string]models.UserSource)
if anthroveUserID == "" { err := db.WithContext(ctx).Model(&models.UserSource{}).Where("user_id = ?", string(anthroveUserID)).Find(&userSources).Error
return nil, &errors2.EntityValidationFailed{Reason: "anthroveUserID cannot be empty"} if err != nil {
} log.WithFields(log.Fields{
"anthrove_user_id": anthroveUserID,
if len(anthroveUserID) != 25 { }).Error("database: failed to get user source link")
return nil, &errors2.EntityValidationFailed{Reason: "anthroveUserID needs to be 25 characters long"} return nil, err
}
result := db.WithContext(ctx).Model(&models.UserSource{}).Where("user_id = ?", string(anthroveUserID)).Find(&userSources)
if result.Error != nil {
if errors.Is(result.Error, gorm.ErrRecordNotFound) {
return nil, &errors2.NoDataFound{}
}
return nil, result.Error
} }
for _, userSource := range userSources { for _, userSource := range userSources {
var source models.Source var source models.Source
result = db.WithContext(ctx).Model(&models.Source{}).Where("id = ?", userSource.SourceID).First(&source) err = db.WithContext(ctx).Model(&models.Source{}).Where("id = ?", userSource.SourceID).First(&source).Error
if result.Error != nil { if err != nil {
if errors.Is(result.Error, gorm.ErrRecordNotFound) { log.WithFields(log.Fields{
return nil, &errors2.NoDataFound{} "source_id": userSource.SourceID,
} }).Error("database: failed to get source")
return nil, result.Error return nil, err
} }
userSourceMap[source.DisplayName] = models.UserSource{ userSourceMap[source.DisplayName] = models.UserSource{
@ -178,41 +152,34 @@ func GetUserSourceLinks(ctx context.Context, db *gorm.DB, anthroveUserID models.
} }
func GetUserSourceBySourceID(ctx context.Context, db *gorm.DB, anthroveUserID models.AnthroveUserID, sourceID models.AnthroveSourceID) (map[string]models.UserSource, error) { func GetUserSourceBySourceID(ctx context.Context, db *gorm.DB, anthroveUserID models.AnthroveUserID, sourceID models.AnthroveSourceID) (map[string]models.UserSource, error) {
var userSources []models.UserSource
userSourceMap := make(map[string]models.UserSource)
if anthroveUserID == "" { if anthroveUserID == "" {
return nil, &errors2.EntityValidationFailed{Reason: "anthroveUserID cannot be empty"} return nil, fmt.Errorf("anthroveUserID cannot be empty")
}
if len(anthroveUserID) != 25 {
return nil, &errors2.EntityValidationFailed{Reason: "anthroveUserID needs to be 25 characters long"}
} }
if sourceID == "" { if sourceID == "" {
return nil, &errors2.EntityValidationFailed{Reason: "sourceID cannot be empty"} return nil, fmt.Errorf("sourceID cannot be empty")
} }
if len(sourceID) != 25 { var userSources []models.UserSource
return nil, &errors2.EntityValidationFailed{Reason: "sourceID needs to be 25 characters long"} userSourceMap := make(map[string]models.UserSource)
}
result := db.WithContext(ctx).Model(&models.UserSource{}).InnerJoins("Source", db.Where("id = ?", sourceID)).Where("user_id = ?", string(anthroveUserID)).First(&userSources) err := db.WithContext(ctx).Model(&models.UserSource{}).InnerJoins("Source", db.Where("id = ?", sourceID)).Where("user_id = ?", string(anthroveUserID)).First(&userSources).Error
if result.Error != nil { if err != nil {
if errors.Is(result.Error, gorm.ErrRecordNotFound) { log.WithFields(log.Fields{
return nil, &errors2.NoDataFound{} "anthrove_user_id": anthroveUserID,
} "source_id": sourceID,
return nil, result.Error }).Error("database: failed to get specified user source link")
return nil, err
} }
for _, userSource := range userSources { for _, userSource := range userSources {
var source models.Source var source models.Source
result = db.WithContext(ctx).Model(&models.Source{}).Where("id = ?", userSource.SourceID).First(&source) err = db.WithContext(ctx).Model(&models.Source{}).Where("id = ?", userSource.SourceID).First(&source).Error
if result.Error != nil { if err != nil {
if errors.Is(result.Error, gorm.ErrRecordNotFound) { log.WithFields(log.Fields{
return nil, &errors2.NoDataFound{} "source_id": userSource.SourceID,
} }).Error("database: failed to get source")
return nil, result.Error return nil, err
} }
userSourceMap[source.DisplayName] = models.UserSource{ userSourceMap[source.DisplayName] = models.UserSource{
@ -238,16 +205,14 @@ func GetAllAnthroveUserIDs(ctx context.Context, db *gorm.DB) ([]models.AnthroveU
var users []models.User var users []models.User
var userIDs []models.AnthroveUserID var userIDs []models.AnthroveUserID
result := db.WithContext(ctx).Model(&models.User{}).Find(&users) err := db.WithContext(ctx).Model(&models.User{}).Find(&users).Error
if result.Error != nil { if err != nil {
if errors.Is(result.Error, gorm.ErrRecordNotFound) { log.Error("database: failed to get all anthrove user IDs")
return nil, &errors2.NoDataFound{} return nil, err
}
return nil, result.Error
} }
for _, user := range users { for _, user := range users {
userIDs = append(userIDs, user.ID) userIDs = append(userIDs, models.AnthroveUserID(user.ID))
} }
log.WithFields(log.Fields{ log.WithFields(log.Fields{
@ -261,19 +226,13 @@ func GetUserFavoriteWithPagination(ctx context.Context, db *gorm.DB, anthroveUse
var userFavorites []models.UserFavorites var userFavorites []models.UserFavorites
var favoritePosts []models.Post var favoritePosts []models.Post
if anthroveUserID == "" {
return nil, &errors2.EntityValidationFailed{Reason: "anthroveUserID cannot be empty"}
}
if len(anthroveUserID) != 25 {
return nil, &errors2.EntityValidationFailed{Reason: "anthroveUserID needs to be 25 characters long"}
}
err := db.WithContext(ctx).Model(&models.UserFavorites{}).Where("user_id = ?", string(anthroveUserID)).Offset(skip).Limit(limit).Find(&userFavorites).Error err := db.WithContext(ctx).Model(&models.UserFavorites{}).Where("user_id = ?", string(anthroveUserID)).Offset(skip).Limit(limit).Find(&userFavorites).Error
if err != nil { if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) { log.WithFields(log.Fields{
return nil, &errors2.NoDataFound{} "anthrove_user_id": anthroveUserID,
} "skip": skip,
"limit": limit,
}).Error("database: failed to get user favorites with pagination")
return nil, err return nil, err
} }
@ -281,9 +240,9 @@ func GetUserFavoriteWithPagination(ctx context.Context, db *gorm.DB, anthroveUse
var post models.Post var post models.Post
err = db.WithContext(ctx).Model(&models.Post{}).Where("id = ?", userFavorite.PostID).First(&post).Error err = db.WithContext(ctx).Model(&models.Post{}).Where("id = ?", userFavorite.PostID).First(&post).Error
if err != nil { if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) { log.WithFields(log.Fields{
return nil, &errors2.NoDataFound{} "post_id": userFavorite.PostID,
} }).Error("database: failed to get post")
return nil, err return nil, err
} }
@ -304,21 +263,12 @@ func GetUserFavoriteWithPagination(ctx context.Context, db *gorm.DB, anthroveUse
func GetUserTagWitRelationToFavedPosts(ctx context.Context, db *gorm.DB, anthroveUserID models.AnthroveUserID) ([]models.TagsWithFrequency, error) { func GetUserTagWitRelationToFavedPosts(ctx context.Context, db *gorm.DB, anthroveUserID models.AnthroveUserID) ([]models.TagsWithFrequency, error) {
var userFavorites []models.UserFavorites var userFavorites []models.UserFavorites
err := db.WithContext(ctx).Where("user_id = ?", string(anthroveUserID)).Find(&userFavorites).Error
if anthroveUserID == "" { if err != nil {
return nil, &errors2.EntityValidationFailed{Reason: "anthroveUserID cannot be empty"} log.WithFields(log.Fields{
} "anthrove_user_id": anthroveUserID,
}).Error("database: failed to get user favorites")
if len(anthroveUserID) != 25 { return nil, err
return nil, &errors2.EntityValidationFailed{Reason: "anthroveUserID needs to be 25 characters long"}
}
result := db.WithContext(ctx).Where("user_id = ?", string(anthroveUserID)).Find(&userFavorites)
if result.Error != nil {
if errors.Is(result.Error, gorm.ErrRecordNotFound) {
return nil, &errors2.NoDataFound{}
}
return nil, result.Error
} }
tagFrequency := make(map[struct { tagFrequency := make(map[struct {
@ -328,12 +278,12 @@ func GetUserTagWitRelationToFavedPosts(ctx context.Context, db *gorm.DB, anthrov
for _, userFavorite := range userFavorites { for _, userFavorite := range userFavorites {
var post models.Post var post models.Post
result = db.WithContext(ctx).Preload("Tags").First(&post, "id = ?", userFavorite.PostID) err = db.WithContext(ctx).Preload("Tags").First(&post, "id = ?", userFavorite.PostID).Error
if result.Error != nil { if err != nil {
if errors.Is(result.Error, gorm.ErrRecordNotFound) { log.WithFields(log.Fields{
return nil, &errors2.NoDataFound{} "post_id": userFavorite.PostID,
} }).Error("database: failed to get post tags")
return nil, result.Error return nil, err
} }
for _, tag := range post.Tags { for _, tag := range post.Tags {

View File

@ -21,9 +21,6 @@ func TestCreateUser(t *testing.T) {
// Setup Test // Setup Test
validUserID := models.AnthroveUserID(fmt.Sprintf("%025s", "User1"))
invalidUserID := models.AnthroveUserID("XXX")
// Test // Test
type args struct { type args struct {
ctx context.Context ctx context.Context
@ -40,7 +37,7 @@ func TestCreateUser(t *testing.T) {
args: args{ args: args{
ctx: ctx, ctx: ctx,
db: gormDB, db: gormDB,
anthroveUserID: validUserID, anthroveUserID: "1",
}, },
wantErr: false, wantErr: false,
}, },
@ -49,7 +46,7 @@ func TestCreateUser(t *testing.T) {
args: args{ args: args{
ctx: ctx, ctx: ctx,
db: gormDB, db: gormDB,
anthroveUserID: invalidUserID, anthroveUserID: "",
}, },
wantErr: true, wantErr: true,
}, },
@ -74,14 +71,9 @@ func TestCreateUserNodeWithSourceRelation(t *testing.T) {
// Setup Test // Setup Test
validUserID := models.AnthroveUserID(fmt.Sprintf("%025s", "User1"))
invalidUserID := models.AnthroveUserID("XXX")
validSourceID := models.AnthroveSourceID(fmt.Sprintf("%025s", "Source1"))
source := &models.Source{ source := &models.Source{
BaseModel: models.BaseModel[models.AnthroveSourceID]{ BaseModel: models.BaseModel[models.AnthroveSourceID]{
ID: validSourceID, ID: models.AnthroveSourceID(fmt.Sprintf("%025s", "1")),
}, },
DisplayName: "e621", DisplayName: "e621",
Domain: "e621.net", Domain: "e621.net",
@ -111,7 +103,7 @@ func TestCreateUserNodeWithSourceRelation(t *testing.T) {
args: args{ args: args{
ctx: ctx, ctx: ctx,
db: gormDB, db: gormDB,
anthroveUserID: validUserID, anthroveUserID: "1",
sourceID: source.ID, sourceID: source.ID,
userID: "e1", userID: "e1",
username: "marius", username: "marius",
@ -123,7 +115,7 @@ func TestCreateUserNodeWithSourceRelation(t *testing.T) {
args: args{ args: args{
ctx: ctx, ctx: ctx,
db: gormDB, db: gormDB,
anthroveUserID: invalidUserID, anthroveUserID: "2",
sourceID: source.ID, sourceID: source.ID,
userID: "e1", userID: "e1",
username: "marius", username: "marius",
@ -147,7 +139,7 @@ func TestCreateUserNodeWithSourceRelation(t *testing.T) {
args: args{ args: args{
ctx: ctx, ctx: ctx,
db: gormDB, db: gormDB,
anthroveUserID: validUserID, anthroveUserID: "1",
sourceID: "fa.net", sourceID: "fa.net",
userID: "e1", userID: "e1",
username: "marius", username: "marius",
@ -159,7 +151,7 @@ func TestCreateUserNodeWithSourceRelation(t *testing.T) {
args: args{ args: args{
ctx: ctx, ctx: ctx,
db: gormDB, db: gormDB,
anthroveUserID: validUserID, anthroveUserID: "1",
sourceID: source.ID, sourceID: source.ID,
userID: "", userID: "",
username: "marius", username: "marius",
@ -171,7 +163,7 @@ func TestCreateUserNodeWithSourceRelation(t *testing.T) {
args: args{ args: args{
ctx: ctx, ctx: ctx,
db: gormDB, db: gormDB,
anthroveUserID: validUserID, anthroveUserID: "1",
sourceID: source.ID, sourceID: source.ID,
userID: "aa", userID: "aa",
username: "", username: "",
@ -198,11 +190,8 @@ func TestGetAllAnthroveUserIDs(t *testing.T) {
defer container.Terminate(ctx) defer container.Terminate(ctx)
// Setup Test // Setup Test
validUserID01 := models.AnthroveUserID(fmt.Sprintf("%025s", "User1"))
validUserID02 := models.AnthroveUserID(fmt.Sprintf("%025s", "User2"))
validUserID03 := models.AnthroveUserID(fmt.Sprintf("%025s", "User3"))
users := []models.AnthroveUserID{validUserID01, validUserID02, validUserID03} users := []models.AnthroveUserID{"1", "2", "3"}
for _, user := range users { for _, user := range users {
err = CreateUser(ctx, gormDB, user) err = CreateUser(ctx, gormDB, user)
@ -257,9 +246,6 @@ func TestGetUserSourceBySourceID(t *testing.T) {
// Setup Test // Setup Test
validUserID := models.AnthroveUserID(fmt.Sprintf("%025s", "User1"))
invalidUserID := models.AnthroveUserID("XXX")
expectedResult := make(map[string]models.UserSource) expectedResult := make(map[string]models.UserSource)
expectedResult["e621"] = models.UserSource{ expectedResult["e621"] = models.UserSource{
UserID: "e1", UserID: "e1",
@ -283,7 +269,7 @@ func TestGetUserSourceBySourceID(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
err = CreateUserWithRelationToSource(ctx, gormDB, validUserID, models.AnthroveSourceID(expectedResult["e621"].SourceID), expectedResult["e621"].UserID, expectedResult["e621"].AccountUsername) err = CreateUserWithRelationToSource(ctx, gormDB, "1", models.AnthroveSourceID(expectedResult["e621"].SourceID), expectedResult["e621"].UserID, expectedResult["e621"].AccountUsername)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -306,7 +292,7 @@ func TestGetUserSourceBySourceID(t *testing.T) {
args: args{ args: args{
ctx: ctx, ctx: ctx,
db: gormDB, db: gormDB,
anthroveUserID: validUserID, anthroveUserID: "1",
sourceID: source.ID, sourceID: source.ID,
}, },
want: expectedResult, want: expectedResult,
@ -317,7 +303,7 @@ func TestGetUserSourceBySourceID(t *testing.T) {
args: args{ args: args{
ctx: ctx, ctx: ctx,
db: gormDB, db: gormDB,
anthroveUserID: invalidUserID, anthroveUserID: "22",
sourceID: source.ID, sourceID: source.ID,
}, },
want: nil, want: nil,
@ -328,7 +314,7 @@ func TestGetUserSourceBySourceID(t *testing.T) {
args: args{ args: args{
ctx: ctx, ctx: ctx,
db: gormDB, db: gormDB,
anthroveUserID: validUserID, anthroveUserID: "1",
sourceID: "fa", sourceID: "fa",
}, },
want: nil, want: nil,
@ -382,8 +368,6 @@ func TestGetUserSourceBySourceID(t *testing.T) {
} }
} }
// TODO: FIX THE FOUR REMAINING TESTS
func TestGetUserFavoriteNodeWithPagination(t *testing.T) { func TestGetUserFavoriteNodeWithPagination(t *testing.T) {
// Setup trow away containert // Setup trow away containert
ctx := context.Background() ctx := context.Background()

View File

@ -1,11 +0,0 @@
package errors
import "fmt"
type EntityValidationFailed struct {
Reason string
}
func (e EntityValidationFailed) Error() string {
return fmt.Sprintf("Entity validation failed: %s", e.Reason)
}