Skip to content
Open
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
4c06e83
feat: add HangFire settings to startup and app settings.
BakhorikovEgor Sep 22, 2023
248c316
feat: add delete and update delayed methods for tasks
BakhorikovEgor Sep 25, 2023
4443ebb
feat: Moved hangfire to NotificationsService
BakhorikovEgor Oct 6, 2023
8557b6c
feat: create ScheduleEvent
BakhorikovEgor Oct 8, 2023
6e0d6ca
feat: add UpdateScheduleEvent class
BakhorikovEgor Oct 8, 2023
20d7fbf
fix: delete delayed logic from CourseService
BakhorikovEgor Oct 23, 2023
635920d
feat: change ScheduleWork id to string
BakhorikovEgor Oct 23, 2023
f3a7d6a
feat: add and delete delayed task events and eventhandlers
BakhorikovEgor Oct 26, 2023
ac1eaa0
feat: add delete update task events and eventhandlers are written
BakhorikovEgor Oct 27, 2023
53e2616
fix: style fixes
BakhorikovEgor Nov 15, 2023
2cb1af1
feat: bear main schedule event handler logic
BakhorikovEgor Nov 19, 2023
1a9e978
feat: transfer CourseDataFilterAttribute.cs to ApiGateway
BakhorikovEgor Nov 22, 2023
323dfd2
feat: add lazy getting course data in task event-handlers
BakhorikovEgor Nov 22, 2023
1d4d5b5
feat: change part of ScheduleWorkId
BakhorikovEgor Nov 22, 2023
eab2e10
Merge pull request #340 from InteIIigeNET/TransferringCourseDataFilter
BakhorikovEgor Dec 2, 2023
d220d21
feat: transfer hangfire dashboard to apigateway
BakhorikovEgor Dec 3, 2023
6476105
Revert "feat: transfer hangfire dashboard to apigateway"
BakhorikovEgor Jan 7, 2024
7ca52e4
fix: composite delayed job key
BakhorikovEgor Feb 16, 2024
5d50b4a
feat: better choice for continuation
BakhorikovEgor Feb 16, 2024
3017b8f
fix: style fixes
BakhorikovEgor Feb 16, 2024
8d8cec2
fix: duplicate reference fix
BakhorikovEgor Feb 23, 2024
70d9ec8
wip
DedSec256 Feb 25, 2024
dac4582
feat: change update extension to rescheduling + add lazy addorupdate…
BakhorikovEgor Mar 6, 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
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using HwProj.APIGateway.API.Filters;
using HwProj.APIGateway.API.Models;
using HwProj.AuthService.Client;
using HwProj.CoursesService.Client;
Expand Down Expand Up @@ -34,6 +35,7 @@ public async Task<CoursePreviewView[]> GetAllCourses()
return result;
}

[CourseDataFilter]
[HttpGet("{courseId}")]
[ProducesResponseType(typeof(CourseViewModel), (int)HttpStatusCode.OK)]
public async Task<IActionResult> GetCourseData(long courseId)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using HwProj.Models;
using HwProj.Models.AuthService.DTO;
using HwProj.Models.CoursesService.ViewModels;
using HwProj.Utils.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;

namespace HwProj.CoursesService.API.Filters
namespace HwProj.APIGateway.API.Filters
{
public class CourseDataFilterAttribute : ResultFilterAttribute
{
public override async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next)
{
var userId = context.HttpContext.Request.GetUserIdFromHeader();
var userId = context.HttpContext.User.Claims
.FirstOrDefault(claim => claim.Type.ToString() == "_id")
?.Value;;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var userId = context.HttpContext.User.Claims
.FirstOrDefault(claim => claim.Type.ToString() == "_id")
?.Value;;
var userId = context.HttpContext.User.FindFirst("_id");


if (userId == null)
{
Expand All @@ -22,25 +25,22 @@ public override async Task OnResultExecutionAsync(ResultExecutingContext context
else
{
var result = context.Result as ObjectResult;
if (result?.Value is CourseDTO courseDto && !courseDto.MentorIds.Contains(userId))
if (result?.Value is CourseViewModel courseViewModel &&
courseViewModel.Mentors.All(mentor => mentor.UserId != userId))
{
var currentDate = DateTimeUtils.GetMoscowNow();
foreach (var homework in courseDto.Homeworks)
foreach (var homework in courseViewModel.Homeworks)
{
homework.Tasks =
new List<HomeworkTaskViewModel>(homework.Tasks.Where(t =>
currentDate >= t.PublicationDate));
}

courseDto.CourseMates = courseDto.CourseMates
.Where(t => t.IsAccepted || t.StudentId == userId)
.ToArray();

courseDto.Groups = courseDto.Groups.Where(g => g.StudentsIds.Contains(userId)).ToArray();
courseViewModel.NewStudents = Array.Empty<AccountDataDto>();
}
}

await next();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Hangfire" Version="1.8.6" />
<PackageReference Include="Hangfire.AspNetCore" Version="1.8.6" />
<PackageReference Include="Hangfire.Core" Version="1.8.6" />
<PackageReference Include="Hangfire.Dashboard.Authorization" Version="3.0.1" />
<PackageReference Include="Microsoft.AspNetCore.All" />
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.2.3" />
Expand All @@ -20,6 +24,7 @@
<ProjectReference Include="..\..\HwProj.AuthService\HwProj.AuthService.Client\HwProj.AuthService.Client.csproj" />
<ProjectReference Include="..\..\HwProj.Common\HwProj.Utils\HwProj.Utils.csproj" />
<ProjectReference Include="..\..\HwProj.CoursesService\HwProj.CoursesService.Client\HwProj.CoursesService.Client.csproj" />
<ProjectReference Include="..\..\HwProj.NotificationsService\HwProj.NotificationsService.API\HwProj.NotificationsService.API.csproj" />
<ProjectReference Include="..\..\HwProj.NotificationsService\HwProj.NotificationsService.Client\HwProj.NotificationsService.Client.csproj" />
<ProjectReference Include="..\..\HwProj.SolutionsService\HwProj.SolutionsService.Client\HwProj.SolutionsService.Client.csproj" />
</ItemGroup>
Expand Down
20 changes: 17 additions & 3 deletions HwProj.APIGateway/HwProj.APIGateway.API/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using HwProj.AuthService.Client;
using Hangfire;
using Hangfire.SqlServer;
using HwProj.AuthService.Client;
using HwProj.CoursesService.Client;
using HwProj.NotificationsService.Client;
using HwProj.SolutionsService.Client;
Expand All @@ -25,8 +27,15 @@ public void ConfigureServices(IServiceCollection services)
{
services.ConfigureHwProjServices("API Gateway");

const string authenticationProviderKey = "GatewayKey";
services.AddHangfire(configuration => configuration
.SetDataCompatibilityLevel(CompatibilityLevel.Version_180)
.UseSimpleAssemblyNameTypeSerializer()
.UseRecommendedSerializerSettings()
.UseSqlServerStorage(Configuration.GetConnectionString("HangfireConnection")));


const string authenticationProviderKey = "GatewayKey";

services.AddAuthentication()
.AddJwtBearer(authenticationProviderKey, x =>
{
Expand Down Expand Up @@ -54,6 +63,11 @@ public void ConfigureServices(IServiceCollection services)
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.ConfigureHwProj(env, "API Gateway");

if (env.IsDevelopment())
{
app.UseHangfireDashboard("/jobs");
}
}
}
}
}
4 changes: 4 additions & 0 deletions HwProj.APIGateway/HwProj.APIGateway.API/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,9 @@
"Courses": "http://localhost:5002",
"Notifications": "http://localhost:5006",
"Solutions": "http://localhost:5007"
},

"ConnectionStrings": {
"HangfireConnection": "Server=(localdb)\\mssqllocaldb;Database=HangfireDB;Trusted_Connection=True;"
}
}
13 changes: 13 additions & 0 deletions HwProj.Common/HwProj.Events/HwProj.Events.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<RootNamespace>HwProj.Events2</RootNamespace>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\HwProj.EventBus\HwProj.EventBus.Client\HwProj.EventBus.Client.csproj" />
<ProjectReference Include="..\HwProj.Models\HwProj.Models.csproj" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion HwProj.Common/HwProj.HttpUtils/RequestHeaderBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public static class RequestHeaderBuilder
{
public static void TryAddUserId(this HttpRequestMessage request, IHttpContextAccessor httpContextAccessor)
{
var userId = httpContextAccessor.HttpContext.User.FindFirst("_id");
var userId = httpContextAccessor.HttpContext?.User.FindFirst("_id");
if (userId != null) request.Headers.Add("UserId", userId.Value);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ public class HomeworkTaskViewModel
public bool IsDeferred { get; set; }
}


public class HomeworkTaskDTO
{
public long Id { get; set; }

public string Title { get; set; }

public DateTime PublicationDate { get; set; }

public DateTime? DeadlineDate { get; set; }
}

public class CreateTaskViewModel
{
[Required]
Expand Down Expand Up @@ -57,4 +69,4 @@ public void InitializeDeadline()
}
}
}
}
}
14 changes: 14 additions & 0 deletions HwProj.Common/HwProj.Models/Events/CourseEvents/DeleteTaskEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using HwProj.EventBus.Client;

namespace HwProj.Models.Events.CourseEvents
{
public class DeleteTaskEvent : Event
{
public long TaskId { get; set; }

public DeleteTaskEvent(long taskId)
{
TaskId = taskId;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using HwProj.EventBus.Client;

namespace HwProj.CoursesService.API.Events
namespace HwProj.Models.Events.CourseEvents
{
public class LecturerAcceptToCourseEvent : Event
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using HwProj.EventBus.Client;

namespace HwProj.CoursesService.API.Events
namespace HwProj.Models.Events.CourseEvents
{
public class LecturerInvitedToCourseEvent : Event
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using HwProj.EventBus.Client;

namespace HwProj.CoursesService.API.Events
namespace HwProj.Models.Events.CourseEvents
{
public class LecturerRejectToCourseEvent : Event
{
Expand All @@ -9,4 +9,4 @@ public class LecturerRejectToCourseEvent : Event
public string MentorIds { get; set; }
public string StudentId { get; set; }
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using HwProj.EventBus.Client;

namespace HwProj.CoursesService.API.Events
namespace HwProj.Models.Events.CourseEvents
{
public class NewCourseMateEvent : Event
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using HwProj.EventBus.Client;
using HwProj.Models.CoursesService.ViewModels;

namespace HwProj.CoursesService.API.Events
namespace HwProj.Models.Events.CourseEvents
{
public class NewHomeworkEvent : Event
{
Expand All @@ -14,4 +14,4 @@ public NewHomeworkEvent(string homework, CourseDTO course)
Course = course;
}
}
}
}
23 changes: 23 additions & 0 deletions HwProj.Common/HwProj.Models/Events/CourseEvents/NewTaskEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using HwProj.EventBus.Client;
using HwProj.Models.CoursesService.ViewModels;

namespace HwProj.Models.Events.CourseEvents
{
public class NewTaskEvent : Event
{
public long TaskId { get; set; }

public HomeworkTaskDTO Task { get; set; }

public CourseDTO Course { get; set; }


public NewTaskEvent(long taskId, HomeworkTaskDTO task, CourseDTO course)
{
TaskId = taskId;
Task = task;
Course = course;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using HwProj.EventBus.Client;
using HwProj.Models.CoursesService.ViewModels;

namespace HwProj.CoursesService.API.Events
namespace HwProj.Models.Events.CourseEvents
{
public class UpdateHomeworkEvent : Event
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using HwProj.EventBus.Client;

namespace HwProj.CoursesService.API.Events
namespace HwProj.Models.Events.CourseEvents
{
public class UpdateSolutionMaxRatingEvent : Event
{
Expand Down
26 changes: 26 additions & 0 deletions HwProj.Common/HwProj.Models/Events/CourseEvents/UpdateTaskEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using HwProj.EventBus.Client;
using HwProj.Models.CoursesService.ViewModels;

namespace HwProj.Models.Events.CourseEvents
{
public class UpdateTaskEvent : Event
{
public long TaskId { get; set; }

public HomeworkTaskDTO PreviousEvent { get; set; }

public HomeworkTaskDTO NewEvent { get; set; }

public CourseDTO Course { get; set; }


public UpdateTaskEvent(long taskId, HomeworkTaskDTO previousEvent, HomeworkTaskDTO newEvent, CourseDTO course)
{
TaskId = taskId;
PreviousEvent = previousEvent;
NewEvent = newEvent;
Course = course;
}
}
}
4 changes: 3 additions & 1 deletion HwProj.Common/HwProj.Models/HwProj.Models.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.2.3" />
<PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="2.2.0" />
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\HwProj.EventBus\HwProj.EventBus.Client\HwProj.EventBus.Client.csproj" />
<ProjectReference Include="..\HwProj.Repositories\HwProj.Repositories.csproj" />
</ItemGroup>

<ItemGroup>
<Folder Include="CoursesService" />
<Folder Include="Events\" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public enum CategoryState
None,
Profile,
Courses,
Homeworks
Homeworks,
Tasks
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Думаю, нам не нужно это изменение

}
}
Loading