From 3b4f24b33f4def6371fe46a6d2dec4ae70ca46b8 Mon Sep 17 00:00:00 2001 From: balintgrober Date: Wed, 27 Sep 2023 20:35:56 +0200 Subject: [PATCH] fix bugs --- .../Functions/ListGrades/ListGradesFunction.cs | 6 ++++-- .../ResultProcessing/ResultProcessor.cs | 2 +- .../SetGrade/ConfirmAutoGradeEventFunction.cs | 4 ++-- .../SetGrade/SetGradeEventFunction.cs | 7 ++++--- .../Services/GradeService/GradeService.cs | 12 +++++++++--- .../Services/GradeService/IGradeService.cs | 3 ++- .../Services/GroupService/GroupService.cs | 13 +++++++++++++ review-ui/Ahk.Review.Ui/Ahk.Review.Ui.csproj | 1 + .../Ahk.Review.Ui/Components/Header.razor.cs | 18 ++++++++++++------ .../Pages/GroupPages/CreateGroup.razor.cs | 4 ++++ .../Pages/GroupPages/GroupDetails.razor.cs | 6 ++++-- review-ui/Ahk.Review.Ui/Program.cs | 4 ++++ .../Services/AssignmentService.cs | 2 ++ .../Ahk.Review.Ui/Services/GroupService.cs | 3 ++- 14 files changed, 64 insertions(+), 21 deletions(-) diff --git a/grade-management/Ahk.GradeManagement/Functions/ListGrades/ListGradesFunction.cs b/grade-management/Ahk.GradeManagement/Functions/ListGrades/ListGradesFunction.cs index bdbec302..75b03cf4 100644 --- a/grade-management/Ahk.GradeManagement/Functions/ListGrades/ListGradesFunction.cs +++ b/grade-management/Ahk.GradeManagement/Functions/ListGrades/ListGradesFunction.cs @@ -1,6 +1,8 @@ using System; using System.Text; using System.Threading.Tasks; +using Ahk.GradeManagement.Functions.Groups; + using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Azure.Functions.Worker; @@ -14,10 +16,10 @@ public class ListGradesFunction private readonly IGradeListing service; private readonly ILogger logger; - public ListGradesFunction(IGradeListing service, ILogger logger) + public ListGradesFunction(IGradeListing service, ILoggerFactory loggerFactory) { this.service = service; - this.logger = logger; + this.logger = loggerFactory.CreateLogger(); } [Function("list-grades")] diff --git a/grade-management/Ahk.GradeManagement/Functions/ResultProcessing/ResultProcessor.cs b/grade-management/Ahk.GradeManagement/Functions/ResultProcessing/ResultProcessor.cs index 121f1886..5e70aaaa 100644 --- a/grade-management/Ahk.GradeManagement/Functions/ResultProcessing/ResultProcessor.cs +++ b/grade-management/Ahk.GradeManagement/Functions/ResultProcessing/ResultProcessor.cs @@ -33,7 +33,7 @@ public Task ProcessResultAsync(AhkProcessResult value, System.DateTime dateTime) Origin = formatOrigin(value), Points = GetTotalPoints(value.Result), IsConfirmed = false, - Assignment = service.FindAssignment(value.NeptunCode) + Assignment = service.FindAssignment(value.Result) }); internal static System.Collections.Generic.List GetTotalPoints(AhkTaskResult[] value) diff --git a/grade-management/Ahk.GradeManagement/Functions/SetGrade/ConfirmAutoGradeEventFunction.cs b/grade-management/Ahk.GradeManagement/Functions/SetGrade/ConfirmAutoGradeEventFunction.cs index b3399ba9..98d6d38a 100644 --- a/grade-management/Ahk.GradeManagement/Functions/SetGrade/ConfirmAutoGradeEventFunction.cs +++ b/grade-management/Ahk.GradeManagement/Functions/SetGrade/ConfirmAutoGradeEventFunction.cs @@ -10,10 +10,10 @@ public class ConfirmAutoGradeEventFunction { private readonly ISetGradeService service; private readonly ILogger logger; - public ConfirmAutoGradeEventFunction(ISetGradeService service, ILogger logger) + public ConfirmAutoGradeEventFunction(ISetGradeService service, ILoggerFactory loggerFactory) { this.service = service; - this.logger = logger; + this.logger = loggerFactory.CreateLogger(); } [Function("ConfirmAutoGradeEventFunction")] diff --git a/grade-management/Ahk.GradeManagement/Functions/SetGrade/SetGradeEventFunction.cs b/grade-management/Ahk.GradeManagement/Functions/SetGrade/SetGradeEventFunction.cs index 91836645..d7647fc0 100644 --- a/grade-management/Ahk.GradeManagement/Functions/SetGrade/SetGradeEventFunction.cs +++ b/grade-management/Ahk.GradeManagement/Functions/SetGrade/SetGradeEventFunction.cs @@ -1,5 +1,7 @@ using System; using System.Threading.Tasks; + +using Ahk.GradeManagement.Functions.Groups; using Ahk.GradeManagement.Services.SetGradeService; using Microsoft.Azure.Functions.Worker; using Microsoft.Extensions.Logging; @@ -11,12 +13,11 @@ public class SetGradeEventFunction private readonly ISetGradeService service; private readonly ILogger logger; - public SetGradeEventFunction(ISetGradeService service, ILogger logger) + public SetGradeEventFunction(ISetGradeService service, ILoggerFactory loggerFactory) { this.service = service; - this.logger = logger; + this.logger = loggerFactory.CreateLogger(); } - [Function("SetGradeEventFunction")] public async Task Run([QueueTrigger("ahksetgrade", Connection = "AHK_EventsQueueConnectionString")] SetGradeEvent data) diff --git a/grade-management/Ahk.GradeManagement/Services/GradeService/GradeService.cs b/grade-management/Ahk.GradeManagement/Services/GradeService/GradeService.cs index 70b2c7bd..7ebae34d 100644 --- a/grade-management/Ahk.GradeManagement/Services/GradeService/GradeService.cs +++ b/grade-management/Ahk.GradeManagement/Services/GradeService/GradeService.cs @@ -6,6 +6,9 @@ using System.Threading.Tasks; using Ahk.GradeManagement.Data; using Ahk.GradeManagement.Data.Entities; +using Ahk.GradeManagement.ResultProcessing.Dto; + +using Microsoft.EntityFrameworkCore; namespace Ahk.GradeManagement.Services { @@ -24,7 +27,7 @@ public async Task AddGradeAsync(Grade value) } public async Task GetLastResultOfAsync(string neptun, string gitHubRepoName, int gitHubPrNumber) { - var grades = Context.Grades + var grades = Context.Grades.Include(g => g.Student).Include(g => g.Assignment) .Where(s => s.Student.Neptun == neptun.ToUpperInvariant() && s.GithubRepoName == gitHubRepoName.ToLowerInvariant() && s.GithubPrNumber == gitHubPrNumber) .OrderByDescending(s => s.Date); @@ -50,9 +53,12 @@ public Student FindStudentAsync(string neptun) return Context.Students.Where(s => s.Neptun == neptun).FirstOrDefault(); } - public Assignment FindAssignment(string neptun) + public Assignment FindAssignment(AhkTaskResult[] results) { - return Context.StudentAssignments.Where(sa => sa.Student.Neptun == neptun).Select(sa => sa.Assignment).FirstOrDefault(); + string firstExercise = results[0].ExerciseName; + var assignment = Context.Exercises.Include(e => e.Assignment).Where(e => e.Name == firstExercise).Select(e => e.Assignment).FirstOrDefault(); + + return assignment; } } diff --git a/grade-management/Ahk.GradeManagement/Services/GradeService/IGradeService.cs b/grade-management/Ahk.GradeManagement/Services/GradeService/IGradeService.cs index 52870e28..81121de6 100644 --- a/grade-management/Ahk.GradeManagement/Services/GradeService/IGradeService.cs +++ b/grade-management/Ahk.GradeManagement/Services/GradeService/IGradeService.cs @@ -2,6 +2,7 @@ using System.Threading.Tasks; using Ahk.GradeManagement.Data; using Ahk.GradeManagement.Data.Entities; +using Ahk.GradeManagement.ResultProcessing.Dto; namespace Ahk.GradeManagement.Services { @@ -12,6 +13,6 @@ public interface IGradeService Task GetLastResultOfAsync(string neptun, string gitHubRepoName, int gitHubPrNumber); Task> ListConfirmedWithRepositoryPrefixAsync(string repoPrefix); Student FindStudentAsync(string neptun); - Assignment FindAssignment(string neptun); + Assignment FindAssignment(AhkTaskResult[] results); } } diff --git a/grade-management/Ahk.GradeManagement/Services/GroupService/GroupService.cs b/grade-management/Ahk.GradeManagement/Services/GroupService/GroupService.cs index 181e6142..df712fa0 100644 --- a/grade-management/Ahk.GradeManagement/Services/GroupService/GroupService.cs +++ b/grade-management/Ahk.GradeManagement/Services/GroupService/GroupService.cs @@ -91,6 +91,19 @@ public async Task AddStudentToGroupAsync(string subjectCode, string groupId, Stu Subject = subject, }; + var assignments = Context.Assignments.Include(a => a.Subject).Where(a => a.Subject.SubjectCode == subjectCode).ToList(); + + foreach (var assignment in assignments) + { + StudentAssignment studentAssignment = new StudentAssignment + { + Student = student, + Assignment = assignment, + }; + + Context.StudentAssignments.Add(studentAssignment); + } + if (!Context.StudentSubjects.Where(ss => ss.Subject.SubjectCode == subject.SubjectCode && ss.Student.Neptun.ToLower() == student.Neptun.ToLower()).Any()) { Context.StudentSubjects.Add(studentSubject); diff --git a/review-ui/Ahk.Review.Ui/Ahk.Review.Ui.csproj b/review-ui/Ahk.Review.Ui/Ahk.Review.Ui.csproj index adceea65..25b64be2 100644 --- a/review-ui/Ahk.Review.Ui/Ahk.Review.Ui.csproj +++ b/review-ui/Ahk.Review.Ui/Ahk.Review.Ui.csproj @@ -17,6 +17,7 @@ + diff --git a/review-ui/Ahk.Review.Ui/Components/Header.razor.cs b/review-ui/Ahk.Review.Ui/Components/Header.razor.cs index edfb2979..175f472c 100644 --- a/review-ui/Ahk.Review.Ui/Components/Header.razor.cs +++ b/review-ui/Ahk.Review.Ui/Components/Header.razor.cs @@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Components; using Newtonsoft.Json; using Microsoft.JSInterop; +using Blazored.LocalStorage; namespace Ahk.Review.Ui.Components { @@ -14,6 +15,8 @@ public partial class Header : ComponentBase private NavigationManager NavigationManager { get; set; } [Inject] private IJSRuntime JSRuntime { get; set; } + [Inject] + private ILocalStorageService LocalStorage { get; set; } private string subjectCode = string.Empty; private List subjects = new List(); @@ -24,17 +27,20 @@ protected override async void OnInitialized() var results = await Service.GetSubjects(); subjects = results.ToList(); - Service.TenantCode = JSRuntime.InvokeAsync("localStorage.getItem", "SelectedTenantCode").Result; - Service.CurrentTenant = JSRuntime.InvokeAsync("localStorage.getItem", "SelectedTenant").Result; + Service.TenantCode = await LocalStorage.GetItemAsStringAsync("SelectedTenantCode"); + Service.CurrentTenant = JsonConvert.DeserializeObject(await LocalStorage.GetItemAsStringAsync("SelectedTenant")); + + subjectCode = Service.TenantCode; + + StateHasChanged(); } - private void SetTenant() + private async void SetTenant() { var subject = subjects.Where(s => s.SubjectCode == subjectCode).FirstOrDefault(); Service.SetCurrentTenant(subjectCode, subject); - JSRuntime.InvokeAsync("localStorage.setItem", "SelectedTenantCode", subjectCode); - JSRuntime.InvokeAsync("localStorage.setItem", "SelectedTenant", subject); - + await LocalStorage.SetItemAsStringAsync("SelectedTenantCode", subjectCode); + await LocalStorage.SetItemAsStringAsync("SelectedTenant", JsonConvert.SerializeObject(subject)); } } } diff --git a/review-ui/Ahk.Review.Ui/Pages/GroupPages/CreateGroup.razor.cs b/review-ui/Ahk.Review.Ui/Pages/GroupPages/CreateGroup.razor.cs index 98b8c7b4..f749bed7 100644 --- a/review-ui/Ahk.Review.Ui/Pages/GroupPages/CreateGroup.razor.cs +++ b/review-ui/Ahk.Review.Ui/Pages/GroupPages/CreateGroup.razor.cs @@ -10,6 +10,8 @@ public partial class CreateGroup : ComponentBase private GroupService GroupService { get; set; } [Inject] private SubjectService SubjectService { get; set; } + [Inject] + private NavigationManager NavigationManager { get; set; } private string name; private string room; @@ -29,6 +31,8 @@ private async void Submit() }; await GroupService.CreateGroupAsync(SubjectService.CurrentTenant.Id.ToString(), group); + + NavigationManager.NavigateTo("/subject-details"); } } } diff --git a/review-ui/Ahk.Review.Ui/Pages/GroupPages/GroupDetails.razor.cs b/review-ui/Ahk.Review.Ui/Pages/GroupPages/GroupDetails.razor.cs index 5511c5f8..403396e3 100644 --- a/review-ui/Ahk.Review.Ui/Pages/GroupPages/GroupDetails.razor.cs +++ b/review-ui/Ahk.Review.Ui/Pages/GroupPages/GroupDetails.razor.cs @@ -3,6 +3,8 @@ using Microsoft.AspNetCore.Components; +using Newtonsoft.Json; + namespace Ahk.Review.Ui.Pages.GroupPages { public partial class GroupDetails : ComponentBase @@ -18,8 +20,8 @@ public partial class GroupDetails : ComponentBase private NavigationManager NavigationManager { get; set; } private Group group; - private List students; - private List teachers; + private List students = new List(); + private List teachers = new List(); protected override async void OnInitialized() { diff --git a/review-ui/Ahk.Review.Ui/Program.cs b/review-ui/Ahk.Review.Ui/Program.cs index 296ab9ca..12280265 100644 --- a/review-ui/Ahk.Review.Ui/Program.cs +++ b/review-ui/Ahk.Review.Ui/Program.cs @@ -1,5 +1,8 @@ using Ahk.Review.Ui; using Ahk.Review.Ui.Services; + +using Blazored.LocalStorage; + using Microsoft.AspNetCore.Components.Web; using Microsoft.AspNetCore.Components.WebAssembly.Hosting; using MudBlazor.Services; @@ -13,6 +16,7 @@ httpClient.BaseAddress = new Uri(builder.Configuration.GetSection("baseAddress").Value); }); builder.Services.AddMudServices(); +builder.Services.AddBlazoredLocalStorage(); var mapper = MapperConfig.InitializeAutomapper(); diff --git a/review-ui/Ahk.Review.Ui/Services/AssignmentService.cs b/review-ui/Ahk.Review.Ui/Services/AssignmentService.cs index f8096845..529cb2f9 100644 --- a/review-ui/Ahk.Review.Ui/Services/AssignmentService.cs +++ b/review-ui/Ahk.Review.Ui/Services/AssignmentService.cs @@ -44,6 +44,8 @@ public async Task GetAssignmentAsync(string subject, string assignme var assignments = await GetAssignmentsAsync(subject); var assignment = assignments.Where(a => a.Id.ToString() == assignmentId).FirstOrDefault(); + Console.WriteLine(JsonConvert.SerializeObject(assignment)); + return assignment; } diff --git a/review-ui/Ahk.Review.Ui/Services/GroupService.cs b/review-ui/Ahk.Review.Ui/Services/GroupService.cs index fbd3f3ad..873eb616 100644 --- a/review-ui/Ahk.Review.Ui/Services/GroupService.cs +++ b/review-ui/Ahk.Review.Ui/Services/GroupService.cs @@ -47,7 +47,8 @@ public async Task GetGroupAsync(string subject, string groupId) public async Task UpdateGroupAsync(string subject, Group group) { - await httpClient.PostAsJsonAsync($"edit-group/{subject}", Mapper.Map(group)); + Console.WriteLine(JsonConvert.SerializeObject(group)); + await httpClient.PostAsJsonAsync($"edit-group", Mapper.Map(group)); } public async Task DeleteGroupAsync(string groupId)