chore: refactoring some code to introduce a common base class for all api classes
This commit is contained in:
49
src/ClientContacts/ClientContactsApi.cs
Normal file
49
src/ClientContacts/ClientContactsApi.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Novaloop.PaymoApi.ClientContacts.Models;
|
||||
using Novaloop.PaymoApi.Shared;
|
||||
|
||||
namespace Novaloop.PaymoApi.ClientContacts
|
||||
{
|
||||
public class ClientContactsApi : IClientContactsApi
|
||||
{
|
||||
private readonly IBaseApi<GetClientContactsResponse, ClientContact> _baseApi;
|
||||
|
||||
public ClientContactsApi(IBaseApi<GetClientContactsResponse, ClientContact> baseApi)
|
||||
{
|
||||
_baseApi = baseApi;
|
||||
_baseApi.ResourceUri = "clientcontacts";
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<IEnumerable<ClientContact>> GetClientContacts()
|
||||
{
|
||||
return (await _baseApi.GetAll()).ClientContacts;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<ClientContact> GetClientContact(int clientContactId)
|
||||
{
|
||||
return (await _baseApi.Get(clientContactId)).ClientContacts.Single();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<ClientContact> CreateClientContact(ClientContact clientContact)
|
||||
{
|
||||
return (await _baseApi.Create(clientContact)).ClientContacts.Single();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task DeleteClientContact(int clientContactId)
|
||||
{
|
||||
await _baseApi.Delete(clientContactId);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task UpdateClientContact(ClientContact clientContact, int clientContactId)
|
||||
{
|
||||
await _baseApi.Update(clientContact, clientContactId);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user