Skip to content

Commit

Permalink
feat(app): adjust status query param for subscription-status
Browse files Browse the repository at this point in the history
Refs: #592
  • Loading branch information
Phil91 committed Sep 3, 2024
1 parent 7c71e1a commit 3e983be
Show file tree
Hide file tree
Showing 16 changed files with 49 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,9 @@ public async Task AddFavouriteAppForUserAsync(Guid appId)
}

/// <inheritdoc />
public Task<Pagination.Response<OfferSubscriptionStatusDetailData>> GetCompanySubscribedAppSubscriptionStatusesForUserAsync(int page, int size, OfferSubscriptionStatusId? statusId) =>
_offerService.GetCompanySubscribedOfferSubscriptionStatusesForUserAsync(page, size, OfferTypeId.APP, DocumentTypeId.APP_LEADIMAGE, statusId);
public Task<Pagination.Response<OfferSubscriptionStatusDetailData>>
GetCompanySubscribedAppSubscriptionStatusesForUserAsync(int page, int size, OfferSubscriptionStatusId? statusId, string? name) =>
_offerService.GetCompanySubscribedOfferSubscriptionStatusesForUserAsync(page, size, OfferTypeId.APP, DocumentTypeId.APP_LEADIMAGE, statusId, name);

/// <inheritdoc/>
public async Task<Pagination.Response<OfferCompanySubscriptionStatusResponse>> GetCompanyProvidedAppSubscriptionStatusesForUserAsync(int page, int size, SubscriptionStatusSorting? sorting, OfferSubscriptionStatusId? statusId, Guid? offerId, string? companyName = null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,11 @@ public interface IAppsBusinessLogic
/// <param name ="page">page</param>
/// <param name ="size">size</param>
/// <param name="statusId"></param>
/// <param name="name"></param>
/// <returns>Returns the details of the subscription status for App user</returns>
public Task<Pagination.Response<OfferSubscriptionStatusDetailData>> GetCompanySubscribedAppSubscriptionStatusesForUserAsync(int page, int size, OfferSubscriptionStatusId? statusId);
public Task<Pagination.Response<OfferSubscriptionStatusDetailData>>
GetCompanySubscribedAppSubscriptionStatusesForUserAsync(int page, int size, OfferSubscriptionStatusId? statusId,
string? name);

/// <summary>
/// Retrieves subscription statuses of provided apps of the provided user's company.
Expand Down
7 changes: 4 additions & 3 deletions src/marketplace/Apps.Service/Controllers/AppsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ public async Task<IActionResult> RemoveFavouriteAppForCurrentUserAsync([FromRout
/// <remarks>Example: GET: /api/apps/subscribed/subscription-status</remarks>
/// <param name="page">The page that should be displayed</param>
/// <param name="size">The size per page of elements that should be returned</param>
/// <param name="statusId">Filter for the offer subscription status. If not set all elements will be returned</param>
/// <param name="status">Filter for the offer subscription status. If not set all elements will be returned</param>
/// <param name="name">An optional search query for the name</param>
/// <response code="200">Returns list of applicable apps subscription statuses.</response>
/// <response code="400">If sub claim is empty/invalid or user does not exist.</response>
[HttpGet]
Expand All @@ -167,8 +168,8 @@ public async Task<IActionResult> RemoveFavouriteAppForCurrentUserAsync([FromRout
[Authorize(Policy = PolicyTypes.ValidCompany)]
[ProducesResponseType(typeof(Pagination.Response<OfferSubscriptionStatusDetailData>), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status400BadRequest)]
public Task<Pagination.Response<OfferSubscriptionStatusDetailData>> GetCompanySubscribedAppSubscriptionStatusesForUserAsync([FromQuery] int page = 0, [FromQuery] int size = 15, [FromQuery] OfferSubscriptionStatusId? statusId = null) =>
_appsBusinessLogic.GetCompanySubscribedAppSubscriptionStatusesForUserAsync(page, size, statusId);
public Task<Pagination.Response<OfferSubscriptionStatusDetailData>> GetCompanySubscribedAppSubscriptionStatusesForUserAsync([FromQuery] int page = 0, [FromQuery] int size = 15, [FromQuery] OfferSubscriptionStatusId? status = null, [FromQuery] string? name = null) =>
_appsBusinessLogic.GetCompanySubscribedAppSubscriptionStatusesForUserAsync(page, size, status, name);

/// <summary>
/// Retrieves subscription statuses of provided apps of the currently logged in user's company.
Expand Down
5 changes: 4 additions & 1 deletion src/marketplace/Offers.Library/Service/IOfferService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,11 @@ Task CreateOrUpdateOfferSubscriptionAgreementConsentAsync(Guid subscriptionId,
/// <param name="offerTypeId"></param>
/// <param name="documentTypeId"></param>
/// <param name="statusId"></param>
/// <param name="name"></param>
/// <returns>Returns the details of the subscription status for user by OfferType</returns>
Task<Pagination.Response<OfferSubscriptionStatusDetailData>> GetCompanySubscribedOfferSubscriptionStatusesForUserAsync(int page, int size, OfferTypeId offerTypeId, DocumentTypeId documentTypeId, OfferSubscriptionStatusId? statusId);
Task<Pagination.Response<OfferSubscriptionStatusDetailData>>
GetCompanySubscribedOfferSubscriptionStatusesForUserAsync(int page, int size, OfferTypeId offerTypeId,
DocumentTypeId documentTypeId, OfferSubscriptionStatusId? statusId, string? name);

/// <summary>
/// Gets the information for the subscription for the provider
Expand Down
5 changes: 3 additions & 2 deletions src/marketplace/Offers.Library/Service/OfferService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -889,12 +889,13 @@ private async Task<IEnumerable<Guid>> ValidateRoleData(IEnumerable<UserRoleConfi
}

/// <inheritdoc/>
public async Task<Pagination.Response<OfferSubscriptionStatusDetailData>> GetCompanySubscribedOfferSubscriptionStatusesForUserAsync(int page, int size, OfferTypeId offerTypeId, DocumentTypeId documentTypeId, OfferSubscriptionStatusId? statusId)
public async Task<Pagination.Response<OfferSubscriptionStatusDetailData>>
GetCompanySubscribedOfferSubscriptionStatusesForUserAsync(int page, int size, OfferTypeId offerTypeId, DocumentTypeId documentTypeId, OfferSubscriptionStatusId? statusId, string? name)
{
async Task<Pagination.Source<OfferSubscriptionStatusDetailData>?> GetCompanySubscribedOfferSubscriptionStatusesData(int skip, int take)
{
var offerCompanySubscriptionResponse = await _portalRepositories.GetInstance<IOfferSubscriptionsRepository>()
.GetOwnCompanySubscribedOfferSubscriptionStatusAsync(_identityData.CompanyId, offerTypeId, documentTypeId, statusId)(skip, take).ConfigureAwait(ConfigureAwaitOptions.None);
.GetOwnCompanySubscribedOfferSubscriptionStatusAsync(_identityData.CompanyId, offerTypeId, documentTypeId, statusId, name)(skip, take).ConfigureAwait(ConfigureAwaitOptions.None);

return offerCompanySubscriptionResponse == null
? null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public interface IServiceBusinessLogic
/// <param name ="size">size</param>
/// <param name="statusId"></param>
/// <returns>Returns the details of the subscription status for Service user</returns>
Task<Pagination.Response<OfferSubscriptionStatusDetailData>> GetCompanySubscribedServiceSubscriptionStatusesForUserAsync(int page, int size, OfferSubscriptionStatusId? statusId);
Task<Pagination.Response<OfferSubscriptionStatusDetailData>> GetCompanySubscribedServiceSubscriptionStatusesForUserAsync(int page, int size, OfferSubscriptionStatusId? statusId, string? name);

/// <summary>
/// Starts the auto setup process.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@ public Task<SubscriberSubscriptionDetailData> GetSubscriptionDetailForSubscriber
_offerService.GetSubscriptionDetailsForSubscriberAsync(serviceId, subscriptionId, OfferTypeId.SERVICE, _settings.SalesManagerRoles);

/// <inheritdoc />
public Task<Pagination.Response<OfferSubscriptionStatusDetailData>> GetCompanySubscribedServiceSubscriptionStatusesForUserAsync(int page, int size, OfferSubscriptionStatusId? statusId) =>
_offerService.GetCompanySubscribedOfferSubscriptionStatusesForUserAsync(page, size, OfferTypeId.SERVICE, DocumentTypeId.SERVICE_LEADIMAGE, statusId);
public Task<Pagination.Response<OfferSubscriptionStatusDetailData>> GetCompanySubscribedServiceSubscriptionStatusesForUserAsync(int page, int size, OfferSubscriptionStatusId? statusId, string? name) =>
_offerService.GetCompanySubscribedOfferSubscriptionStatusesForUserAsync(page, size, OfferTypeId.SERVICE, DocumentTypeId.SERVICE_LEADIMAGE, statusId, name);

/// <inheritdoc />
public Task StartAutoSetupAsync(OfferAutoSetupData data) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,8 @@ public Task<SubscriberSubscriptionDetailData> GetSubscriptionDetailForSubscriber
/// <remarks>Example: GET: /api/services/subscribed/subscription-status</remarks>
/// <param name="page">The page that should be displayed</param>
/// <param name="size">The size per page of elements that should be returned</param>
/// <param name="statusId">Filter for the offer subscription status. If not set all elements will be returned</param>
/// <param name="status">Filter for the offer subscription status. If not set all elements will be returned</param>
/// <param name="name">Optional search query to filter for the name</param>
/// <response code="200">Returns list of applicable service subscription statuses.</response>
/// <response code="400">If sub claim is empty/invalid or user does not exist.</response>
[HttpGet]
Expand All @@ -306,8 +307,8 @@ public Task<SubscriberSubscriptionDetailData> GetSubscriptionDetailForSubscriber
[Authorize(Policy = PolicyTypes.ValidCompany)]
[ProducesResponseType(typeof(Pagination.Response<OfferSubscriptionStatusDetailData>), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status400BadRequest)]
public Task<Pagination.Response<OfferSubscriptionStatusDetailData>> GetCompanySubscribedServiceSubscriptionStatusesForUserAsync([FromQuery] int page = 0, [FromQuery] int size = 15, [FromQuery] OfferSubscriptionStatusId? statusId = null) =>
_serviceBusinessLogic.GetCompanySubscribedServiceSubscriptionStatusesForUserAsync(page, size, statusId);
public Task<Pagination.Response<OfferSubscriptionStatusDetailData>> GetCompanySubscribedServiceSubscriptionStatusesForUserAsync([FromQuery] int page = 0, [FromQuery] int size = 15, [FromQuery] OfferSubscriptionStatusId? status = null, [FromQuery] string? name = null) =>
_serviceBusinessLogic.GetCompanySubscribedServiceSubscriptionStatusesForUserAsync(page, size, status, name);

/// <summary>
/// Unsubscribes an service from the current user's company's subscriptions.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,11 @@ public interface IOfferSubscriptionsRepository
/// <param name="offerTypeId">Id of the offer type</param>
/// <param name="documentTypeId">Id of the document type</param>
/// <param name="statusId"></param>
/// <param name="name"></param>
/// <returns>Returns a func with skip, take and the pagination of the source</returns>
Func<int, int, Task<Pagination.Source<OfferSubscriptionStatusData>?>>
GetOwnCompanySubscribedOfferSubscriptionStatusAsync(Guid userCompanyId, OfferTypeId offerTypeId,
DocumentTypeId documentTypeId, OfferSubscriptionStatusId? statusId);
DocumentTypeId documentTypeId, OfferSubscriptionStatusId? statusId, string? name);

/// <summary>
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,8 @@ public void AttachAndModifyAppSubscriptionDetail(Guid detailId, Guid subscriptio

/// <inheritdoc />
public Func<int, int, Task<Pagination.Source<OfferSubscriptionStatusData>?>>
GetOwnCompanySubscribedOfferSubscriptionStatusAsync(Guid userCompanyId, OfferTypeId offerTypeId, DocumentTypeId documentTypeId, OfferSubscriptionStatusId? statusId) =>
GetOwnCompanySubscribedOfferSubscriptionStatusAsync(Guid userCompanyId, OfferTypeId offerTypeId,
DocumentTypeId documentTypeId, OfferSubscriptionStatusId? statusId, string? name) =>
(skip, take) => Pagination.CreateSourceQueryAsync(
skip,
take,
Expand All @@ -318,7 +319,8 @@ public void AttachAndModifyAppSubscriptionDetail(Guid detailId, Guid subscriptio
.Where(os =>
os.Offer!.OfferTypeId == offerTypeId &&
os.CompanyId == userCompanyId &&
(statusId == null || os.OfferSubscriptionStatusId == statusId))
(statusId == null || os.OfferSubscriptionStatusId == statusId) &&
(name == null || (os.Offer.Name != null && EF.Functions.ILike(os.Offer!.Name, $"%{name.EscapeForILike()}%"))))
.GroupBy(os => os.CompanyId),
null,
os => new OfferSubscriptionStatusData(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,18 +471,18 @@ public async Task GetCompanySubscribedAppSubscriptionStatusesForUserAsync_Return
// Arrange
var data = _fixture.CreateMany<OfferSubscriptionStatusDetailData>(5).ToImmutableArray();
var pagination = new Pagination.Response<OfferSubscriptionStatusDetailData>(new Pagination.Metadata(data.Length, 1, 0, data.Length), data);
A.CallTo(() => _offerService.GetCompanySubscribedOfferSubscriptionStatusesForUserAsync(A<int>._, A<int>._, A<OfferTypeId>._, A<DocumentTypeId>._, A<OfferSubscriptionStatusId?>._))
A.CallTo(() => _offerService.GetCompanySubscribedOfferSubscriptionStatusesForUserAsync(A<int>._, A<int>._, A<OfferTypeId>._, A<DocumentTypeId>._, A<OfferSubscriptionStatusId?>._, A<string?>._))
.Returns(pagination);

var sut = new AppsBusinessLogic(_portalRepositories, null!, _offerService, null!, _fixture.Create<IOptions<AppsSettings>>(), _identityService);

// Act
var result = await sut.GetCompanySubscribedAppSubscriptionStatusesForUserAsync(0, 10, null);
var result = await sut.GetCompanySubscribedAppSubscriptionStatusesForUserAsync(0, 10, null, null);

// Assert
result.Meta.NumberOfElements.Should().Be(5);
result.Content.Should().HaveCount(5);
A.CallTo(() => _offerService.GetCompanySubscribedOfferSubscriptionStatusesForUserAsync(0, 10, OfferTypeId.APP, DocumentTypeId.APP_LEADIMAGE, null)).MustHaveHappenedOnceExactly();
A.CallTo(() => _offerService.GetCompanySubscribedOfferSubscriptionStatusesForUserAsync(0, 10, OfferTypeId.APP, DocumentTypeId.APP_LEADIMAGE, null, null)).MustHaveHappenedOnceExactly();
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,14 @@ public async Task GetCompanySubscribedAppSubscriptionStatusesForCurrentUserAsync
//Arrange
var data = _fixture.CreateMany<OfferSubscriptionStatusDetailData>(3).ToImmutableArray();
var pagination = new Pagination.Response<OfferSubscriptionStatusDetailData>(new Pagination.Metadata(data.Length, 1, 0, data.Length), data);
A.CallTo(() => _logic.GetCompanySubscribedAppSubscriptionStatusesForUserAsync(A<int>._, A<int>._, A<OfferSubscriptionStatusId?>._))
A.CallTo(() => _logic.GetCompanySubscribedAppSubscriptionStatusesForUserAsync(A<int>._, A<int>._, A<OfferSubscriptionStatusId?>._, A<string?>._))
.Returns(pagination);

//Act
var result = await _controller.GetCompanySubscribedAppSubscriptionStatusesForUserAsync();

//Assert
A.CallTo(() => _logic.GetCompanySubscribedAppSubscriptionStatusesForUserAsync(0, 15, null)).MustHaveHappenedOnceExactly();
A.CallTo(() => _logic.GetCompanySubscribedAppSubscriptionStatusesForUserAsync(0, 15, null, null)).MustHaveHappenedOnceExactly();
result.Content.Should().HaveCount(3).And.ContainInOrder(data);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2442,11 +2442,11 @@ public async Task GetCompanySubscribedOfferSubscriptionStatusesForUserAsync_Retu
{
// Arrange
var data = _fixture.CreateMany<OfferSubscriptionStatusData>(5).ToImmutableArray();
A.CallTo(() => _offerSubscriptionsRepository.GetOwnCompanySubscribedOfferSubscriptionStatusAsync(A<Guid>._, A<OfferTypeId>._, A<DocumentTypeId>._, A<OfferSubscriptionStatusId?>._))
A.CallTo(() => _offerSubscriptionsRepository.GetOwnCompanySubscribedOfferSubscriptionStatusAsync(A<Guid>._, A<OfferTypeId>._, A<DocumentTypeId>._, A<OfferSubscriptionStatusId?>._, A<string?>._))
.Returns((skip, take) => Task.FromResult(new Pagination.Source<OfferSubscriptionStatusData>(data.Length, data.Skip(skip).Take(take)))!);

// Act
var result = await _sut.GetCompanySubscribedOfferSubscriptionStatusesForUserAsync(0, 10, offerTypeId, documentTypeId, null);
var result = await _sut.GetCompanySubscribedOfferSubscriptionStatusesForUserAsync(0, 10, offerTypeId, documentTypeId, null, null);

// Assert
result.Meta.NumberOfElements.Should().Be(5);
Expand All @@ -2457,7 +2457,7 @@ public async Task GetCompanySubscribedOfferSubscriptionStatusesForUserAsync_Retu
x => x.OfferId == data[3].OfferId && x.OfferName == data[3].OfferName && x.Provider == data[3].Provider && x.OfferSubscriptionStatusId == data[3].OfferSubscriptionStatusId && x.OfferSubscriptionId == data[3].OfferSubscriptionId && x.DocumentId == data[3].DocumentId,
x => x.OfferId == data[4].OfferId && x.OfferName == data[4].OfferName && x.Provider == data[4].Provider && x.OfferSubscriptionStatusId == data[4].OfferSubscriptionStatusId && x.OfferSubscriptionId == data[4].OfferSubscriptionId && x.DocumentId == data[4].DocumentId
);
A.CallTo(() => _offerSubscriptionsRepository.GetOwnCompanySubscribedOfferSubscriptionStatusAsync(_companyId, offerTypeId, documentTypeId, null))
A.CallTo(() => _offerSubscriptionsRepository.GetOwnCompanySubscribedOfferSubscriptionStatusAsync(_companyId, offerTypeId, documentTypeId, null, null))
.MustHaveHappenedOnceExactly();
}

Expand All @@ -2467,16 +2467,16 @@ public async Task GetCompanySubscribedOfferSubscriptionStatusesForUserAsync_Retu
public async Task GetCompanySubscribedOfferSubscriptionStatusesForUserAsync_WithQueryNullResult_ReturnsExpected(OfferTypeId offerTypeId, DocumentTypeId documentTypeId)
{
// Arrange
A.CallTo(() => _offerSubscriptionsRepository.GetOwnCompanySubscribedOfferSubscriptionStatusAsync(A<Guid>._, A<OfferTypeId>._, A<DocumentTypeId>._, A<OfferSubscriptionStatusId?>._))
A.CallTo(() => _offerSubscriptionsRepository.GetOwnCompanySubscribedOfferSubscriptionStatusAsync(A<Guid>._, A<OfferTypeId>._, A<DocumentTypeId>._, A<OfferSubscriptionStatusId?>._, A<string?>._))
.Returns((skip, take) => Task.FromResult<Pagination.Source<OfferSubscriptionStatusData>?>(null));

// Act
var result = await _sut.GetCompanySubscribedOfferSubscriptionStatusesForUserAsync(0, 10, offerTypeId, documentTypeId, null);
var result = await _sut.GetCompanySubscribedOfferSubscriptionStatusesForUserAsync(0, 10, offerTypeId, documentTypeId, null, null);

// Assert
result.Meta.NumberOfElements.Should().Be(0);
result.Content.Should().BeEmpty();
A.CallTo(() => _offerSubscriptionsRepository.GetOwnCompanySubscribedOfferSubscriptionStatusAsync(_companyId, offerTypeId, documentTypeId, null))
A.CallTo(() => _offerSubscriptionsRepository.GetOwnCompanySubscribedOfferSubscriptionStatusAsync(_companyId, offerTypeId, documentTypeId, null, null))
.MustHaveHappenedOnceExactly();
}

Expand Down
Loading

0 comments on commit 3e983be

Please sign in to comment.