-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
order cancellation implemented (#592)
* order cancellation implemented * fixed code smells * fixed bug * added unregistered service * Update src/Altinn.Notifications.Persistence/Repository/OrderRepository.cs Co-authored-by: Terje Holene <[email protected]> * -> canCancel * removed task from analysis --------- Co-authored-by: Terje Holene <[email protected]>
- Loading branch information
1 parent
70775b8
commit 26f6c89
Showing
18 changed files
with
1,111 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,9 +81,9 @@ jobs: | |
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | ||
run: | | ||
dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}" | ||
- name: Process .NET test result | ||
if: always() | ||
uses: NasAmin/[email protected] | ||
with: | ||
TRX_PATH: ${{ github.workspace }}/TestResults | ||
REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
# - name: Process .NET test result | ||
# if: always() | ||
# uses: NasAmin/[email protected] | ||
# with: | ||
# TRX_PATH: ${{ github.workspace }}/TestResults | ||
# REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
namespace Altinn.Notifications.Core.Enums | ||
{ | ||
/// <summary> | ||
/// Enum for the different types of errors that can occur when cancelling an order | ||
/// </summary> | ||
public enum CancellationError | ||
{ | ||
/// <summary> | ||
/// Order was not found | ||
/// </summary> | ||
OrderNotFound, | ||
|
||
/// <summary> | ||
/// Order was found but processing had already started | ||
/// </summary> | ||
CancellationProhibited | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/Altinn.Notifications.Core/Services/CancelOrderService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using Altinn.Notifications.Core.Enums; | ||
using Altinn.Notifications.Core.Models.Orders; | ||
using Altinn.Notifications.Core.Persistence; | ||
using Altinn.Notifications.Core.Services.Interfaces; | ||
using Altinn.Notifications.Core.Shared; | ||
|
||
namespace Altinn.Notifications.Core.Services | ||
{ | ||
/// <summary> | ||
/// Implementation of the <see cref="ICancelOrderService"/> interface. | ||
/// </summary> | ||
public class CancelOrderService : ICancelOrderService | ||
{ | ||
private readonly IOrderRepository _repository; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="CancelOrderService"/> class. | ||
/// </summary> | ||
/// <param name="repository">The repository</param> | ||
public CancelOrderService(IOrderRepository repository) | ||
{ | ||
_repository = repository; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public async Task<Result<NotificationOrderWithStatus, CancellationError>> CancelOrder(Guid id, string creator) | ||
{ | ||
var result = await _repository.CancelOrder(id, creator); | ||
|
||
return result.Match<Result<NotificationOrderWithStatus, CancellationError>>( | ||
order => | ||
{ | ||
order.ProcessingStatus.StatusDescription = GetOrderService.GetStatusDescription(order.ProcessingStatus.Status); | ||
return order; | ||
}, | ||
error => | ||
{ | ||
return error; | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/Altinn.Notifications.Core/Services/Interfaces/ICancelOrderService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using Altinn.Notifications.Core.Enums; | ||
using Altinn.Notifications.Core.Models.Orders; | ||
using Altinn.Notifications.Core.Shared; | ||
|
||
namespace Altinn.Notifications.Core.Services.Interfaces | ||
{ | ||
/// <summary> | ||
/// Interface for operations related to cancelling notification orders | ||
/// </summary> | ||
public interface ICancelOrderService | ||
{ | ||
/// <summary> | ||
/// Cancels an order if it has not been processed yet | ||
/// </summary> | ||
/// <param name="id">The order id</param> | ||
/// <param name="creator">The creator of the orders</param> | ||
/// <returns>The cancelled order or a </returns> | ||
public Task<Result<NotificationOrderWithStatus, CancellationError>> CancelOrder(Guid id, string creator); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/Altinn.Notifications.Persistence/Migration/FunctionsAndProcedures/cancelorder.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
CREATE OR REPLACE FUNCTION notifications.cancelorder( | ||
_alternateid uuid, | ||
_creatorname text | ||
) | ||
RETURNS TABLE( | ||
cancelallowed boolean, | ||
alternateid uuid, | ||
creatorname text, | ||
sendersreference text, | ||
created timestamp with time zone, | ||
requestedsendtime timestamp with time zone, | ||
processed timestamp with time zone, | ||
processedstatus orderprocessingstate, | ||
notificationchannel text, | ||
ignorereservation boolean, | ||
resourceid text, | ||
conditionendpoint text, | ||
generatedemailcount bigint, | ||
succeededemailcount bigint, | ||
generatedsmscount bigint, | ||
succeededsmscount bigint | ||
) | ||
LANGUAGE plpgsql | ||
AS $$ | ||
DECLARE | ||
order_record RECORD; | ||
BEGIN | ||
-- Retrieve the order and its status | ||
SELECT o.requestedsendtime, o.processedstatus | ||
INTO order_record | ||
FROM notifications.orders o | ||
WHERE o.alternateid = _alternateid AND o.creatorname = _creatorname; | ||
|
||
-- If no order is found, return an empty result set | ||
IF NOT FOUND THEN | ||
RETURN; | ||
END IF; | ||
|
||
-- Check if order is already cancelled | ||
IF order_record.processedstatus = 'Cancelled' THEN | ||
RETURN QUERY | ||
SELECT TRUE AS cancelallowed, | ||
order_details.* | ||
FROM notifications.getorder_includestatus_v4(_alternateid, _creatorname) AS order_details; | ||
ELSEIF (order_record.requestedsendtime <= NOW() + INTERVAL '5 minutes' or order_record.processedstatus != 'Registered') THEN | ||
RETURN QUERY | ||
SELECT FALSE AS cancelallowed, NULL::uuid, NULL::text, NULL::text, NULL::timestamp with time zone, NULL::timestamp with time zone, NULL::timestamp with time zone, NULL::orderprocessingstate, NULL::text, NULL::boolean, NULL::text, NULL::text, NULL::bigint, NULL::bigint, NULL::bigint, NULL::bigint; | ||
ELSE | ||
-- Cancel the order by updating its status | ||
UPDATE notifications.orders | ||
SET processedstatus = 'Cancelled', processed = NOW() | ||
WHERE notifications.orders.alternateid = _alternateid; | ||
|
||
-- Retrieve the updated order details | ||
RETURN QUERY | ||
SELECT TRUE AS cancelallowed, | ||
order_details.* | ||
FROM notifications.getorder_includestatus_v4(_alternateid, _creatorname) AS order_details; | ||
END IF; | ||
END; | ||
$$; |
1 change: 1 addition & 0 deletions
1
src/Altinn.Notifications.Persistence/Migration/v0.35/00-alter-types.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ALTER TYPE public.orderprocessingstate ADD VALUE IF NOT EXISTS 'Cancelled'; |
Oops, something went wrong.