checkpoint: updated add and remove
This commit is contained in:
parent
8cffac2074
commit
22b47e4b40
3 changed files with 39 additions and 18 deletions
|
@ -9,7 +9,12 @@ import (
|
||||||
"codeflow.dananglin.me.uk/apollo/enbas/internal/model"
|
"codeflow.dananglin.me.uk/apollo/enbas/internal/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
func getAccountID(gtsClient *client.Client, myAccount bool, accountNames internalFlag.StringSliceValue, credentialsFile string) (string, error) {
|
func getAccountID(
|
||||||
|
gtsClient *client.Client,
|
||||||
|
myAccount bool,
|
||||||
|
accountNames internalFlag.StringSliceValue,
|
||||||
|
credentialsFile string,
|
||||||
|
) (string, error) {
|
||||||
account, err := getAccount(gtsClient, myAccount, accountNames, credentialsFile)
|
account, err := getAccount(gtsClient, myAccount, accountNames, credentialsFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("unable to get the account information: %w", err)
|
return "", fmt.Errorf("unable to get the account information: %w", err)
|
||||||
|
@ -79,3 +84,19 @@ func getOtherAccount(gtsClient *client.Client, accountNames internalFlag.StringS
|
||||||
|
|
||||||
return account, nil
|
return account, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getOtherAccounts(gtsClient *client.Client, accountNames internalFlag.StringSliceValue) ([]model.Account, error) {
|
||||||
|
numAccountNames := len(accountNames)
|
||||||
|
accounts := make([]model.Account, numAccountNames)
|
||||||
|
|
||||||
|
for ind := 0; ind < numAccountNames; ind++ {
|
||||||
|
var err error
|
||||||
|
|
||||||
|
accounts[ind], err = gtsClient.GetAccount(accountNames[ind])
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("unable to retrieve the account information for %s: %w", accountNames[ind], err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return accounts, nil
|
||||||
|
}
|
||||||
|
|
|
@ -58,24 +58,24 @@ func (a *AddExecutor) addAccountsToList(gtsClient *client.Client) error {
|
||||||
return NoAccountSpecifiedError{}
|
return NoAccountSpecifiedError{}
|
||||||
}
|
}
|
||||||
|
|
||||||
accountIDs := make([]string, len(a.accountNames))
|
accounts, err := getOtherAccounts(gtsClient, a.accountNames)
|
||||||
|
|
||||||
for ind := range a.accountNames {
|
|
||||||
accountID, err := getTheirAccountID(gtsClient, a.accountNames[ind])
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to get the account ID for %s: %w", a.accountNames[ind], err)
|
return fmt.Errorf("unable to get the accounts: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
relationship, err := gtsClient.GetAccountRelationship(accountID)
|
accountIDs := make([]string, len(accounts))
|
||||||
|
|
||||||
|
for ind := range accounts {
|
||||||
|
relationship, err := gtsClient.GetAccountRelationship(accounts[ind].ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to get your relationship to %s: %w", a.accountNames[ind], err)
|
return fmt.Errorf("unable to get your relationship to %s: %w", accounts[ind].Acct, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !relationship.Following {
|
if !relationship.Following {
|
||||||
return NotFollowingError{Account: a.accountNames[ind]}
|
return NotFollowingError{Account: accounts[ind].Acct}
|
||||||
}
|
}
|
||||||
|
|
||||||
accountIDs[ind] = accountID
|
accountIDs[ind] = accounts[ind].ID
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := gtsClient.AddAccountsToList(a.listID, accountIDs); err != nil {
|
if err := gtsClient.AddAccountsToList(a.listID, accountIDs); err != nil {
|
||||||
|
|
|
@ -56,15 +56,15 @@ func (r *RemoveExecutor) removeAccountsFromList(gtsClient *client.Client) error
|
||||||
return NoAccountSpecifiedError{}
|
return NoAccountSpecifiedError{}
|
||||||
}
|
}
|
||||||
|
|
||||||
accountIDs := make([]string, len(r.accountNames))
|
accounts, err := getOtherAccounts(gtsClient, r.accountNames)
|
||||||
|
|
||||||
for ind := range r.accountNames {
|
|
||||||
accountID, err := getTheirAccountID(gtsClient, r.accountNames[ind])
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to get the account ID for %s: %w", r.accountNames[ind], err)
|
return fmt.Errorf("unable to get the accounts: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
accountIDs[ind] = accountID
|
accountIDs := make([]string, len(accounts))
|
||||||
|
|
||||||
|
for ind := range accounts {
|
||||||
|
accountIDs[ind] = accounts[ind].ID
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := gtsClient.RemoveAccountsFromList(r.listID, accountIDs); err != nil {
|
if err := gtsClient.RemoveAccountsFromList(r.listID, accountIDs); err != nil {
|
||||||
|
|
Loading…
Reference in a new issue