Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PS-148 notification email #41

Merged
merged 21 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
706ef8b
first draft sub
MysticFragilist Apr 6, 2024
5d36e45
Fix notification
MysticFragilist Apr 8, 2024
548c1af
Update core/Controllers/SubscriptionController.cs
MysticFragilist Apr 10, 2024
73f7a9f
Update core/Controllers/SubscriptionController.cs
MysticFragilist Apr 10, 2024
6536d60
Update core/Data/Entities/Notification.cs
MysticFragilist Apr 10, 2024
fde6859
Update core/Misc/SchedulerSetup.cs
MysticFragilist Apr 10, 2024
7ed6fec
Update core/Services/NotificationService.cs
MysticFragilist Apr 10, 2024
983fc9f
Update core/Services/NotificationService.cs
MysticFragilist Apr 10, 2024
58844e0
Update core/Services/NotificationService.cs
MysticFragilist Apr 10, 2024
a9ca680
Update core/Services/SubscriptionService.cs
MysticFragilist Apr 10, 2024
e386a41
Update core/Services/NotificationService.cs
MysticFragilist Apr 10, 2024
38db376
Update emails/Services/Abstractions/IEmailService.cs
MysticFragilist Apr 10, 2024
2a2ef26
Update emails/Services/EmailService.cs
MysticFragilist Apr 10, 2024
fd0bd01
Add loggers
MysticFragilist Apr 10, 2024
54031e0
Merge branch 'ftr/ps-148-notification-email' of github.com:ApplETS/Ba…
MysticFragilist Apr 10, 2024
8d5e7ae
fix varying log
MysticFragilist Apr 10, 2024
d4e8763
change to use environement variable from conf
MysticFragilist Apr 10, 2024
854110a
Add tests
MysticFragilist Apr 10, 2024
8cb6bf3
Fix tests and add asserts
MysticFragilist Apr 10, 2024
5190f3f
Merge branch 'main' into ftr/ps-148-notification-email
MysticFragilist Apr 10, 2024
eeaff34
fix security issue
MysticFragilist Apr 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions core/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ csharp_style_prefer_top_level_statements = true:silent
csharp_style_prefer_primary_constructors = true:suggestion

#### Naming styles ####

# CA1862: Use the 'StringComparison' method overloads to perform case-insensitive string comparisons
dotnet_diagnostic.CA1862.severity = suggestion

[*.{cs,vb}]

# Naming rules
Expand Down
8 changes: 6 additions & 2 deletions core/Controllers/OrganizersController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ namespace api.core.controllers;
[Authorize(Policy = AuthPolicies.IsModerator)]
[ApiController]
[Route("api/moderator/organizer")]
public class ModeratorUserController(IUserService userService, IAuthService authService, IEmailService emailService) : ControllerBase
public class ModeratorUserController(
IUserService userService,
IAuthService authService,
IEmailService emailService,
IConfiguration configuration) : ControllerBase
{
[AllowAnonymous]
[HttpGet("{organizerId}")]
Expand All @@ -41,7 +45,7 @@ public async Task<IActionResult> CreateOrganizer([FromBody] UserCreateDTO organi
var supabaseUser = authService.SignUp(organizer.Email, strongPassword);
Guid.TryParse(supabaseUser, out Guid userId);
var created = userService.AddOrganizer(userId, organizer);
var frontBaseUrl = Environment.GetEnvironmentVariable("FRONTEND_BASE_URL") ?? throw new Exception("FRONTEND_BASE_URL is not set");
var frontBaseUrl = configuration.GetValue<string>("FRONTEND_BASE_URL") ?? throw new Exception("FRONTEND_BASE_URL is not set");
await emailService.SendEmailAsync(
organizer.Email,
"Votre compte Hello!",
Expand Down
32 changes: 32 additions & 0 deletions core/Controllers/SubscriptionController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using api.core.Data;
using api.core.Data.requests;
using api.core.Services.Abstractions;

using Microsoft.AspNetCore.Mvc;

namespace api.core.Controllers;

[ApiController]
[Route("api/subscriptions")]
public class SubscriptionController(ISubscriptionService subscriptionService) : ControllerBase
{
[HttpPost]
public IActionResult Subscribe([FromBody] SubscribeRequestDTO request)
{
subscriptionService.Subscribe(request);
return Ok(new Response<object>
{
Data = "Subscribed successfully to this organizer posts."
});
}

[HttpDelete]
public IActionResult Unsubcribe([FromBody] UnsubscribeRequestDTO request)
{
subscriptionService.Unsubscribe(request);
return Ok(new Response<object>
{
Data = "Unsubscribed successfully from this organizer posts."
});
}
}
23 changes: 23 additions & 0 deletions core/Data/Entities/Notification.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.ComponentModel.DataAnnotations.Schema;

using api.core.Data.Entities;

namespace api.core.data.entities;

[Table(nameof(Notification))]
public partial class Notification : BaseEntity
{
public Guid PublicationId { get; set; }

public Guid SubscriptionId { get; set; }

public bool IsSent { get; set; } = false;

[ForeignKey(nameof(PublicationId))]
[InverseProperty(nameof(Publication.Notifications))]
public virtual Publication Publication { get; set; } = null!;

[ForeignKey(nameof(SubscriptionId))]
[InverseProperty(nameof(Subscription.Notifications))]
public virtual Subscription Subscription { get; set; } = null!;
}
3 changes: 3 additions & 0 deletions core/Data/Entities/Organizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,7 @@ public partial class Organizer : User
[ForeignKey("ActivityAreaId")]
[InverseProperty("Organizers")]
public virtual ActivityArea? ActivityArea { get; set; }

[InverseProperty(nameof(Subscription.Organizer))]
public virtual ICollection<Subscription> Subscriptions { get; set; } = new List<Subscription>();
}
3 changes: 3 additions & 0 deletions core/Data/Entities/Publication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,7 @@ public partial class Publication
[ForeignKey("PublicationsId")]
[InverseProperty("Publications")]
public virtual ICollection<Tag> Tags { get; set; } = new List<Tag>();

[InverseProperty(nameof(Notification.Publication))]
public virtual ICollection<Notification> Notifications { get; set; } = new List<Notification>();
}
23 changes: 23 additions & 0 deletions core/Data/Entities/Subscription.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.ComponentModel.DataAnnotations.Schema;

using api.core.Data.Entities;


namespace api.core.data.entities;

[Table(nameof(Subscription))]
public partial class Subscription : BaseEntity
{
public string Email { get; set; } = null!;

public Guid OrganizerId { get; set; }

public string SubscriptionToken { get; set; } = null!;

[ForeignKey(nameof(OrganizerId))]
[InverseProperty(nameof(entities.Organizer.Subscriptions))]
public virtual Organizer Organizer { get; set; } = null!;

[InverseProperty(nameof(Notification.Subscription))]
public virtual ICollection<Notification> Notifications { get; set; } = new List<Notification>();
}
8 changes: 8 additions & 0 deletions core/Data/EventManagementContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ public EventManagementContext(DbContextOptions<EventManagementContext> options)

public virtual DbSet<ActivityArea> ActivityAreas { get; set; }

public virtual DbSet<Subscription> Subscriptions { get; set; }

public virtual DbSet<Notification> Notifications { get; set; }

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Event>(entity =>
Expand Down Expand Up @@ -116,6 +120,10 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
});
});

modelBuilder.Entity<Subscription>()
.HasIndex(a => new { a.Email, a.OrganizerId })
.IsUnique();

OnModelCreatingPartial(modelBuilder);
}

Expand Down
15 changes: 15 additions & 0 deletions core/Data/Requests/SubscriptionRequestDTO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace api.core.Data.requests;

public class SubscribeRequestDTO
{
public required string Email { get; set; }

public required Guid OrganizerId { get; set; }
}


public class UnsubscribeRequestDTO
{
public required string SubscriptionToken { get; set; }

}
4 changes: 4 additions & 0 deletions core/Extensions/DependencyInjectionExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public static IServiceCollection AddDependencyInjection(this IServiceCollection
services.AddTransient<IModeratorRepository, ModeratorRepository>();
services.AddTransient<IReportRepository, ReportRepository>();
services.AddTransient<IActivityAreaRepository, ActivityAreaRepository>();
services.AddTransient<ISubscriptionRepository, SubscriptionRepository>();
services.AddTransient<INotificationRepository, NotificationRepository>();

// Services
services.AddTransient<IUserService, UserService>();
Expand All @@ -40,6 +42,8 @@ public static IServiceCollection AddDependencyInjection(this IServiceCollection
services.AddTransient<IReportService, ReportService>();
services.AddTransient<IActivityAreaService, ActivityAreaService>();
services.AddTransient<IModeratorService, ModeratorService>();
services.AddTransient<ISubscriptionService, SubscriptionService>();
services.AddTransient<INotificationService, NotificationService>();

return services;
}
Expand Down
Loading
Loading