feat(postgres): added GetSpecifiedUserSourceLink
This commit is contained in:
parent
16d5a381df
commit
bbd08b9a2f
@ -118,3 +118,45 @@ func GetUserSourceLink(ctx context.Context, db *gorm.DB, anthroveUserID models.A
|
|||||||
|
|
||||||
return userSourceMap, nil
|
return userSourceMap, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetSpecifiedUserSourceLink(ctx context.Context, db *gorm.DB, anthroveUserID models.AnthroveUserID, sourceDisplayName string) (map[string]graphModels.AnthroveUserRelationship, error) {
|
||||||
|
var userSources []pgModels.UserSource
|
||||||
|
userSourceMap := make(map[string]graphModels.AnthroveUserRelationship)
|
||||||
|
|
||||||
|
err := db.WithContext(ctx).Model(&pgModels.UserSource{}).Joins("Source").Where("user_id = ? AND display_name = ?", string(anthroveUserID), sourceDisplayName).Find(&userSources).Error
|
||||||
|
if err != nil {
|
||||||
|
log.WithFields(log.Fields{
|
||||||
|
"anthrove_user_id": anthroveUserID,
|
||||||
|
"source_display_name": sourceDisplayName,
|
||||||
|
}).Error("database: failed to get specified 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,
|
||||||
|
"source_display_name": sourceDisplayName,
|
||||||
|
}).Trace("database: got specified user source link")
|
||||||
|
|
||||||
|
return userSourceMap, nil
|
||||||
|
}
|
||||||
|
@ -110,8 +110,7 @@ func (p *postgresqlConnection) GetUserSourceLinks(ctx context.Context, anthroveU
|
|||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
//TODO implement me
|
return postgres.GetSpecifiedUserSourceLink(ctx, p.db, anthroveUserID, sourceDisplayName)
|
||||||
panic("implement me")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *postgresqlConnection) GetAnthroveUser(ctx context.Context, anthroveUserID models.AnthroveUserID) (*graphModels.AnthroveUser, error) {
|
func (p *postgresqlConnection) GetAnthroveUser(ctx context.Context, anthroveUserID models.AnthroveUserID) (*graphModels.AnthroveUser, error) {
|
||||||
|
Reference in New Issue
Block a user