jeudi 28 janvier 2016

Should a respository be responsible to update specified field of model stored in external service?

I understand that the repository should be responsible for CRUD in repository pattern. My question is: should a respository be responsible to update specified field of model stored in external service?

For example:

  • The UserAccount data is stored in external web service.
  • The user could have multiple UserAccount
  • By the app, the user can select target UserAccount and can update displayName of UserAccount
  • There are some words not allowed to use in displayName and the app doesn't know what are those words.

pesdocode:

public class MainController
{
    IUserAccountService userAccountService; // injected

    public void Main ()
    {
        userAccountService.GetUsers ().Then (UpdateUserView);
    }

    // ...

    void OnUserAccountSelected (UserAccount selectedUserAccount, string newDisplayName)
    {
        userAccountService.UpdateDisplayName (selectedUserAccount, newDisplayName)
        .Then (UpdateUserView)
        .Catch<WordInDisplayNameNotAllowedException> (HandleWordInDisplayNameNotAllowedException)
        .Catch (HandleError);
    }
}

public class UserAccountService : IUserAccountSercie
{
    IUserAccountRepository repository; // injected

    // ...

    public Promise<UserList> GetUsers ()
    {
        return repository.GetAll ();
    }

    public UpdateDisplayName (UserAccount userAccount, string newDisplayName)
    {
        // Should I like the following?
        repository.UpdateDisplayName (userAccount, newDisplayName);
    }
}

public class UserAccountRepository : IUserAccountRepository
{
    public Promise<UserList> GetAll ()
    {
        // request to external web service...
    }

    public Promise<UserAccount> UpdateDisplayName (UserAccount userAccount, string newDisplayName)
    {
        // request to external web service...
    }
}

Where should I put codes to call web API to update UserAccount::displayName?

Aucun commentaire:

Enregistrer un commentaire