Skip to content

Commit

Permalink
[SPDBT-3227] cancel application endpoint. (#1671)
Browse files Browse the repository at this point in the history
# Description

This PR includes the following proposed change(s):

when application is not type of new and the status is draft or
incomplete, user can cancel it
  • Loading branch information
esdd1995 authored Oct 30, 2024
1 parent eb2fd67 commit 26c9dea
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/Spd.Manager.Licence/BizLicAppContract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public interface IBizLicAppManager
public Task<BizLicAppCommandResponse> Handle(BizLicAppUpdateCommand command, CancellationToken ct);
public Task<IEnumerable<LicenceAppListResponse>> Handle(GetBizLicAppListQuery cmd, CancellationToken ct);
public Task<FileResponse> Handle(BrandImageQuery qry, CancellationToken ct);
public Task<Unit> Handle(CancelDraftApplicationCommand cmd, CancellationToken ct);
}

public record BizLicAppUpsertCommand(BizLicAppUpsertRequest BizLicAppUpsertRequest) : IRequest<BizLicAppCommandResponse>;
Expand All @@ -22,6 +23,8 @@ public record BizLicAppSubmitCommand(BizLicAppUpsertRequest BizLicAppUpsertReque
public record GetBizLicAppQuery(Guid LicenceApplicationId) : IRequest<BizLicAppResponse>;
public record GetLatestBizLicenceAppQuery(Guid BizId) : IRequest<BizLicAppResponse>;
public record GetBizLicAppListQuery(Guid BizId) : IRequest<IEnumerable<LicenceAppListResponse>>;
public record CancelDraftApplicationCommand(Guid ApplicationId) : IRequest<Unit>;

public record BizLicAppReplaceCommand(
BizLicAppSubmitRequest LicenceRequest,
IEnumerable<LicAppFileInfo> LicAppFileInfos)
Expand Down
13 changes: 13 additions & 0 deletions src/Spd.Manager.Licence/BizLicAppManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ internal class BizLicAppManager :
IRequestHandler<BizLicAppUpdateCommand, BizLicAppCommandResponse>,
IRequestHandler<GetBizLicAppListQuery, IEnumerable<LicenceAppListResponse>>,
IRequestHandler<BrandImageQuery, FileResponse>,
IRequestHandler<CancelDraftApplicationCommand, Unit>,
IBizLicAppManager
{
private readonly IBizLicApplicationRepository _bizLicApplicationRepository;
Expand Down Expand Up @@ -356,6 +357,18 @@ public async Task<FileResponse> Handle(BrandImageQuery qry, CancellationToken ct
return new FileResponse(); //error in S3, probably cannot find the file
}
}
public async Task<Unit> Handle(CancelDraftApplicationCommand cmd, CancellationToken ct)
{
try
{
await _bizLicApplicationRepository.CancelDraftApplicationAsync(cmd.ApplicationId, ct);
}
catch (ArgumentException e)
{
throw new ApiException(HttpStatusCode.Forbidden, e.Message);
};
return default;
}

private async Task ValidateFilesForRenewUpdateAppAsync(BizLicAppSubmitRequest request,
IList<LicAppFileInfo> newFileInfos,
Expand Down
15 changes: 15 additions & 0 deletions src/Spd.Presentation.Licensing/Controllers/LicenceAppController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,20 @@ public async Task<IEnumerable<LicenceAppListResponse>> GetBizLicenceApplications
{
return await _mediator.Send(new GetBizLicAppListQuery(bizId), ct);
}

/// <summary>
/// Cancel Draft Application
/// </summary>
/// <param name="appId"></param>
/// <param name="ct"></param>
/// <returns></returns>
[Route("api/applications/{appId}")]
[HttpDelete]
[Authorize(Policy = "BcscBCeID")]
public async Task<ActionResult> CancelDraftApplication([FromRoute] Guid appId, CancellationToken ct)
{
await _mediator.Send(new CancelDraftApplicationCommand(appId), ct);
return Ok();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using AutoMapper;
using MediatR;
using Microsoft.AspNetCore.Http.HttpResults;
using Microsoft.Dynamics.CRM;
using Microsoft.OData.Client;
using Spd.Resource.Repository.PersonLicApplication;
Expand Down Expand Up @@ -356,4 +358,20 @@ private spd_licence GetLicence(Guid licenceId)

return licence;
}

public async Task CancelDraftApplicationAsync(Guid applicationId, CancellationToken ct)
{
spd_application? app = _context.spd_applications.Where(a => a.spd_applicationid == applicationId).FirstOrDefault();
if (app == null)
throw new ArgumentException("Application not found");
if (app.spd_licenceapplicationtype == (int)LicenceApplicationTypeOptionSet.New)
throw new ArgumentException("Canceling application with this type is not allowed.");
if (app.statuscode != (int)ApplicationStatusOptionSet.Draft && app.statuscode != (int)ApplicationStatusOptionSet.Incomplete)
throw new ArgumentException("Canceling application with this status is not allowed.");

app.statecode = DynamicsConstants.StateCode_Inactive;
app.statuscode = (int) ApplicationStatusOptionSet.Cancelled;
_context.UpdateObject(app);
await _context.SaveChangesAsync(ct);
}
}
4 changes: 3 additions & 1 deletion src/Spd.Resource.Repository/BizLicApplication/Contract.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Spd.Resource.Repository.Application;
using MediatR;
using Spd.Resource.Repository.Application;
using Spd.Resource.Repository.Biz;
using Spd.Resource.Repository.PersonLicApplication;

Expand All @@ -8,6 +9,7 @@ public partial interface IBizLicApplicationRepository
public Task<BizLicApplicationCmdResp> CreateBizLicApplicationAsync(CreateBizLicApplicationCmd cmd, CancellationToken ct);
public Task<BizLicApplicationCmdResp> SaveBizLicApplicationAsync(SaveBizLicApplicationCmd cmd, CancellationToken ct);
public Task<BizLicApplicationResp> GetBizLicApplicationAsync(Guid licenceApplicationId, CancellationToken ct);
public Task CancelDraftApplicationAsync(Guid applicationId, CancellationToken ct);
}

public record BizLicApplicationCmdResp(Guid LicenceAppId, Guid AccountId);
Expand Down

0 comments on commit 26c9dea

Please sign in to comment.