diff --git a/internal/postgres/relationships.go b/internal/postgres/relationships.go index 5e03a12..e0d6e3e 100644 --- a/internal/postgres/relationships.go +++ b/internal/postgres/relationships.go @@ -62,7 +62,7 @@ func CreateReferenceBetweenUserAndPost(ctx context.Context, db *gorm.DB, anthrov return &otterError.EntityValidationFailed{Reason: "anthroveUserID cannot be empty"} } - userFavorite := models.UserFavorites{ + userFavorite := models.UserFavorite{ UserID: string(anthroveUserID), PostID: string(anthrovePostID), } @@ -106,7 +106,7 @@ func CheckReferenceBetweenUserAndPost(ctx context.Context, db *gorm.DB, anthrove return false, &otterError.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) + result := db.WithContext(ctx).Model(&models.UserFavorite{}).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, &otterError.NoDataFound{} diff --git a/internal/postgres/user.go b/internal/postgres/user.go index 45a847a..625e285 100644 --- a/internal/postgres/user.go +++ b/internal/postgres/user.go @@ -113,7 +113,7 @@ func GetUserFavoritesCount(ctx context.Context, db *gorm.DB, anthroveUserID mode return 0, &otterError.EntityValidationFailed{Reason: otterError.AnthroveUserIDToShort} } - result := db.WithContext(ctx).Model(&models.UserFavorites{}).Where("user_id = ?", string(anthroveUserID)).Count(&count) + result := db.WithContext(ctx).Model(&models.UserFavorite{}).Where("user_id = ?", string(anthroveUserID)).Count(&count) if result.Error != nil { if errors.Is(result.Error, gorm.ErrRecordNotFound) { return 0, &otterError.NoDataFound{} @@ -242,7 +242,7 @@ func GetUserFavoriteWithPagination(ctx context.Context, db *gorm.DB, anthroveUse return nil, &otterError.EntityValidationFailed{Reason: otterError.AnthroveUserIDToShort} } - db.WithContext(ctx).Joins("RIGHT JOIN \"UserFavorites\" AS of ON \"Post\".id = of.post_id AND of.user_id = ?", anthroveUserID).Preload("References").Offset(skip).Limit(limit).Find(&favoritePosts) + db.WithContext(ctx).Joins("RIGHT JOIN \"UserFavorite\" AS of ON \"Post\".id = of.post_id AND of.user_id = ?", anthroveUserID).Preload("References").Offset(skip).Limit(limit).Find(&favoritePosts) log.WithFields(log.Fields{ "anthrove_user_id": anthroveUserID, @@ -265,7 +265,7 @@ func GetUserTagWitRelationToFavedPosts(ctx context.Context, db *gorm.DB, anthrov rows, err := db.WithContext(ctx).Raw( `WITH user_posts AS ( - SELECT post_id FROM "UserFavorites" WHERE user_id = $1 + SELECT post_id FROM "UserFavorite" WHERE user_id = $1 ) SELECT post_tags.tag_name AS tag_name, count(*) AS count, (SELECT tag_type FROM "Tag" WHERE "Tag".name = post_tags.tag_name LIMIT 1) AS tag_type FROM post_tags, user_posts WHERE post_tags.post_id IN (user_posts.post_id) GROUP BY post_tags.tag_name ORDER BY tag_type DESC, tag_name DESC`, anthroveUserID).Rows() if err != nil { diff --git a/pkg/models/post.go b/pkg/models/post.go index 8b24e60..0d0dda3 100644 --- a/pkg/models/post.go +++ b/pkg/models/post.go @@ -5,7 +5,7 @@ type Post struct { BaseModel[PostID] Rating Rating `json:"rating" gorm:"type:enum('safe','questionable','explicit')"` Tags []Tag `json:"-" gorm:"many2many:post_tags;"` - Favorites []UserFavorites `json:"-" gorm:"foreignKey:PostID"` + Favorites []UserFavorite `json:"-" gorm:"foreignKey:PostID"` References []PostReference `json:"references" gorm:"foreignKey:PostID"` } diff --git a/pkg/models/post_test.go b/pkg/models/post_test.go index 7c6856f..b4c856e 100644 --- a/pkg/models/post_test.go +++ b/pkg/models/post_test.go @@ -7,7 +7,7 @@ func TestPost_TableName(t *testing.T) { BaseModel BaseModel[PostID] Rating Rating Tags []Tag - Favorites []UserFavorites + Favorites []UserFavorite References []PostReference } tests := []struct { diff --git a/pkg/models/user.go b/pkg/models/user.go index e2a88c1..bf544ce 100644 --- a/pkg/models/user.go +++ b/pkg/models/user.go @@ -3,8 +3,8 @@ package models // User model type User struct { BaseModel[UserID] - Favorites []UserFavorites `json:"-" gorm:"foreignKey:UserID"` - Sources []UserSource `json:"-" gorm:"foreignKey:UserID"` + Favorites []UserFavorite `json:"-" gorm:"foreignKey:UserID"` + Sources []UserSource `json:"-" gorm:"foreignKey:UserID"` } func (User) TableName() string { diff --git a/pkg/models/userFavorite_test.go b/pkg/models/userFavorite_test.go index 3b69143..5a09532 100644 --- a/pkg/models/userFavorite_test.go +++ b/pkg/models/userFavorite_test.go @@ -17,14 +17,14 @@ func TestUserFavorite_TableName(t *testing.T) { want string }{ { - name: "Test 1: Is name UserFavorites", + name: "Test 1: Is name UserFavorite", fields: fields{}, - want: "UserFavorites", + want: "UserFavorite", }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - us := UserFavorites{ + us := UserFavorite{ UserID: tt.fields.UserID, PostID: tt.fields.PostID, CreatedAt: tt.fields.CreatedAt, diff --git a/pkg/models/user_test.go b/pkg/models/user_test.go index 34db57f..09d3f2f 100644 --- a/pkg/models/user_test.go +++ b/pkg/models/user_test.go @@ -5,7 +5,7 @@ import "testing" func TestUser_TableName(t *testing.T) { type fields struct { BaseModel BaseModel[UserID] - Favorites []UserFavorites + Favorites []UserFavorite Sources []UserSource } tests := []struct {