diff --git a/internal/postgres/relationships.go b/internal/postgres/relationships.go index b3170d4..1a07396 100644 --- a/internal/postgres/relationships.go +++ b/internal/postgres/relationships.go @@ -37,3 +37,22 @@ func EstablishAnthrovePostToSourceLink(ctx context.Context, db *gorm.DB, anthrov return nil } + +func EstablishUserToPostLink(ctx context.Context, db *gorm.DB, anthroveUserID models.AnthroveUserID, anthrovePostID models.AnthrovePostID) error { + userFavorite := pgModels.UserFavorite{ + UserID: string(anthroveUserID), + PostID: string(anthrovePostID), + } + + err := db.WithContext(ctx).Create(&userFavorite).Error + if err != nil { + return err + } + + log.WithFields(log.Fields{ + "anthrove_user_id": anthroveUserID, + "anthrove_post_id": anthrovePostID, + }).Trace("database: created user to post link") + + return nil +} diff --git a/pkg/database/postgres.go b/pkg/database/postgres.go index bd57a64..a4a9008 100644 --- a/pkg/database/postgres.go +++ b/pkg/database/postgres.go @@ -77,8 +77,7 @@ func (p *postgresqlConnection) LinkPostWithSource(ctx context.Context, anthroveP } func (p *postgresqlConnection) LinkUserWithPost(ctx context.Context, anthroveUser *graphModels.AnthroveUser, anthrovePost *graphModels.AnthrovePost) error { - //TODO implement me - panic("implement me") + return postgres.EstablishUserToPostLink(ctx, p.db, anthroveUser.UserID, anthrovePost.PostID) } func (p *postgresqlConnection) CheckUserPostLink(ctx context.Context, anthroveUserID models.AnthroveUserID, sourcePostID string, sourceUrl string) (bool, error) {