Skip to content

Commit

Permalink
fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
balintgrober committed Sep 27, 2023
1 parent a612425 commit 3b4f24b
Show file tree
Hide file tree
Showing 14 changed files with 64 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<ListGradesFunction>();
}

[Function("list-grades")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Point> GetTotalPoints(AhkTaskResult[] value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ConfirmAutoGradeEventFunction>();
}

[Function("ConfirmAutoGradeEventFunction")]
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<SetGradeEventFunction>();
}


[Function("SetGradeEventFunction")]
public async Task Run([QueueTrigger("ahksetgrade", Connection = "AHK_EventsQueueConnectionString")] SetGradeEvent data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -24,7 +27,7 @@ public async Task AddGradeAsync(Grade value)
}
public async Task<Grade> 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);

Expand All @@ -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;
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -12,6 +13,6 @@ public interface IGradeService
Task<Grade> GetLastResultOfAsync(string neptun, string gitHubRepoName, int gitHubPrNumber);
Task<IReadOnlyCollection<Grade>> ListConfirmedWithRepositoryPrefixAsync(string repoPrefix);
Student FindStudentAsync(string neptun);
Assignment FindAssignment(string neptun);
Assignment FindAssignment(AhkTaskResult[] results);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions review-ui/Ahk.Review.Ui/Ahk.Review.Ui.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

<ItemGroup>
<PackageReference Include="AutoMapper" Version="12.0.1" />
<PackageReference Include="Blazored.LocalStorage" Version="4.4.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="7.0.5" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="7.0.5" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Cors" Version="2.2.0" />
Expand Down
18 changes: 12 additions & 6 deletions review-ui/Ahk.Review.Ui/Components/Header.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Microsoft.AspNetCore.Components;
using Newtonsoft.Json;
using Microsoft.JSInterop;
using Blazored.LocalStorage;

namespace Ahk.Review.Ui.Components
{
Expand All @@ -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<Subject> subjects = new List<Subject>();
Expand All @@ -24,17 +27,20 @@ protected override async void OnInitialized()
var results = await Service.GetSubjects();
subjects = results.ToList();

Service.TenantCode = JSRuntime.InvokeAsync<string>("localStorage.getItem", "SelectedTenantCode").Result;
Service.CurrentTenant = JSRuntime.InvokeAsync<Subject>("localStorage.getItem", "SelectedTenant").Result;
Service.TenantCode = await LocalStorage.GetItemAsStringAsync("SelectedTenantCode");
Service.CurrentTenant = JsonConvert.DeserializeObject<Subject>(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<string>("localStorage.setItem", "SelectedTenantCode", subjectCode);
JSRuntime.InvokeAsync<string>("localStorage.setItem", "SelectedTenant", subject);

await LocalStorage.SetItemAsStringAsync("SelectedTenantCode", subjectCode);
await LocalStorage.SetItemAsStringAsync("SelectedTenant", JsonConvert.SerializeObject(subject));
}
}
}
4 changes: 4 additions & 0 deletions review-ui/Ahk.Review.Ui/Pages/GroupPages/CreateGroup.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,6 +31,8 @@ private async void Submit()
};

await GroupService.CreateGroupAsync(SubjectService.CurrentTenant.Id.ToString(), group);

NavigationManager.NavigateTo("/subject-details");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

using Microsoft.AspNetCore.Components;

using Newtonsoft.Json;

namespace Ahk.Review.Ui.Pages.GroupPages
{
public partial class GroupDetails : ComponentBase
Expand All @@ -18,8 +20,8 @@ public partial class GroupDetails : ComponentBase
private NavigationManager NavigationManager { get; set; }

private Group group;
private List<Student> students;
private List<Teacher> teachers;
private List<Student> students = new List<Student>();
private List<Teacher> teachers = new List<Teacher>();

protected override async void OnInitialized()
{
Expand Down
4 changes: 4 additions & 0 deletions review-ui/Ahk.Review.Ui/Program.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -13,6 +16,7 @@
httpClient.BaseAddress = new Uri(builder.Configuration.GetSection("baseAddress").Value);
});
builder.Services.AddMudServices();
builder.Services.AddBlazoredLocalStorage();

var mapper = MapperConfig.InitializeAutomapper();

Expand Down
2 changes: 2 additions & 0 deletions review-ui/Ahk.Review.Ui/Services/AssignmentService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public async Task<Assignment> 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;
}

Expand Down
3 changes: 2 additions & 1 deletion review-ui/Ahk.Review.Ui/Services/GroupService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public async Task<Group> GetGroupAsync(string subject, string groupId)

public async Task UpdateGroupAsync(string subject, Group group)
{
await httpClient.PostAsJsonAsync<GroupDTO>($"edit-group/{subject}", Mapper.Map<GroupDTO>(group));
Console.WriteLine(JsonConvert.SerializeObject(group));
await httpClient.PostAsJsonAsync<GroupDTO>($"edit-group", Mapper.Map<GroupDTO>(group));
}

public async Task DeleteGroupAsync(string groupId)
Expand Down

0 comments on commit 3b4f24b

Please sign in to comment.