Skip to content

Commit c839aa9

Browse files
committed
Add notification service
1 parent 3bd8a8d commit c839aa9

18 files changed

+1110
-26
lines changed

devblog/devblog/ClientApp/src/global.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ button:hover {
55

66
main {
77
width: 1100px;
8-
margin: auto
8+
margin: auto;
99
}
1010

1111
@media (max-width: 1000px) {
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using devblog.Interfaces;
2+
using devblog.Services;
3+
using Microsoft.AspNetCore.Mvc;
4+
5+
namespace devblog.Controllers
6+
{
7+
[ApiController]
8+
[Route("api/[controller]")]
9+
public class NotificationController : ControllerBase
10+
{
11+
private readonly INotificationService _notifications;
12+
13+
public NotificationController(NotificationService notifications)
14+
{
15+
_notifications = notifications;
16+
}
17+
18+
public async Task Get()
19+
{
20+
21+
}
22+
}
23+
}

devblog/devblog/Controllers/PostsController.cs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,13 @@ namespace devblog.Controllers
1010
public class PostsController : ControllerBase
1111
{
1212
private readonly IPostService _posts;
13-
private readonly IImgService _imgService;
14-
15-
public PostsController(IPostService posts, IImgService imgService)
13+
private readonly IImgService _imgs;
14+
public PostsController(IPostService posts, IImgService imgs)
1615
{
1716
_posts = posts;
18-
_imgService = imgService;
17+
_imgs = imgs;
1918
}
2019

21-
/// <summary>
22-
/// Retrieves all posts
23-
/// </summary>
24-
/// <returns>List<Post></returns>
25-
//[HttpGet]
26-
//public async Task<List<Post>> Get()
27-
//{
28-
// var posts = await _posts.Get();
29-
// return posts;
30-
//}
31-
3220
[HttpGet("page/{pageNum}")]
3321
public async Task<List<Post>> GetPage(int pageNum)
3422
{
@@ -107,7 +95,7 @@ public async Task<Post> Update(int id, [FromBody] string description)
10795
public async Task Delete(int id)
10896
{
10997
var imgs = _posts.Get(id).Result.Imgs;
110-
await _imgService.DeleteImgFromDropBox(imgs);
98+
await _imgs.DeleteImgFromDropBox(imgs);
11199
await _posts.Delete(id);
112100
}
113101
}

devblog/devblog/Data/AppDbContext.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using devblog.Models;
2-
using Discord;
32
using Microsoft.EntityFrameworkCore;
43

54
namespace devblog.Data
@@ -12,6 +11,7 @@ public class AppDbContext : DbContext
1211
public DbSet<DownVote> DownVote { get; set; }
1312
public DbSet<Img> Img { get; set; }
1413
public DbSet<YtVideo> YtVideo { get; set; }
14+
public DbSet<Notification> Notification { get; set; }
1515

1616
public AppDbContext(DbContextOptions<AppDbContext> opt) : base(opt)
1717
{
@@ -21,6 +21,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
2121
{
2222
base.OnModelCreating(modelBuilder);
2323

24+
modelBuilder.Entity<Notification>().HasKey(e => new { e.PostId, e.UserName });
25+
2426
modelBuilder.Entity<UpVote>().HasKey(e => new { e.PostId, e.UserName });
2527

2628
modelBuilder.Entity<DownVote>().HasKey(e => new { e.PostId, e.UserName });
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace devblog.Interfaces
2+
{
3+
public interface INotificationService
4+
{
5+
/// <summary>
6+
/// Creates a noticication for a new post to every user
7+
/// </summary>
8+
Task Create(int PostId);
9+
}
10+
}

devblog/devblog/Migrations/20231111193006_noticication table.Designer.cs

Lines changed: 203 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using Microsoft.EntityFrameworkCore.Metadata;
2+
using Microsoft.EntityFrameworkCore.Migrations;
3+
4+
#nullable disable
5+
6+
namespace devblog.Migrations
7+
{
8+
/// <inheritdoc />
9+
public partial class noticicationtable : Migration
10+
{
11+
/// <inheritdoc />
12+
protected override void Up(MigrationBuilder migrationBuilder)
13+
{
14+
migrationBuilder.CreateTable(
15+
name: "Notification",
16+
columns: table => new
17+
{
18+
PostId = table.Column<int>(type: "int", nullable: false)
19+
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
20+
Seen = table.Column<bool>(type: "tinyint(1)", nullable: false)
21+
},
22+
constraints: table =>
23+
{
24+
table.PrimaryKey("PK_Notification", x => x.PostId);
25+
})
26+
.Annotation("MySql:CharSet", "utf8mb4");
27+
}
28+
29+
/// <inheritdoc />
30+
protected override void Down(MigrationBuilder migrationBuilder)
31+
{
32+
migrationBuilder.DropTable(
33+
name: "Notification");
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)