2026-01-03 18:52:07 +00:00
|
|
|
using DoliMiddlewareApi.Dtos.command;
|
|
|
|
|
using DoliMiddlewareApi.Services.Auth;
|
|
|
|
|
|
|
|
|
|
namespace DoliMiddlewareApi.Services;
|
|
|
|
|
|
|
|
|
|
public class AuthApplicationService(DolibarrAuthService dolibarrAuth, JwtTokenProvider jwtProvider, DolibarrTokenCacheService tokenCacheService)
|
|
|
|
|
{
|
|
|
|
|
public async Task<LoginResponse> LoginAsync(CreateTokenDto dto)
|
|
|
|
|
{
|
|
|
|
|
var doliToken = await dolibarrAuth.AuthenticateAsync(dto);
|
|
|
|
|
var sessionId = Guid.NewGuid().ToString();
|
|
|
|
|
|
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
|
|
|
tokenCacheService.SetDolibarrToken(sessionId, doliToken, TimeSpan.FromHours(8));
|
2026-01-03 18:52:07 +00:00
|
|
|
|
|
|
|
|
var jwt = jwtProvider.GenerateJwt(sessionId, dto.Username);
|
|
|
|
|
|
|
|
|
|
return new LoginResponse { Token = jwt };
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class LoginResponse
|
|
|
|
|
{
|
|
|
|
|
public required string Token { get; set; }
|
|
|
|
|
}
|