diff --git a/internal/postgres/user.go b/internal/postgres/user.go index f24191d..acd9695 100644 --- a/internal/postgres/user.go +++ b/internal/postgres/user.go @@ -59,3 +59,21 @@ func CreateUserNodeWithSourceRelation(ctx context.Context, db *gorm.DB, anthrove return nil } + +func GetUserFavoritesCount(ctx context.Context, db *gorm.DB, anthroveUserID models.AnthroveUserID) (int64, error) { + var count int64 + err := db.WithContext(ctx).Model(&pgModels.UserFavorite{}).Where("user_id = ?", string(anthroveUserID)).Count(&count).Error + if err != nil { + log.WithFields(log.Fields{ + "anthrove_user_id": anthroveUserID, + }).Error("database: failed to get user favorites count") + return 0, err + } + + log.WithFields(log.Fields{ + "anthrove_user_id": anthroveUserID, + "anthrove_user_fav_count": count, + }).Trace("database: got user favorite count") + + return count, nil +} diff --git a/pkg/database/postgres.go b/pkg/database/postgres.go index 13fe10d..883de13 100644 --- a/pkg/database/postgres.go +++ b/pkg/database/postgres.go @@ -102,8 +102,7 @@ func (p *postgresqlConnection) CheckPostNodeExistsBySourceID(ctx context.Context } func (p *postgresqlConnection) GetUserFavoriteCount(ctx context.Context, anthroveUserID models.AnthroveUserID) (int64, error) { - //TODO implement me - panic("implement me") + return postgres.GetUserFavoritesCount(ctx, p.db, anthroveUserID) } func (p *postgresqlConnection) GetUserSourceLinks(ctx context.Context, anthroveUserID models.AnthroveUserID) (map[string]graphModels.AnthroveUserRelationship, error) {