fix: fixed function to work properly
Some checks failed
Gitea Build Check / Build (pull_request) Failing after 6m32s
Gitea Build Check / Build (push) Failing after 6m28s

Signed-off-by: SoXX <soxx@fenpa.ws>
This commit is contained in:
SoXX 2024-07-01 22:40:53 +02:00
parent 2d4102be6a
commit 768203ebd7
3 changed files with 33 additions and 3 deletions

View File

@ -69,7 +69,7 @@ func GetAllTagByTagsType(ctx context.Context, db *gorm.DB, tagType models.TagTyp
return nil, &otterError.EntityValidationFailed{Reason: "tagType cannot be empty"} return nil, &otterError.EntityValidationFailed{Reason: "tagType cannot be empty"}
} }
result := db.WithContext(ctx).Find(&tags).Where("tag_type = ?", tagType) result := db.WithContext(ctx).Model(&models.Tag{}).Where("tag_type = ?", tagType).Scan(&tags)
if result.Error != nil { if result.Error != nil {
if errors.Is(result.Error, gorm.ErrRecordNotFound) { if errors.Is(result.Error, gorm.ErrRecordNotFound) {

View File

@ -1050,6 +1050,21 @@ func TestGetAllTagByTagType(t *testing.T) {
}, },
} }
expectetResult := []models.Tag{
{
Name: "JayTheFerret",
Type: models.Character,
},
{
Name: "SoXX",
Type: models.Character,
},
{
Name: "Alphyron",
Type: models.Character,
},
}
for _, tag := range validTags { for _, tag := range validTags {
err = CreateTag(ctx, gormDB, models.AnthroveTagName(tag.Name), tag.Type) err = CreateTag(ctx, gormDB, models.AnthroveTagName(tag.Name), tag.Type)
if err != nil { if err != nil {
@ -1076,7 +1091,7 @@ func TestGetAllTagByTagType(t *testing.T) {
db: gormDB, db: gormDB,
tagType: models.Character, tagType: models.Character,
}, },
want: validTags, want: expectetResult,
wantErr: false, wantErr: false,
}, },
{ {

View File

@ -3174,6 +3174,21 @@ func Test_postgresqlConnection_GetAllTagsByTagType(t *testing.T) {
}, },
} }
expectetResult := []models.Tag{
{
Name: "JayTheFerret",
Type: models.Character,
},
{
Name: "SoXX",
Type: models.Character,
},
{
Name: "Alphyron",
Type: models.Character,
},
}
for _, tag := range validTags { for _, tag := range validTags {
err = postgres.CreateTag(ctx, gormDB, models.AnthroveTagName(tag.Name), tag.Type) err = postgres.CreateTag(ctx, gormDB, models.AnthroveTagName(tag.Name), tag.Type)
if err != nil { if err != nil {
@ -3198,7 +3213,7 @@ func Test_postgresqlConnection_GetAllTagsByTagType(t *testing.T) {
ctx: ctx, ctx: ctx,
tagType: models.Character, tagType: models.Character,
}, },
want: validTags, want: expectetResult,
wantErr: false, wantErr: false,
}, },
{ {