Skip to content

Commit

Permalink
My suggested changes to feature/notifications (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivarne authored Nov 20, 2023
1 parent e3bb5f1 commit 1a861d3
Show file tree
Hide file tree
Showing 41 changed files with 157 additions and 80 deletions.
3 changes: 3 additions & 0 deletions src/LocalTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
<TargetFramework>net6.0</TargetFramework>
<UserSecretsId>56f36ce2-b44b-415e-a8a5-f399a76e35b9</UserSecretsId>
<ImplicitUsings>enable</ImplicitUsings>

<!-- Allow copied code to use #if LOCALTEST to maintain changes for localtest from core services -->
<DefineConstants>$(DefineConstants);LOCALTEST</DefineConstants>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
using Altinn.Notifications.Core.Models;
#nullable enable
#if !LOCALTEST
using Altinn.Notifications.Configuration;
#endif
using Altinn.Notifications.Core.Models;
using Altinn.Notifications.Core.Models.Orders;
using Altinn.Notifications.Core.Services.Interfaces;
using Altinn.Notifications.Extensions;
Expand All @@ -8,15 +12,28 @@

using FluentValidation;

#if !LOCALTEST
using Microsoft.AspNetCore.Authorization;
#endif
using Microsoft.AspNetCore.Mvc;

#if !LOCALTEST
using Swashbuckle.AspNetCore.Annotations;
using Swashbuckle.AspNetCore.Filters;
#endif

namespace Altinn.Notifications.Controllers;

/// <summary>
/// Controller for all operations related to email notification orders
/// </summary>
[Route("notifications/api/v1/orders/email")]
[ApiController]
#if !LOCALTEST
[Authorize(Policy = AuthorizationConstants.POLICY_CREATE_SCOPE_OR_PLATFORM_ACCESS)]
[SwaggerResponse(401, "Caller is unauthorized")]
[SwaggerResponse(403, "Caller is not authorized to access the requested resource")]
# endif
public class EmailNotificationOrdersController : ControllerBase
{
private readonly IValidator<EmailNotificationOrderRequestExt> _validator;
Expand All @@ -42,6 +59,11 @@ public EmailNotificationOrdersController(IValidator<EmailNotificationOrderReques
[HttpPost]
[Consumes("application/json")]
[Produces("application/json")]
#if !LOCALTEST
[SwaggerResponse(202, "The notification order was accepted", typeof(OrderIdExt))]
[SwaggerResponse(400, "The notification order is invalid", typeof(ValidationProblemDetails))]
[SwaggerResponseHeader(202, "Location", "string", "Link to access the newly created notification order.")]
#endif
public async Task<ActionResult<OrderIdExt>> Post(EmailNotificationOrderRequestExt emailNotificationOrderRequest)
{
var validationResult = _validator.Validate(emailNotificationOrderRequest);
Expand All @@ -51,10 +73,19 @@ public async Task<ActionResult<OrderIdExt>> Post(EmailNotificationOrderRequestEx
return ValidationProblem(ModelState);
}

#if LOCALTEST
string creator = "localtest";
#else
string? creator = HttpContext.GetOrg();

if (creator == null)
{
return Forbid();
}
#endif

var orderRequest = emailNotificationOrderRequest.MapToOrderRequest(creator);
(NotificationOrder registeredOrder, ServiceError error) = await _orderService.RegisterEmailNotificationOrder(orderRequest);
(NotificationOrder? registeredOrder, ServiceError? error) = await _orderService.RegisterEmailNotificationOrder(orderRequest);

if (error != null)
{
Expand Down
19 changes: 0 additions & 19 deletions src/Notifications/API/Extensions/HttpContextExtensions.cs

This file was deleted.

3 changes: 2 additions & 1 deletion src/Notifications/API/Models/EmailContentTypeExt.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
namespace Altinn.Notifications.Models;
#nullable enable
namespace Altinn.Notifications.Models;

/// <summary>
/// Enum describing available content types for an email.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text.Json.Serialization;
#nullable enable
using System.Text.Json.Serialization;

using Altinn.Notifications.Models;

Expand Down
3 changes: 2 additions & 1 deletion src/Notifications/API/Models/EmailTemplateExt.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text.Json.Serialization;
#nullable enable
using System.Text.Json.Serialization;

namespace Altinn.Notifications.Models;

Expand Down
3 changes: 2 additions & 1 deletion src/Notifications/API/Models/NotificationChannelExt.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
namespace Altinn.Notifications.Models;
#nullable enable
namespace Altinn.Notifications.Models;

/// <summary>
/// Enum describing available notification channels.
Expand Down
3 changes: 2 additions & 1 deletion src/Notifications/API/Models/NotificationOrderListExt.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text.Json.Serialization;
#nullable enable
using System.Text.Json.Serialization;

namespace Altinn.Notifications.Models;

Expand Down
3 changes: 2 additions & 1 deletion src/Notifications/API/Models/NotificationResourceLinksExt.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text.Json.Serialization;
#nullable enable
using System.Text.Json.Serialization;

namespace Altinn.Notifications.Models;

Expand Down
3 changes: 2 additions & 1 deletion src/Notifications/API/Models/NotificationStatusExt.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text.Json.Serialization;
#nullable enable
using System.Text.Json.Serialization;

namespace Altinn.Notifications.Models;

Expand Down
3 changes: 2 additions & 1 deletion src/Notifications/API/Models/OrderIdExt.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text.Json.Serialization;
#nullable enable
using System.Text.Json.Serialization;

namespace Altinn.Notifications.Models;

Expand Down
3 changes: 2 additions & 1 deletion src/Notifications/API/Models/OrderResourceLinksExt.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text.Json.Serialization;
#nullable enable
using System.Text.Json.Serialization;

namespace Altinn.Notifications.Models;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using FluentValidation.Results;
#nullable enable
using FluentValidation.Results;

using Microsoft.AspNetCore.Mvc.ModelBinding;

Expand Down
13 changes: 13 additions & 0 deletions src/Notifications/Core/Configuration/NotificationOrderConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#nullable enable
namespace Altinn.Notifications.Core.Configuration;

/// <summary>
/// Configuration class for notification orders
/// </summary>
public class NotificationOrderConfig
{
/// <summary>
/// Default from address for email notifications
/// </summary>
public string DefaultEmailFromAddress { get; set; } = string.Empty;
}
3 changes: 2 additions & 1 deletion src/Notifications/Core/Enums/AddressType.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
namespace Altinn.Notifications.Core.Enums;
#nullable enable
namespace Altinn.Notifications.Core.Enums;

#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
/// <summary>
Expand Down
3 changes: 2 additions & 1 deletion src/Notifications/Core/Enums/EmailContentType.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
namespace Altinn.Notifications.Core.Enums;
#nullable enable
namespace Altinn.Notifications.Core.Enums;

/// <summary>
/// Enum describing available email content types
Expand Down
3 changes: 2 additions & 1 deletion src/Notifications/Core/Enums/EmailNotificationResultType.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
namespace Altinn.Notifications.Core.Enums;
#nullable enable
namespace Altinn.Notifications.Core.Enums;

/// <summary>
/// Enum describing email notification result types
Expand Down
3 changes: 2 additions & 1 deletion src/Notifications/Core/Enums/IResultType.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
namespace Altinn.Notifications.Core.Enums;
#nullable enable
namespace Altinn.Notifications.Core.Enums;

/// <summary>
/// Base class for send result of a notification
Expand Down
3 changes: 2 additions & 1 deletion src/Notifications/Core/Enums/NotificationChannel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
namespace Altinn.Notifications.Core.Enums;
#nullable enable
namespace Altinn.Notifications.Core.Enums;

/// <summary>
/// Enum describing available notification channels.
Expand Down
3 changes: 2 additions & 1 deletion src/Notifications/Core/Enums/NotificationTemplateType.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
namespace Altinn.Notifications.Core.Enums;
#nullable enable
namespace Altinn.Notifications.Core.Enums;

#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
/// <summary>
Expand Down
3 changes: 2 additions & 1 deletion src/Notifications/Core/Enums/OrderProcessingStatus.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
namespace Altinn.Notifications.Core.Enums;
#nullable enable
namespace Altinn.Notifications.Core.Enums;

#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
/// <summary>
Expand Down
3 changes: 2 additions & 1 deletion src/Notifications/Core/Models/Address/EmailAddressPoint.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Altinn.Notifications.Core.Enums;
#nullable enable
using Altinn.Notifications.Core.Enums;

namespace Altinn.Notifications.Core.Models.Address;

Expand Down
3 changes: 2 additions & 1 deletion src/Notifications/Core/Models/Address/IAddressPoint.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text.Json.Serialization;
#nullable enable
using System.Text.Json.Serialization;

using Altinn.Notifications.Core.Enums;

Expand Down
3 changes: 2 additions & 1 deletion src/Notifications/Core/Models/Creator.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
namespace Altinn.Notifications.Core.Models;
#nullable enable
namespace Altinn.Notifications.Core.Models;

/// <summary>
/// A class representing a notification creator
Expand Down
3 changes: 2 additions & 1 deletion src/Notifications/Core/Models/Email.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text.Json;
#nullable enable
using System.Text.Json;
using System.Text.Json.Serialization;

using Altinn.Notifications.Core.Enums;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Altinn.Notifications.Core.Enums;
#nullable enable
using Altinn.Notifications.Core.Enums;
using Altinn.Notifications.Core.Models.Recipients;

namespace Altinn.Notifications.Core.Models.Notification
Expand Down
3 changes: 2 additions & 1 deletion src/Notifications/Core/Models/Notification/INotification.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
#nullable enable
using System;

using Altinn.Notifications.Core.Enums;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
namespace Altinn.Notifications.Core.Models.Notification;
#nullable enable
namespace Altinn.Notifications.Core.Models.Notification;

/// <summary>
/// Interface representing a notification object with send result data
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#nullable enable
using System.Text.Json;
using System.Text.Json.Serialization;

using Altinn.Notifications.Core.Enums;
using Altinn.Notifications.Core.Models.Orders;

namespace Altinn.Notifications.Core.Models.Notification;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text.Json.Serialization;
#nullable enable
using System.Text.Json.Serialization;

using Altinn.Notifications.Core.Enums;

Expand Down
3 changes: 2 additions & 1 deletion src/Notifications/Core/Models/Recipient.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Altinn.Notifications.Core.Models.Address;
#nullable enable
using Altinn.Notifications.Core.Models.Address;

namespace Altinn.Notifications.Core.Models;

Expand Down
3 changes: 2 additions & 1 deletion src/Notifications/Core/Services/DateTimeService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Diagnostics.CodeAnalysis;
#nullable enable
using System.Diagnostics.CodeAnalysis;

using Altinn.Notifications.Core.Services.Interfaces;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#nullable enable
using Altinn.Notifications.Core.Configuration;
using Altinn.Notifications.Core.Models;
using Altinn.Notifications.Core.Models.NotificationTemplate;
using Altinn.Notifications.Core.Models.Orders;
using Altinn.Notifications.Core.Repository.Interfaces;
using Altinn.Notifications.Core.Services.Interfaces;

using Microsoft.Extensions.Options;

namespace Altinn.Notifications.Core.Services;

/// <summary>
Expand All @@ -20,12 +23,12 @@ public class EmailNotificationOrderService : IEmailNotificationOrderService
/// <summary>
/// Initializes a new instance of the <see cref="EmailNotificationOrderService"/> class.
/// </summary>
public EmailNotificationOrderService(IOrderRepository repository, IGuidService guid, IDateTimeService dateTime)
public EmailNotificationOrderService(IOrderRepository repository, IGuidService guid, IDateTimeService dateTime, IOptions<NotificationOrderConfig> config)
{
_repository = repository;
_guid = guid;
_dateTime = dateTime;
_defaultFromAddress = "localtest@altinn.no";
_defaultFromAddress = config.Value.DefaultEmailFromAddress;
}

/// <inheritdoc/>
Expand Down
3 changes: 2 additions & 1 deletion src/Notifications/Core/Services/GuidService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Diagnostics.CodeAnalysis;
#nullable enable
using System.Diagnostics.CodeAnalysis;

using Altinn.Notifications.Core.Services.Interfaces;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
namespace Altinn.Notifications.Core.Services.Interfaces;
#nullable enable
namespace Altinn.Notifications.Core.Services.Interfaces;

/// <summary>
/// Interface describing a dateTime service
Expand Down
3 changes: 2 additions & 1 deletion src/Notifications/Core/Services/Interfaces/IGuidService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
namespace Altinn.Notifications.Core.Services.Interfaces;
#nullable enable
namespace Altinn.Notifications.Core.Services.Interfaces;

/// <summary>
/// Interface describing a guid service
Expand Down
Loading

0 comments on commit 1a861d3

Please sign in to comment.