feat: add Contacts & Setup controllers, extend Clients/Invoices/Document controllers
- ContactsController: full CRUD (list, get, get by email, create, update, delete)
- SetupController: dictionary endpoints (payment-types, countries, civilities,
contact-types, payment-terms, company)
- ClientsController: added GET/{id}, POST, PUT/{id}, DELETE/{id}
- InvoicesController: added PUT/{id}/lines/{lineId}, GET /templates
- DocumentController: added GET /list and GET /download endpoints
- ClientService: added GetClientAsync, CreateClientAsync, UpdateClientAsync,
DeleteClientAsync
- InvoiceService: added UpdateInvoiceLineAsync, GetInvoiceTemplatesAsync
- DocumentService: added GetDocumentsAsync, DownloadDocumentAsync (using
new GetAsyncRaw on IDolibarrApiClient)
- ContactService: new service with CRUD operations
- SetupService: new service for Dolibarr dictionary data
- IDolibarrApiClient: added GetAsyncRaw method for raw string responses
- DolibarrApiClient: implemented GetAsyncRaw
- JwtTokenProvider: extended token expiry from 30 min to 8 hours
- AuthApplicationService: extended Dolibarr token cache from 30 min to 8 hours
2026-05-15 16:58:35 +00:00
|
|
|
using DoliMiddlewareApi.Dtos.command;
|
2026-01-30 15:34:23 +00:00
|
|
|
using DoliMiddlewareApi.Dtos.Dolibarr;
|
|
|
|
|
using DoliMiddlewareApi.Dtos.query;
|
feat: add Contacts & Setup controllers, extend Clients/Invoices/Document controllers
- ContactsController: full CRUD (list, get, get by email, create, update, delete)
- SetupController: dictionary endpoints (payment-types, countries, civilities,
contact-types, payment-terms, company)
- ClientsController: added GET/{id}, POST, PUT/{id}, DELETE/{id}
- InvoicesController: added PUT/{id}/lines/{lineId}, GET /templates
- DocumentController: added GET /list and GET /download endpoints
- ClientService: added GetClientAsync, CreateClientAsync, UpdateClientAsync,
DeleteClientAsync
- InvoiceService: added UpdateInvoiceLineAsync, GetInvoiceTemplatesAsync
- DocumentService: added GetDocumentsAsync, DownloadDocumentAsync (using
new GetAsyncRaw on IDolibarrApiClient)
- ContactService: new service with CRUD operations
- SetupService: new service for Dolibarr dictionary data
- IDolibarrApiClient: added GetAsyncRaw method for raw string responses
- DolibarrApiClient: implemented GetAsyncRaw
- JwtTokenProvider: extended token expiry from 30 min to 8 hours
- AuthApplicationService: extended Dolibarr token cache from 30 min to 8 hours
2026-05-15 16:58:35 +00:00
|
|
|
using DoliMiddlewareApi.Exceptions;
|
2026-01-30 15:34:23 +00:00
|
|
|
using DoliMiddlewareApi.Mappers;
|
|
|
|
|
using DoliMiddlewareApi.Services.Clients;
|
|
|
|
|
|
|
|
|
|
namespace DoliMiddlewareApi.Services;
|
|
|
|
|
|
feat: add Contacts & Setup controllers, extend Clients/Invoices/Document controllers
- ContactsController: full CRUD (list, get, get by email, create, update, delete)
- SetupController: dictionary endpoints (payment-types, countries, civilities,
contact-types, payment-terms, company)
- ClientsController: added GET/{id}, POST, PUT/{id}, DELETE/{id}
- InvoicesController: added PUT/{id}/lines/{lineId}, GET /templates
- DocumentController: added GET /list and GET /download endpoints
- ClientService: added GetClientAsync, CreateClientAsync, UpdateClientAsync,
DeleteClientAsync
- InvoiceService: added UpdateInvoiceLineAsync, GetInvoiceTemplatesAsync
- DocumentService: added GetDocumentsAsync, DownloadDocumentAsync (using
new GetAsyncRaw on IDolibarrApiClient)
- ContactService: new service with CRUD operations
- SetupService: new service for Dolibarr dictionary data
- IDolibarrApiClient: added GetAsyncRaw method for raw string responses
- DolibarrApiClient: implemented GetAsyncRaw
- JwtTokenProvider: extended token expiry from 30 min to 8 hours
- AuthApplicationService: extended Dolibarr token cache from 30 min to 8 hours
2026-05-15 16:58:35 +00:00
|
|
|
public class ClientService(IDolibarrApiClient apiClient)
|
2026-01-30 15:34:23 +00:00
|
|
|
{
|
feat: add Contacts & Setup controllers, extend Clients/Invoices/Document controllers
- ContactsController: full CRUD (list, get, get by email, create, update, delete)
- SetupController: dictionary endpoints (payment-types, countries, civilities,
contact-types, payment-terms, company)
- ClientsController: added GET/{id}, POST, PUT/{id}, DELETE/{id}
- InvoicesController: added PUT/{id}/lines/{lineId}, GET /templates
- DocumentController: added GET /list and GET /download endpoints
- ClientService: added GetClientAsync, CreateClientAsync, UpdateClientAsync,
DeleteClientAsync
- InvoiceService: added UpdateInvoiceLineAsync, GetInvoiceTemplatesAsync
- DocumentService: added GetDocumentsAsync, DownloadDocumentAsync (using
new GetAsyncRaw on IDolibarrApiClient)
- ContactService: new service with CRUD operations
- SetupService: new service for Dolibarr dictionary data
- IDolibarrApiClient: added GetAsyncRaw method for raw string responses
- DolibarrApiClient: implemented GetAsyncRaw
- JwtTokenProvider: extended token expiry from 30 min to 8 hours
- AuthApplicationService: extended Dolibarr token cache from 30 min to 8 hours
2026-05-15 16:58:35 +00:00
|
|
|
public async Task<List<ClientDto>> GetClientsAsync(int limit = 50, int page = 1)
|
2026-01-30 15:34:23 +00:00
|
|
|
{
|
|
|
|
|
var endpoint = $"thirdparties?limit={limit}&page={page - 1}";
|
|
|
|
|
|
feat: add Contacts & Setup controllers, extend Clients/Invoices/Document controllers
- ContactsController: full CRUD (list, get, get by email, create, update, delete)
- SetupController: dictionary endpoints (payment-types, countries, civilities,
contact-types, payment-terms, company)
- ClientsController: added GET/{id}, POST, PUT/{id}, DELETE/{id}
- InvoicesController: added PUT/{id}/lines/{lineId}, GET /templates
- DocumentController: added GET /list and GET /download endpoints
- ClientService: added GetClientAsync, CreateClientAsync, UpdateClientAsync,
DeleteClientAsync
- InvoiceService: added UpdateInvoiceLineAsync, GetInvoiceTemplatesAsync
- DocumentService: added GetDocumentsAsync, DownloadDocumentAsync (using
new GetAsyncRaw on IDolibarrApiClient)
- ContactService: new service with CRUD operations
- SetupService: new service for Dolibarr dictionary data
- IDolibarrApiClient: added GetAsyncRaw method for raw string responses
- DolibarrApiClient: implemented GetAsyncRaw
- JwtTokenProvider: extended token expiry from 30 min to 8 hours
- AuthApplicationService: extended Dolibarr token cache from 30 min to 8 hours
2026-05-15 16:58:35 +00:00
|
|
|
var clients = await apiClient.GetCollectionAsync<ClientResponse>(endpoint);
|
2026-01-30 15:34:23 +00:00
|
|
|
|
|
|
|
|
if (clients.Count == 0)
|
|
|
|
|
return clients.Select(ClientMapper.MapToClientDtoWithoutContacts).ToList();
|
|
|
|
|
|
|
|
|
|
var clientIds = string.Join(",", clients.Select(c => c.id).Where(id => !string.IsNullOrEmpty(id)));
|
|
|
|
|
|
feat: add Contacts & Setup controllers, extend Clients/Invoices/Document controllers
- ContactsController: full CRUD (list, get, get by email, create, update, delete)
- SetupController: dictionary endpoints (payment-types, countries, civilities,
contact-types, payment-terms, company)
- ClientsController: added GET/{id}, POST, PUT/{id}, DELETE/{id}
- InvoicesController: added PUT/{id}/lines/{lineId}, GET /templates
- DocumentController: added GET /list and GET /download endpoints
- ClientService: added GetClientAsync, CreateClientAsync, UpdateClientAsync,
DeleteClientAsync
- InvoiceService: added UpdateInvoiceLineAsync, GetInvoiceTemplatesAsync
- DocumentService: added GetDocumentsAsync, DownloadDocumentAsync (using
new GetAsyncRaw on IDolibarrApiClient)
- ContactService: new service with CRUD operations
- SetupService: new service for Dolibarr dictionary data
- IDolibarrApiClient: added GetAsyncRaw method for raw string responses
- DolibarrApiClient: implemented GetAsyncRaw
- JwtTokenProvider: extended token expiry from 30 min to 8 hours
- AuthApplicationService: extended Dolibarr token cache from 30 min to 8 hours
2026-05-15 16:58:35 +00:00
|
|
|
var contacts = await apiClient.GetCollectionAsync<ContactResponse>($"contacts?thirdparty_ids={clientIds}");
|
2026-01-30 15:34:23 +00:00
|
|
|
var contactDtos = contacts.Select(ContactMapper.MapToContactDto).ToList();
|
|
|
|
|
|
|
|
|
|
return clients.Select(c => ClientMapper.MapToClientDto(c, contactDtos)).ToList();
|
|
|
|
|
}
|
feat: add Contacts & Setup controllers, extend Clients/Invoices/Document controllers
- ContactsController: full CRUD (list, get, get by email, create, update, delete)
- SetupController: dictionary endpoints (payment-types, countries, civilities,
contact-types, payment-terms, company)
- ClientsController: added GET/{id}, POST, PUT/{id}, DELETE/{id}
- InvoicesController: added PUT/{id}/lines/{lineId}, GET /templates
- DocumentController: added GET /list and GET /download endpoints
- ClientService: added GetClientAsync, CreateClientAsync, UpdateClientAsync,
DeleteClientAsync
- InvoiceService: added UpdateInvoiceLineAsync, GetInvoiceTemplatesAsync
- DocumentService: added GetDocumentsAsync, DownloadDocumentAsync (using
new GetAsyncRaw on IDolibarrApiClient)
- ContactService: new service with CRUD operations
- SetupService: new service for Dolibarr dictionary data
- IDolibarrApiClient: added GetAsyncRaw method for raw string responses
- DolibarrApiClient: implemented GetAsyncRaw
- JwtTokenProvider: extended token expiry from 30 min to 8 hours
- AuthApplicationService: extended Dolibarr token cache from 30 min to 8 hours
2026-05-15 16:58:35 +00:00
|
|
|
|
|
|
|
|
public async Task<ClientDetailDto> GetClientAsync(int id)
|
|
|
|
|
{
|
|
|
|
|
var client = await apiClient.GetResourceAsync<ClientResponse>($"thirdparties/{id}");
|
|
|
|
|
|
|
|
|
|
List<ContactDto> contactDtos = new();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var contacts = await apiClient.GetCollectionAsync<ContactResponse>($"contacts?thirdparty_ids={id}");
|
|
|
|
|
contactDtos = contacts.Select(ContactMapper.MapToContactDto).ToList();
|
|
|
|
|
}
|
|
|
|
|
catch (ApiException)
|
|
|
|
|
{
|
|
|
|
|
// Contacts may fail or be empty, continue without them
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ClientMapper.MapToClientDetailDto(client, contactDtos);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<int> CreateClientAsync(CreateClientDto dto)
|
|
|
|
|
{
|
|
|
|
|
var requestBody = new Dictionary<string, object?>
|
|
|
|
|
{
|
|
|
|
|
["name"] = dto.Name,
|
|
|
|
|
["client"] = "1",
|
|
|
|
|
["address"] = dto.Address,
|
|
|
|
|
["zip"] = dto.Zip,
|
|
|
|
|
["town"] = dto.Town,
|
|
|
|
|
["phone"] = dto.Phone,
|
|
|
|
|
["email"] = dto.Email,
|
|
|
|
|
["country_code"] = dto.CountryCode,
|
|
|
|
|
["tva_intra"] = dto.VatNumber,
|
|
|
|
|
["url"] = dto.Url,
|
|
|
|
|
["note_public"] = dto.NotePublic,
|
|
|
|
|
["note_private"] = dto.NotePrivate
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var response = await apiClient.PostAsync("thirdparties", requestBody);
|
|
|
|
|
return int.Parse(response);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task UpdateClientAsync(int id, UpdateClientDto dto)
|
|
|
|
|
{
|
|
|
|
|
var current = await apiClient.GetResourceAsync<ClientResponse>($"thirdparties/{id}");
|
|
|
|
|
|
|
|
|
|
var requestBody = new Dictionary<string, object?>
|
|
|
|
|
{
|
|
|
|
|
["name"] = dto.Name ?? current.name,
|
|
|
|
|
["address"] = dto.Address ?? current.address,
|
|
|
|
|
["zip"] = dto.Zip ?? current.zip,
|
|
|
|
|
["town"] = dto.Town ?? current.town,
|
|
|
|
|
["phone"] = dto.Phone ?? current.phone,
|
|
|
|
|
["email"] = dto.Email ?? current.email,
|
|
|
|
|
["country_code"] = dto.CountryCode ?? current.country_code,
|
|
|
|
|
["tva_intra"] = dto.VatNumber ?? current.tva_intra,
|
|
|
|
|
["url"] = dto.Url ?? current.url,
|
|
|
|
|
["note_public"] = dto.NotePublic ?? current.note_public,
|
|
|
|
|
["note_private"] = dto.NotePrivate ?? current.note_private
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
await apiClient.PutAsync($"thirdparties/{id}", requestBody);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task DeleteClientAsync(int id)
|
|
|
|
|
{
|
|
|
|
|
await apiClient.DeleteAsync($"thirdparties/{id}");
|
|
|
|
|
}
|
2026-01-30 15:34:23 +00:00
|
|
|
}
|