Skip to content

Commit 781e98d

Browse files
committed
Contact us notification endpoint
1 parent 4eab6de commit 781e98d

File tree

5 files changed

+54
-13
lines changed

5 files changed

+54
-13
lines changed

src/Core/Api/NotificationsController.cs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Microsoft.AspNetCore.Cors;
66
using Microsoft.AspNetCore.Mvc;
77
using System.Collections.Generic;
8+
using System.Linq;
89
using System.Threading.Tasks;
910

1011
namespace Core.Api
@@ -14,10 +15,12 @@ namespace Core.Api
1415
public class NotificationsController : ControllerBase
1516
{
1617
IDataService _data;
18+
INotificationService _notes;
1719

18-
public NotificationsController(IDataService data)
20+
public NotificationsController(IDataService data, INotificationService notes)
1921
{
2022
_data = data;
23+
_notes = notes;
2124
}
2225

2326
/// <summary>
@@ -89,5 +92,26 @@ public IActionResult Unsubscribe(string email)
8992
}
9093
return Ok();
9194
}
95+
96+
/// <summary>
97+
/// "Contact us" form notifications (CORS enabled)
98+
/// </summary>
99+
/// <param name="model">Contact model</param>
100+
/// <returns>Ok</returns>
101+
[HttpPost("contact")]
102+
[EnableCors("AllowOrigin")]
103+
public async Task<IActionResult> Contact([FromBody]ContactModel model)
104+
{
105+
if (ModelState.IsValid)
106+
{
107+
await _notes.AddNotification(
108+
AlertType.Contact,
109+
0,
110+
$"{model.Name}|{model.Email}",
111+
model.Content.StripHtml()
112+
);
113+
}
114+
return Ok();
115+
}
92116
}
93117
}

src/Core/CoreAPI.xml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Core/Data/Domain/Notification.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ public class Newsletter
2121

2222
public enum AlertType
2323
{
24-
Primary, Success, Warning, Error, Sticky
24+
Primary, Sticky, Contact
2525
}
2626
}

src/Core/Data/Models/NewsletterModel.cs

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using Core.Helpers;
2+
using System.Collections.Generic;
3+
using System.ComponentModel.DataAnnotations;
4+
5+
namespace Core.Data.Models
6+
{
7+
public class NewsletterModel
8+
{
9+
public IEnumerable<Newsletter> Emails { get; set; }
10+
public Pager Pager { get; set; }
11+
}
12+
13+
public class ContactModel
14+
{
15+
[Required]
16+
public string Name { get; set; }
17+
[Required, EmailAddress]
18+
public string Email { get; set; }
19+
public string Content { get; set; }
20+
}
21+
}

0 commit comments

Comments
 (0)