Skip to content

Commit

Permalink
Update dependencies + query groups + tenant selector
Browse files Browse the repository at this point in the history
  • Loading branch information
balintgrober committed Sep 11, 2023
1 parent 29b198b commit c0f436d
Show file tree
Hide file tree
Showing 14 changed files with 101 additions and 40 deletions.
12 changes: 6 additions & 6 deletions grade-management/Ahk.GradeManagement/Ahk.GradeManagement.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@

<ItemGroup>
<PackageReference Include="AutoMapper.EF6" Version="3.0.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.14.1" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Core" Version="1.12.1" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.0.13" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" Version="1.0.0-preview1" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Storage" Version="5.0.1" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.10.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.19.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Core" Version="1.15.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.1.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" Version="1.0.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Storage" Version="6.2.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.14.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System.Net;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.Extensions.Logging;

namespace Ahk.GradeManagement.Functions.Groups
{
public class DeleteGroupFunction
{
private readonly ILogger _logger;

public DeleteGroupFunction(ILoggerFactory loggerFactory)
{
_logger = loggerFactory.CreateLogger<DeleteGroupFunction>();
}

[Function("delete-group")]
public HttpResponseData Run([HttpTrigger(AuthorizationLevel.Anonymous, "delete", Route = "delete-group/{subject}/{id}")] HttpRequestData req, string subject, int id)
{
_logger.LogInformation("C# HTTP trigger function processed a request.");

var response = req.CreateResponse(HttpStatusCode.OK);
response.Headers.Add("Content-Type", "text/plain; charset=utf-8");

response.WriteString("Welcome to Azure Functions!");

return response;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
using System.Collections.Generic;
using System.Net;
using System.Threading.Tasks;
using Ahk.GradeManagement.Services;
using Ahk.GradeManagement.Services.GroupService;
using AutoMapper;
using DTOs;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.Extensions.Logging;
Expand All @@ -8,23 +16,24 @@ namespace Ahk.GradeManagement.Functions.Groups
public class ListGroupsFunction
{
private readonly ILogger _logger;
private readonly IGroupService groupService;
private readonly Mapper mapper;

public ListGroupsFunction(ILoggerFactory loggerFactory)
public ListGroupsFunction(ILoggerFactory loggerFactory, IGroupService groupService, Mapper mapper)
{
_logger = loggerFactory.CreateLogger<ListGroupsFunction>();
this.groupService = groupService;
this.mapper = mapper;
}

[Function("list-groups")]
public HttpResponseData Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "list-groups/{*subject}")] HttpRequestData req, string subject)
public async Task<IActionResult> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "list-groups/{subject}")] HttpRequest req, string subject)
{
_logger.LogInformation("C# HTTP trigger function processed a request.");

var response = req.CreateResponse(HttpStatusCode.OK);
response.Headers.Add("Content-Type", "text/plain; charset=utf-8");
var results = mapper.Map<List<GroupDTO>>(await groupService.ListGroupsAsync(subject));

response.WriteString("Welcome to Azure Functions!");

return response;
return new OkObjectResult(results);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using Ahk.GradeManagement.Services.StatusTrackingService;
Expand All @@ -24,12 +25,13 @@ public GetSubjectsFunction(ILoggerFactory loggerFactory, ISubjectService service
this.mapper = mapper;
}

[Function("GetSubjectsFunction")]
[Function("list-subjects")]
public async Task<IActionResult> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "list-subjects")] HttpRequestData req)
{
_logger.LogInformation($"Received request to list all subjects");

var results = mapper.Map<SubjectDTO>(service.GetAllSubjects());
var subjects = service.GetAllSubjects();
var results = subjects.Select(subject => mapper.Map<SubjectDTO>(subject)).ToList();

return new OkObjectResult(results);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ public void ClearData()
Context.TeacherGroups.RemoveRange(Context.TeacherGroups);
Context.Teachers.RemoveRange(Context.Teachers);
Context.TeacherSubjects.RemoveRange(Context.TeacherSubjects);

Context.SaveChanges();
}

private static List<Subject> CreateSubjectData()
Expand Down
28 changes: 14 additions & 14 deletions grade-management/Ahk.GradeManagement/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using Ahk.GradeManagement.Services.SetGradeService;
using Ahk.GradeManagement.Services.StatusTrackingService;
using Ahk.GradeManagement.Helpers;
using Ahk.GradeManagement.Services.SubjectService;

namespace Ahk.GradeManagement
{
Expand All @@ -23,26 +24,25 @@ public class Program
public static async Task Main(string[] args)
{
var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults(workerApplication =>
{
workerApplication.UseAspNetCoreIntegration();
})
.ConfigureAspNetCoreIntegration()
.ConfigureFunctionsWorkerDefaults()
.ConfigureServices(services =>
{
services.AddMemoryCache(setup =>
{
setup.ExpirationScanFrequency = TimeSpan.FromMinutes(4);
});
services.AddSingleton<IDateTimeProvider, DateTimeProvider>();
services.AddScoped<ResultProcessing.IResultProcessor, ResultProcessing.ResultProcessor>();
services.AddScoped<Services.ITokenManagementService, Services.TokenManagementService>();
services.AddScoped<ISetGradeService, SetGradeService>();
services.AddScoped<ListGrades.IGradeListing, ListGrades.GradeListing>();
services.AddScoped<IStatusTrackingService, StatusTrackingService>();
services.AddScoped<IGroupService, GroupService>();
services.AddScoped<IAssignmentService, AssignmentService>();
services.AddScoped<IGradeService, GradeService>();
services.AddSingleton<ResultProcessing.IResultProcessor, ResultProcessing.ResultProcessor>();
services.AddSingleton<Services.ITokenManagementService, Services.TokenManagementService>();
services.AddSingleton<ISetGradeService, SetGradeService>();
services.AddSingleton<ListGrades.IGradeListing, ListGrades.GradeListing>();
services.AddSingleton<IStatusTrackingService, StatusTrackingService>();
services.AddSingleton<IGroupService, GroupService>();
services.AddSingleton<IAssignmentService, AssignmentService>();
services.AddSingleton<IGradeService, GradeService>();
services.AddSingleton<ISubjectService, SubjectService>();
services.AddCors();
var mapper = MapperConfig.InitializeAutomapper();
Expand All @@ -69,7 +69,7 @@ public static async Task Main(string[] args)

SampleDataSeeder seeder = new SampleDataSeeder(context);
//seeder.ClearData();
seeder.SeedData();
//seeder.SeedData();
}

await host.RunAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Threading.Tasks;
using Ahk.GradeManagement.Data;
using Ahk.GradeManagement.Data.Entities;
using Microsoft.EntityFrameworkCore;

namespace Ahk.GradeManagement.Services.GroupService
{
Expand All @@ -23,9 +24,9 @@ public async Task SaveGroupAsync(Group group)
await Context.SaveChangesAsync();
}

public async Task<List<Group>> ListGroupsAsync()
public async Task<List<Group>> ListGroupsAsync(string subject)
{
return Context.Groups.ToList();
return Context.Groups.Where(g => g.Subject.Name == subject).ToList();
}

public async Task<List<Student>> ListStudentsAsync(int groupId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Ahk.GradeManagement.Services.GroupService
public interface IGroupService
{
public Task SaveGroupAsync(Group group);
public Task<List<Group>> ListGroupsAsync();
public Task<List<Group>> ListGroupsAsync(string subject);
public Task<List<Student>> ListStudentsAsync(int groupId);
public Task DeleteGroupAsync(int groupId);
}
Expand Down
2 changes: 1 addition & 1 deletion grade-management/DTOs/GroupDTO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class GroupDTO
public string Name { get; set; }

Check warning on line 7 in grade-management/DTOs/GroupDTO.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Name' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
public string Room { get; set; }

Check warning on line 8 in grade-management/DTOs/GroupDTO.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Room' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
public string Time { get; set; }
public List<StudentDTO> Students { get; set; }
public int SubjectId { get; set; }

}
}
2 changes: 2 additions & 0 deletions review-ui/Ahk.Review.Ui/Ahk.Review.Ui.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
<PackageReference Include="AutoMapper" Version="12.0.1" />
<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" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
<PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" />
<PackageReference Include="MudBlazor" Version="6.2.5" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.354">
Expand Down
4 changes: 3 additions & 1 deletion review-ui/Ahk.Review.Ui/Components/Header.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ public partial class Header : ComponentBase

protected override async void OnInitialized()
{
subjects = service.GetSubjects().Result.ToList();
var results = await service.GetSubjects();
subjects = results.ToList();
}

private void SetTenant()
{
service.Tenant = subjectCode;
Console.WriteLine(service.Tenant);
}
}
}
7 changes: 2 additions & 5 deletions review-ui/Ahk.Review.Ui/Models/Group.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,13 @@ public Group(GroupDTO groupDTO)
this.Name = groupDTO.Name;
this.Room = groupDTO.Room;
this.Time = groupDTO.Time;
this.Students = groupDTO.Students.Select(sDTO =>
{
return new Student(sDTO);
}).ToList();
this.SubjectId = groupDTO.SubjectId;
}

public int Id { get; set; }
public string Name { get; set; }
public string Room { get; set; }
public string Time { get; set; }
public List<Student> Students { get; set; }
public int SubjectId { get; set; }
}
}
11 changes: 11 additions & 0 deletions review-ui/Ahk.Review.Ui/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,15 @@
builder.Services.AddSingleton<GroupService>();
builder.Services.AddSingleton<AssignmentService>();

builder.Services.AddCors(options =>
{
options.AddDefaultPolicy(
policy =>
{
policy.WithOrigins(builder.Configuration.GetSection("baseAddress").Value + "*")
.AllowAnyHeader()
.AllowAnyMethod();
});
});

await builder.Build().RunAsync();
7 changes: 6 additions & 1 deletion review-ui/Ahk.Review.Ui/Services/SubjectService.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using Ahk.Review.Ui.Models;
using AutoMapper;
using DTOs;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using System.Net.Http.Json;

namespace Ahk.Review.Ui.Services
Expand All @@ -20,7 +23,9 @@ public SubjectService(IHttpClientFactory httpClientFactory, Mapper mapper)

public async Task<IReadOnlyCollection<Subject>> GetSubjects()
{
var subjectDTOs = await httpClient.GetFromJsonAsync<IReadOnlyCollection<SubjectDTO>>($"list-subjects");
var results = await httpClient.GetFromJsonAsync<OkObjectResult>($"list-subjects");

var subjectDTOs = JsonConvert.DeserializeObject<List<SubjectDTO>>(results.Value.ToString());

return subjectDTOs.Select(sDTO =>
{
Expand Down

0 comments on commit c0f436d

Please sign in to comment.