Skip to content

Commit

Permalink
Add notification service
Browse files Browse the repository at this point in the history
  • Loading branch information
The-DevBlog committed Nov 12, 2023
1 parent 3bd8a8d commit c839aa9
Show file tree
Hide file tree
Showing 18 changed files with 1,110 additions and 26 deletions.
2 changes: 1 addition & 1 deletion devblog/devblog/ClientApp/src/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ button:hover {

main {
width: 1100px;
margin: auto
margin: auto;
}

@media (max-width: 1000px) {
Expand Down
23 changes: 23 additions & 0 deletions devblog/devblog/Controllers/NotificationController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using devblog.Interfaces;
using devblog.Services;
using Microsoft.AspNetCore.Mvc;

namespace devblog.Controllers
{
[ApiController]
[Route("api/[controller]")]
public class NotificationController : ControllerBase
{
private readonly INotificationService _notifications;

public NotificationController(NotificationService notifications)
{
_notifications = notifications;
}

public async Task Get()
{

}
}
}
20 changes: 4 additions & 16 deletions devblog/devblog/Controllers/PostsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,13 @@ namespace devblog.Controllers
public class PostsController : ControllerBase
{
private readonly IPostService _posts;
private readonly IImgService _imgService;

public PostsController(IPostService posts, IImgService imgService)
private readonly IImgService _imgs;
public PostsController(IPostService posts, IImgService imgs)
{
_posts = posts;
_imgService = imgService;
_imgs = imgs;
}

/// <summary>
/// Retrieves all posts
/// </summary>
/// <returns>List<Post></returns>
//[HttpGet]
//public async Task<List<Post>> Get()
//{
// var posts = await _posts.Get();
// return posts;
//}

[HttpGet("page/{pageNum}")]
public async Task<List<Post>> GetPage(int pageNum)
{
Expand Down Expand Up @@ -107,7 +95,7 @@ public async Task<Post> Update(int id, [FromBody] string description)
public async Task Delete(int id)
{
var imgs = _posts.Get(id).Result.Imgs;
await _imgService.DeleteImgFromDropBox(imgs);
await _imgs.DeleteImgFromDropBox(imgs);
await _posts.Delete(id);
}
}
Expand Down
4 changes: 3 additions & 1 deletion devblog/devblog/Data/AppDbContext.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using devblog.Models;
using Discord;
using Microsoft.EntityFrameworkCore;

namespace devblog.Data
Expand All @@ -12,6 +11,7 @@ public class AppDbContext : DbContext
public DbSet<DownVote> DownVote { get; set; }
public DbSet<Img> Img { get; set; }
public DbSet<YtVideo> YtVideo { get; set; }
public DbSet<Notification> Notification { get; set; }

public AppDbContext(DbContextOptions<AppDbContext> opt) : base(opt)
{
Expand All @@ -21,6 +21,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);

modelBuilder.Entity<Notification>().HasKey(e => new { e.PostId, e.UserName });

modelBuilder.Entity<UpVote>().HasKey(e => new { e.PostId, e.UserName });

modelBuilder.Entity<DownVote>().HasKey(e => new { e.PostId, e.UserName });
Expand Down
10 changes: 10 additions & 0 deletions devblog/devblog/Interfaces/INotificationService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace devblog.Interfaces
{
public interface INotificationService
{
/// <summary>
/// Creates a noticication for a new post to every user
/// </summary>
Task Create(int PostId);
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions devblog/devblog/Migrations/20231111193006_noticication table.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace devblog.Migrations
{
/// <inheritdoc />
public partial class noticicationtable : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Notification",
columns: table => new
{
PostId = table.Column<int>(type: "int", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
Seen = table.Column<bool>(type: "tinyint(1)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Notification", x => x.PostId);
})
.Annotation("MySql:CharSet", "utf8mb4");
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Notification");
}
}
}
Loading

0 comments on commit c839aa9

Please sign in to comment.