feat(postgres): added GetUserSourceLinks
This commit is contained in:
parent
4f8e54f09a
commit
16d5a381df
@ -3,6 +3,7 @@ package postgres
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"git.dragse.it/anthrove/otter-space-sdk/pkg/models"
|
"git.dragse.it/anthrove/otter-space-sdk/pkg/models"
|
||||||
|
"git.dragse.it/anthrove/otter-space-sdk/pkg/models/graphModels"
|
||||||
"git.dragse.it/anthrove/otter-space-sdk/pkg/models/pgModels"
|
"git.dragse.it/anthrove/otter-space-sdk/pkg/models/pgModels"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
@ -77,3 +78,43 @@ func GetUserFavoritesCount(ctx context.Context, db *gorm.DB, anthroveUserID mode
|
|||||||
|
|
||||||
return count, nil
|
return count, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetUserSourceLink(ctx context.Context, db *gorm.DB, anthroveUserID models.AnthroveUserID) (map[string]graphModels.AnthroveUserRelationship, error) {
|
||||||
|
var userSources []pgModels.UserSource
|
||||||
|
userSourceMap := make(map[string]graphModels.AnthroveUserRelationship)
|
||||||
|
|
||||||
|
err := db.WithContext(ctx).Model(&pgModels.UserSource{}).Where("user_id = ?", string(anthroveUserID)).Find(&userSources).Error
|
||||||
|
if err != nil {
|
||||||
|
log.WithFields(log.Fields{
|
||||||
|
"anthrove_user_id": anthroveUserID,
|
||||||
|
}).Error("database: failed to get user source link")
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, userSource := range userSources {
|
||||||
|
var source pgModels.Source
|
||||||
|
err = db.WithContext(ctx).Model(&pgModels.Source{}).Where("id = ?", userSource.SourceID).First(&source).Error
|
||||||
|
if err != nil {
|
||||||
|
log.WithFields(log.Fields{
|
||||||
|
"source_id": userSource.SourceID,
|
||||||
|
}).Error("database: failed to get source")
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
userSourceMap[source.DisplayName] = graphModels.AnthroveUserRelationship{
|
||||||
|
UserID: userSource.AccountID,
|
||||||
|
Username: userSource.AccountUsername,
|
||||||
|
Source: graphModels.AnthroveSource{
|
||||||
|
DisplayName: source.DisplayName,
|
||||||
|
Domain: source.Domain,
|
||||||
|
Icon: source.Icon,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
log.WithFields(log.Fields{
|
||||||
|
"anthrove_user_id": anthroveUserID,
|
||||||
|
}).Trace("database: got user source link")
|
||||||
|
|
||||||
|
return userSourceMap, nil
|
||||||
|
}
|
||||||
|
@ -106,8 +106,7 @@ func (p *postgresqlConnection) GetUserFavoriteCount(ctx context.Context, anthrov
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *postgresqlConnection) GetUserSourceLinks(ctx context.Context, anthroveUserID models.AnthroveUserID) (map[string]graphModels.AnthroveUserRelationship, error) {
|
func (p *postgresqlConnection) GetUserSourceLinks(ctx context.Context, anthroveUserID models.AnthroveUserID) (map[string]graphModels.AnthroveUserRelationship, error) {
|
||||||
//TODO implement me
|
return postgres.GetUserSourceLink(ctx, p.db, anthroveUserID)
|
||||||
panic("implement me")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *postgresqlConnection) GetSpecifiedUserSourceLink(ctx context.Context, anthroveUserID models.AnthroveUserID, sourceDisplayName string) (map[string]graphModels.AnthroveUserRelationship, error) {
|
func (p *postgresqlConnection) GetSpecifiedUserSourceLink(ctx context.Context, anthroveUserID models.AnthroveUserID, sourceDisplayName string) (map[string]graphModels.AnthroveUserRelationship, error) {
|
||||||
|
Reference in New Issue
Block a user