From 6268a594cf7cace2e110fd7ab08e93cdc05cab76 Mon Sep 17 00:00:00 2001 From: soxx Date: Fri, 14 Jun 2024 15:09:11 +0200 Subject: [PATCH] feat(postgres): added GetAllAnthroveUserIDs --- internal/postgres/user.go | 21 +++++++++++++++++++++ pkg/database/postgres.go | 3 +-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/internal/postgres/user.go b/internal/postgres/user.go index d250f1f..f149d14 100644 --- a/internal/postgres/user.go +++ b/internal/postgres/user.go @@ -211,3 +211,24 @@ func GetAnthroveUser(ctx context.Context, db *gorm.DB, anthroveUserID models.Ant return anthroveUser, nil } + +func GetAllAnthroveUserIDs(ctx context.Context, db *gorm.DB) ([]models.AnthroveUserID, error) { + var users []pgModels.User + var userIDs []models.AnthroveUserID + + err := db.WithContext(ctx).Model(&pgModels.User{}).Find(&users).Error + if err != nil { + log.Error("database: failed to get all anthrove user IDs") + return nil, err + } + + for _, user := range users { + userIDs = append(userIDs, models.AnthroveUserID(user.ID)) + } + + log.WithFields(log.Fields{ + "anthrove_user_id_count": len(userIDs), + }).Trace("database: got all anthrove user IDs") + + return userIDs, nil +} diff --git a/pkg/database/postgres.go b/pkg/database/postgres.go index eea7600..7395bdf 100644 --- a/pkg/database/postgres.go +++ b/pkg/database/postgres.go @@ -118,8 +118,7 @@ func (p *postgresqlConnection) GetAnthroveUser(ctx context.Context, anthroveUser } func (p *postgresqlConnection) GetAllAnthroveUserIDs(ctx context.Context) ([]models.AnthroveUserID, error) { - //TODO implement me - panic("implement me") + return postgres.GetAllAnthroveUserIDs(ctx, p.db) } func (p *postgresqlConnection) GetUserFavoritePostsWithPagination(ctx context.Context, anthroveUserID models.AnthroveUserID, skip int, limit int) (*graphModels.FavoriteList, error) {