From b6988315243cef1be637fc90dab7c7bf9a6d7c68 Mon Sep 17 00:00:00 2001 From: balintgrober Date: Wed, 13 Sep 2023 20:06:08 +0200 Subject: [PATCH] Group delete + edit --- .../Functions/Groups/DeleteGroupFunction.cs | 16 +++--- .../Functions/Groups/EditGroupFunction.cs | 45 ++++++++++++++++ .../Services/GroupService/GroupService.cs | 10 ++++ .../Services/GroupService/IGroupService.cs | 1 + .../Pages/GroupPages/EditGroup.razor | 10 ++++ .../Pages/GroupPages/EditGroup.razor.cs | 47 ++++++++++++++++ .../Pages/GroupPages/GroupDetails.razor | 5 ++ .../Pages/GroupPages/GroupDetails.razor.cs | 10 ++++ .../Pages/SubjectPages/SubjectDetails.razor | 52 ++++++++++++++++-- .../SubjectPages/SubjectDetails.razor.cs | 53 ++++++++++++++++--- .../Services/AssignmentService.cs | 5 ++ .../Ahk.Review.Ui/Services/GroupService.cs | 20 ++++++- .../Ahk.Review.Ui/Shared/MainLayout.razor | 2 +- 13 files changed, 256 insertions(+), 20 deletions(-) create mode 100644 grade-management/Ahk.GradeManagement/Functions/Groups/EditGroupFunction.cs create mode 100644 review-ui/Ahk.Review.Ui/Pages/GroupPages/EditGroup.razor create mode 100644 review-ui/Ahk.Review.Ui/Pages/GroupPages/EditGroup.razor.cs create mode 100644 review-ui/Ahk.Review.Ui/Pages/GroupPages/GroupDetails.razor create mode 100644 review-ui/Ahk.Review.Ui/Pages/GroupPages/GroupDetails.razor.cs diff --git a/grade-management/Ahk.GradeManagement/Functions/Groups/DeleteGroupFunction.cs b/grade-management/Ahk.GradeManagement/Functions/Groups/DeleteGroupFunction.cs index c906ebf7..bdde1baf 100644 --- a/grade-management/Ahk.GradeManagement/Functions/Groups/DeleteGroupFunction.cs +++ b/grade-management/Ahk.GradeManagement/Functions/Groups/DeleteGroupFunction.cs @@ -1,4 +1,7 @@ using System.Net; +using System.Threading.Tasks; +using Ahk.GradeManagement.Services.GroupService; +using Microsoft.AspNetCore.Mvc; using Microsoft.Azure.Functions.Worker; using Microsoft.Azure.Functions.Worker.Http; using Microsoft.Extensions.Logging; @@ -8,23 +11,22 @@ namespace Ahk.GradeManagement.Functions.Groups public class DeleteGroupFunction { private readonly ILogger _logger; + private readonly IGroupService groupService; - public DeleteGroupFunction(ILoggerFactory loggerFactory) + public DeleteGroupFunction(ILoggerFactory loggerFactory, IGroupService groupService) { _logger = loggerFactory.CreateLogger(); + this.groupService = groupService; } [Function("delete-group")] - public HttpResponseData Run([HttpTrigger(AuthorizationLevel.Anonymous, "delete", Route = "delete-group/{subject}/{id}")] HttpRequestData req, string subject, int id) + public async Task Run([HttpTrigger(AuthorizationLevel.Anonymous, "delete", Route = "delete-group/{id}")] HttpRequestData req, 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"); + await groupService.DeleteGroupAsync(id); - response.WriteString("Welcome to Azure Functions!"); - - return response; + return new OkResult(); } } } diff --git a/grade-management/Ahk.GradeManagement/Functions/Groups/EditGroupFunction.cs b/grade-management/Ahk.GradeManagement/Functions/Groups/EditGroupFunction.cs new file mode 100644 index 00000000..2032f291 --- /dev/null +++ b/grade-management/Ahk.GradeManagement/Functions/Groups/EditGroupFunction.cs @@ -0,0 +1,45 @@ +using System.Net; +using System.Threading.Tasks; +using Ahk.GradeManagement.Data.Entities; +using Ahk.GradeManagement.Services.GroupService; +using DTOs; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Azure.Functions.Worker; +using Microsoft.Azure.Functions.Worker.Http; +using Microsoft.Extensions.Logging; +using FromBodyAttribute = Microsoft.Azure.Functions.Worker.Http.FromBodyAttribute; + +namespace Ahk.GradeManagement.Functions.Groups +{ + public class EditGroupFunction + { + private readonly ILogger _logger; + private readonly IGroupService groupService; + + public EditGroupFunction(ILoggerFactory loggerFactory, IGroupService groupService) + { + _logger = loggerFactory.CreateLogger(); + this.groupService = groupService; + } + + [Function("EditGroupFunction")] + public async Task Run([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "edit-group/{subject}")] HttpRequestData req, string subject, + [FromBody] GroupDTO groupDTO) + { + _logger.LogInformation("C# HTTP trigger function processed a request."); + + var update = new Group() + { + Id = groupDTO.Id, + Name = groupDTO.Name, + Time = groupDTO.Time, + Room = groupDTO.Room, + SubjectId = groupDTO.SubjectId, + }; + + await groupService.UpdateGroupAsync(update); + + return new OkResult(); + } + } +} diff --git a/grade-management/Ahk.GradeManagement/Services/GroupService/GroupService.cs b/grade-management/Ahk.GradeManagement/Services/GroupService/GroupService.cs index f90d7b7e..9d06c53f 100644 --- a/grade-management/Ahk.GradeManagement/Services/GroupService/GroupService.cs +++ b/grade-management/Ahk.GradeManagement/Services/GroupService/GroupService.cs @@ -47,5 +47,15 @@ public async Task DeleteGroupAsync(int groupId) Context.Remove(group); await Context.SaveChangesAsync(); } + + public async Task UpdateGroupAsync(Group update) + { + var groupToUpdate = await Context.Groups.FindAsync(update.Id); + groupToUpdate.Name = update.Name; + groupToUpdate.Room = update.Room; + groupToUpdate.Time = update.Time; + + await Context.SaveChangesAsync(); + } } } diff --git a/grade-management/Ahk.GradeManagement/Services/GroupService/IGroupService.cs b/grade-management/Ahk.GradeManagement/Services/GroupService/IGroupService.cs index 7438d554..59038fea 100644 --- a/grade-management/Ahk.GradeManagement/Services/GroupService/IGroupService.cs +++ b/grade-management/Ahk.GradeManagement/Services/GroupService/IGroupService.cs @@ -13,5 +13,6 @@ public interface IGroupService public Task> ListGroupsAsync(string subject); public Task> ListStudentsAsync(int groupId); public Task DeleteGroupAsync(int groupId); + public Task UpdateGroupAsync(Group update); } } diff --git a/review-ui/Ahk.Review.Ui/Pages/GroupPages/EditGroup.razor b/review-ui/Ahk.Review.Ui/Pages/GroupPages/EditGroup.razor new file mode 100644 index 00000000..417c990f --- /dev/null +++ b/review-ui/Ahk.Review.Ui/Pages/GroupPages/EditGroup.razor @@ -0,0 +1,10 @@ +@page "/edit-group/{groupId}" + + + + + + + + +Submit diff --git a/review-ui/Ahk.Review.Ui/Pages/GroupPages/EditGroup.razor.cs b/review-ui/Ahk.Review.Ui/Pages/GroupPages/EditGroup.razor.cs new file mode 100644 index 00000000..b9927b65 --- /dev/null +++ b/review-ui/Ahk.Review.Ui/Pages/GroupPages/EditGroup.razor.cs @@ -0,0 +1,47 @@ +using Ahk.Review.Ui.Models; +using Ahk.Review.Ui.Services; +using Microsoft.AspNetCore.Components; +using Newtonsoft.Json; + +namespace Ahk.Review.Ui.Pages.GroupPages +{ + public partial class EditGroup : ComponentBase + { + [Parameter] + public string GroupId { get; set; } + + [Inject] + private GroupService GroupService { get; set; } + [Inject] + private SubjectService SubjectService { get; set; } + [Inject] + private NavigationManager NavigationManager { get; set; } + + private Group group; + + private string name; + private string room; + private string time; + + protected override async void OnInitialized() + { + group = await GroupService.GetGroupAsync(SubjectService.TenantCode, GroupId); + + name = group.Name; + room = group.Room; + time = group.Time; + + StateHasChanged(); + } + + private async void SubmitAsync() + { + Group update = group; + update.Name = name; + update.Room = room; + update.Time = time; + + await GroupService.UpdateGroupAsync(SubjectService.TenantCode, update); + } + } +} diff --git a/review-ui/Ahk.Review.Ui/Pages/GroupPages/GroupDetails.razor b/review-ui/Ahk.Review.Ui/Pages/GroupPages/GroupDetails.razor new file mode 100644 index 00000000..924b6e80 --- /dev/null +++ b/review-ui/Ahk.Review.Ui/Pages/GroupPages/GroupDetails.razor @@ -0,0 +1,5 @@ +@page "/group-details/{groupId}" + +

GroupDetails

+ + diff --git a/review-ui/Ahk.Review.Ui/Pages/GroupPages/GroupDetails.razor.cs b/review-ui/Ahk.Review.Ui/Pages/GroupPages/GroupDetails.razor.cs new file mode 100644 index 00000000..b43d2611 --- /dev/null +++ b/review-ui/Ahk.Review.Ui/Pages/GroupPages/GroupDetails.razor.cs @@ -0,0 +1,10 @@ +using Microsoft.AspNetCore.Components; + +namespace Ahk.Review.Ui.Pages.GroupPages +{ + public partial class GroupDetails : ComponentBase + { + [Parameter] + public string GroupId { get; set; } + } +} diff --git a/review-ui/Ahk.Review.Ui/Pages/SubjectPages/SubjectDetails.razor b/review-ui/Ahk.Review.Ui/Pages/SubjectPages/SubjectDetails.razor index 7765c1a3..b939fc34 100644 --- a/review-ui/Ahk.Review.Ui/Pages/SubjectPages/SubjectDetails.razor +++ b/review-ui/Ahk.Review.Ui/Pages/SubjectPages/SubjectDetails.razor @@ -1,10 +1,52 @@ @page "/subject-details" + + + + + + + + + - - + + + + Name + Room + Time + Actions + + + @context.Name + @context.Room + @context.Time + + Details + Edit + Delete + + + + + + + + Name + Deadline + Actions + + + @context.Name + @context.DeadLine + + Details + Edit + Delete + + + + - - - diff --git a/review-ui/Ahk.Review.Ui/Pages/SubjectPages/SubjectDetails.razor.cs b/review-ui/Ahk.Review.Ui/Pages/SubjectPages/SubjectDetails.razor.cs index ae7012ce..999c98b5 100644 --- a/review-ui/Ahk.Review.Ui/Pages/SubjectPages/SubjectDetails.razor.cs +++ b/review-ui/Ahk.Review.Ui/Pages/SubjectPages/SubjectDetails.razor.cs @@ -13,6 +13,8 @@ public partial class SubjectDetails : ComponentBase, IDisposable private GroupService GroupService { get; set; } [Inject] private AssignmentService AssignmentService { get; set; } + [Inject] + private NavigationManager NavigationManager { get; set; } private string courseCode; private string subjectName; @@ -22,15 +24,24 @@ public partial class SubjectDetails : ComponentBase, IDisposable private List groups; private List assignments; + private bool firstRender = true; + protected override async void OnInitialized() { - courseCode = SubjectService.TenantCode; - subjectName = SubjectService.CurrentTenant.Name; - semester = SubjectService.CurrentTenant.Semester; - githubOrg = SubjectService.CurrentTenant.GithubOrg; + if (firstRender) + { + courseCode = SubjectService.TenantCode; + subjectName = SubjectService.CurrentTenant.Name; + semester = SubjectService.CurrentTenant.Semester; + githubOrg = SubjectService.CurrentTenant.GithubOrg; - groups = await GroupService.GetGroupsAsync(SubjectService.TenantCode); - assignments = await AssignmentService.GetAssignmentsAsync(SubjectService.TenantCode); + groups = await GroupService.GetGroupsAsync(SubjectService.TenantCode); + assignments = await AssignmentService.GetAssignmentsAsync(SubjectService.TenantCode); + + firstRender = false; + + StateHasChanged(); + } SubjectService.OnChange += SubjectChanged; } @@ -52,5 +63,35 @@ private async void SubjectChanged() StateHasChanged(); } + + private void EditGroup(int groupId) + { + NavigationManager.NavigateTo($"/edit-group/{groupId}"); + } + + private async Task DeleteGroup(int groupId) + { + await GroupService.DeleteGroupAsync(groupId.ToString()); + } + + private void ShowGroupDetails(int groupId) + { + NavigationManager.NavigateTo($"/group-details/{groupId}"); + } + + private void EditAssignment(int assignmentId) + { + NavigationManager.NavigateTo($"/edit-assignment/{assignmentId}"); + } + + private async Task DeleteAssignment(int assignmentId) + { + await AssignmentService.DeleteAssignmentAsync(assignmentId.ToString()); + } + + private void ShowAssignmentDetails(int assignmentId) + { + NavigationManager.NavigateTo($"/assignment-details/{assignmentId}"); + } } } diff --git a/review-ui/Ahk.Review.Ui/Services/AssignmentService.cs b/review-ui/Ahk.Review.Ui/Services/AssignmentService.cs index d3ae63b9..c17646a8 100644 --- a/review-ui/Ahk.Review.Ui/Services/AssignmentService.cs +++ b/review-ui/Ahk.Review.Ui/Services/AssignmentService.cs @@ -34,5 +34,10 @@ public async Task> GetAssignmentsAsync(string subject) return new Assignment(aDTO); }).ToList(); } + + public async Task DeleteAssignmentAsync(string assignmentId) + { + + } } } diff --git a/review-ui/Ahk.Review.Ui/Services/GroupService.cs b/review-ui/Ahk.Review.Ui/Services/GroupService.cs index 279199c7..c915775b 100644 --- a/review-ui/Ahk.Review.Ui/Services/GroupService.cs +++ b/review-ui/Ahk.Review.Ui/Services/GroupService.cs @@ -19,7 +19,7 @@ public GroupService(IHttpClientFactory httpClientFactory, Mapper mapper) this.Mapper = mapper; } - public async void PostDataAsync(Group group) + public async void CreateGroupAsync(Group group) { await httpClient.PostAsJsonAsync($"create-group", Mapper.Map(group)); } @@ -34,5 +34,23 @@ public async Task> GetGroupsAsync(string subject) return new Group(gDTO); }).ToList(); } + + public async Task GetGroupAsync(string subject, string groupId) + { + var groups = await GetGroupsAsync(subject); + var group = groups.Where(g => g.Id.ToString() == groupId).FirstOrDefault(); + + return group; + } + + public async Task UpdateGroupAsync(string subject, Group group) + { + await httpClient.PostAsJsonAsync($"edit-group/{subject}", Mapper.Map(group)); + } + + public async Task DeleteGroupAsync(string groupId) + { + await httpClient.DeleteAsync($"delete-group/{groupId}"); + } } } diff --git a/review-ui/Ahk.Review.Ui/Shared/MainLayout.razor b/review-ui/Ahk.Review.Ui/Shared/MainLayout.razor index 4a3afa68..1be52a79 100644 --- a/review-ui/Ahk.Review.Ui/Shared/MainLayout.razor +++ b/review-ui/Ahk.Review.Ui/Shared/MainLayout.razor @@ -7,7 +7,7 @@
- + @Body