BREAKING CHANGE: V2 of thr SDK #12
@ -160,3 +160,54 @@ func GetSpecifiedUserSourceLink(ctx context.Context, db *gorm.DB, anthroveUserID
|
||||
|
||||
return userSourceMap, nil
|
||||
}
|
||||
|
||||
func GetAnthroveUser(ctx context.Context, db *gorm.DB, anthroveUserID models.AnthroveUserID) (*graphModels.AnthroveUser, error) {
|
||||
var user pgModels.User
|
||||
var userSources []pgModels.UserSource
|
||||
anthroveUser := &graphModels.AnthroveUser{
|
||||
UserID: anthroveUserID,
|
||||
}
|
||||
|
||||
err := db.WithContext(ctx).First(&user, "id = ?", string(anthroveUserID)).Error
|
||||
if err != nil {
|
||||
log.WithFields(log.Fields{
|
||||
"anthrove_user_id": anthroveUserID,
|
||||
}).Error("database: failed to get user")
|
||||
return nil, err
|
||||
}
|
||||
|
||||
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 sources")
|
||||
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
|
||||
}
|
||||
|
||||
anthroveUser.Relationship = append(anthroveUser.Relationship, 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 anthrove user")
|
||||
|
||||
return anthroveUser, nil
|
||||
}
|
||||
|
@ -114,8 +114,7 @@ func (p *postgresqlConnection) GetSpecifiedUserSourceLink(ctx context.Context, a
|
||||
}
|
||||
|
||||
func (p *postgresqlConnection) GetAnthroveUser(ctx context.Context, anthroveUserID models.AnthroveUserID) (*graphModels.AnthroveUser, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
return postgres.GetAnthroveUser(ctx, p.db, anthroveUserID)
|
||||
}
|
||||
|
||||
func (p *postgresqlConnection) GetAllAnthroveUserIDs(ctx context.Context) ([]models.AnthroveUserID, error) {
|
||||
|
Reference in New Issue
Block a user