Skip to content

Commit

Permalink
fix(service) : added leadiamge id and datelastchanged fields (#250)
Browse files Browse the repository at this point in the history
added leadiamge id and datelastchanged fields to the following endpoints:

/api/apps/provided
/api/services/provided

-----------

Refd: CPLP-3169
Reviewed-By: Phil Schneider <[email protected]>
  • Loading branch information
VPrasannaK94 authored Sep 8, 2023
1 parent 0a6745e commit f7f9476
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,25 @@ public Task<OfferAutoSetupResponseData> AutoSetupServiceAsync(OfferAutoSetupData
_offerService.GetOfferDocumentContentAsync(serviceId, documentId, _settings.ServiceImageDocumentTypeIds, OfferTypeId.SERVICE, cancellationToken);

/// <inheritdoc/>
public Task<Pagination.Response<AllOfferStatusData>> GetCompanyProvidedServiceStatusDataAsync(int page, int size, Guid companyId, OfferSorting? sorting, string? offerName, ServiceStatusIdFilter? statusId) =>
Pagination.CreateResponseAsync(page, size, 15,
_portalRepositories.GetInstance<IOfferRepository>()
.GetCompanyProvidedServiceStatusDataAsync(GetOfferStatusIds(statusId), OfferTypeId.SERVICE, companyId, sorting ?? OfferSorting.DateDesc, offerName));
public async Task<Pagination.Response<AllOfferStatusData>> GetCompanyProvidedServiceStatusDataAsync(int page, int size, Guid companyId, OfferSorting? sorting, string? offerName, ServiceStatusIdFilter? statusId)
{
async Task<Pagination.Source<AllOfferStatusData>?> GetCompanyProvidedServiceStatusData(int skip, int take)
{
var companyProvidedServiceStatusData = await _portalRepositories.GetInstance<IOfferRepository>()
.GetCompanyProvidedServiceStatusDataAsync(GetOfferStatusIds(statusId), OfferTypeId.SERVICE, companyId, sorting ?? OfferSorting.DateDesc, offerName)(skip, take).ConfigureAwait(false);

return companyProvidedServiceStatusData == null
? null
: new Pagination.Source<AllOfferStatusData>(
companyProvidedServiceStatusData.Count,
companyProvidedServiceStatusData.Data.Select(item =>
item with
{
LeadPictureId = item.LeadPictureId == Guid.Empty ? null : item.LeadPictureId
}));
}
return await Pagination.CreateResponseAsync(page, size, 15, GetCompanyProvidedServiceStatusData).ConfigureAwait(false);
}

private static IEnumerable<OfferStatusId> GetOfferStatusIds(ServiceStatusIdFilter? serviceStatusIdFilter)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ namespace Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Models;
/// <summary>
/// View model of an application's base data.
/// </summary>
public record AllOfferStatusData(Guid Id, string? Name, string Provider, OfferStatusId Status);
public record AllOfferStatusData(Guid Id, string? Name, Guid? LeadPictureId, string Provider, OfferStatusId Status, DateTimeOffset? LastChanged);
Original file line number Diff line number Diff line change
Expand Up @@ -725,8 +725,10 @@ public void RemoveOffer(Guid offerId) =>
offer => new AllOfferStatusData(
offer.Id,
offer.Name,
offer.Documents.Where(document => document.DocumentTypeId == DocumentTypeId.SERVICE_LEADIMAGE && document.DocumentStatusId != DocumentStatusId.INACTIVE).Select(document => document.Id).FirstOrDefault(),
offer.ProviderCompany!.Name,
offer.OfferStatusId
offer.OfferStatusId,
offer.DateLastChanged
))
.SingleOrDefaultAsync();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
********************************************************************************/

using Microsoft.EntityFrameworkCore;
using Org.Eclipse.TractusX.Portal.Backend.Framework.Linq;
using Org.Eclipse.TractusX.Portal.Backend.Framework.Models;
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Models;
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Repositories;
Expand Down Expand Up @@ -1355,6 +1356,26 @@ public async Task GetOfferActiveStatusDataByIdAsync_ReturnsExpectedResult(Guid o

#endregion

#region GetCompanyProvidedServiceStatusData

[Fact]
public async Task GetCompanyProvidedServiceStatusDataAsync_ReturnsExpectedResult()
{
// Arrange
var sut = await CreateSut().ConfigureAwait(false);

// Act
var result = await sut.GetCompanyProvidedServiceStatusDataAsync(new[] { OfferStatusId.ACTIVE }, OfferTypeId.SERVICE, new("2dc4249f-b5ca-4d42-bef1-7a7a950a4f87"), null, null)(0, 15).ConfigureAwait(false);

// Assert
result!.Data.Should().NotBeNull().And.HaveCount(2).And.Satisfy(
x => x.Id == new Guid("99c5fd12-8085-4de2-abfd-215e1ee4baa5") && x.Name == "Newest Service",
x => x.Id == new Guid("ac1cf001-7fbc-1f2f-817f-bce0000c0001") && x.Name == "Consulting Service - Data Readiness"
);
}

#endregion

#region Setup

private async Task<OfferRepository> CreateSut()
Expand Down

0 comments on commit f7f9476

Please sign in to comment.