Skip to content

Commit

Permalink
Group delete + edit
Browse files Browse the repository at this point in the history
  • Loading branch information
balintgrober committed Sep 13, 2023
1 parent 77f8125 commit b698831
Show file tree
Hide file tree
Showing 13 changed files with 256 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<DeleteGroupFunction>();
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<IActionResult> 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();
}
}
}
Original file line number Diff line number Diff line change
@@ -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<EditGroupFunction>();
this.groupService = groupService;
}

[Function("EditGroupFunction")]
public async Task<IActionResult> 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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ public interface IGroupService
public Task<List<Group>> ListGroupsAsync(string subject);
public Task<List<Student>> ListStudentsAsync(int groupId);
public Task DeleteGroupAsync(int groupId);
public Task UpdateGroupAsync(Group update);
}
}
10 changes: 10 additions & 0 deletions review-ui/Ahk.Review.Ui/Pages/GroupPages/EditGroup.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@page "/edit-group/{groupId}"

<MudPaper>
<MudTextField Margin="Margin.Normal" @bind-Value="@name" Label="Name"></MudTextField>
<MudTextField Margin="Margin.Normal" @bind-Value="@room" Label="Room"></MudTextField>
<MudTextField Margin="Margin.Normal" @bind-Value="@time" Label="Time"></MudTextField>
</MudPaper>


<MudButton Variant="Variant.Filled" Color="Color.Primary" Style="margin:auto" OnClick="() => SubmitAsync()">Submit</MudButton>
47 changes: 47 additions & 0 deletions review-ui/Ahk.Review.Ui/Pages/GroupPages/EditGroup.razor.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
5 changes: 5 additions & 0 deletions review-ui/Ahk.Review.Ui/Pages/GroupPages/GroupDetails.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@page "/group-details/{groupId}"

<h3>GroupDetails</h3>


10 changes: 10 additions & 0 deletions review-ui/Ahk.Review.Ui/Pages/GroupPages/GroupDetails.razor.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
}
52 changes: 47 additions & 5 deletions review-ui/Ahk.Review.Ui/Pages/SubjectPages/SubjectDetails.razor
Original file line number Diff line number Diff line change
@@ -1,10 +1,52 @@
@page "/subject-details"

<MudPaper Class="pa-4 mb-4">
<MudStack Row="true">
<MudTextField @bind-Value="@courseCode" ReadOnly="true" Label="CourseCode"></MudTextField>
<MudTextField @bind-Value="@subjectName" ReadOnly="true" Label="Name"></MudTextField>
</MudStack>
<MudTextField @bind-Value="@semester" ReadOnly="true" Label="Semester"></MudTextField>
<MudTextField @bind-Value="@githubOrg" ReadOnly="true" Label="Github Organization"></MudTextField>
</MudPaper>

<MudStack Row="true">
<MudTextField @bind-Value="@courseCode" ReadOnly="true" Label="CourseCode"></MudTextField>
<MudTextField @bind-Value="@subjectName" ReadOnly="true" Label="Name"></MudTextField>
<MudPaper Class="pa-4 mb-4">
<MudTable Items="groups" T="Group">
<HeaderContent>
<MudTh>Name</MudTh>
<MudTh>Room</MudTh>
<MudTh>Time</MudTh>
<MudTh>Actions</MudTh>
</HeaderContent>
<RowTemplate>
<MudTd DataLabel="Name">@context.Name</MudTd>
<MudTd DataLabel="Room">@context.Room</MudTd>
<MudTd DataLabel="Time">@context.Time</MudTd>
<MudTd DataLabel="Actions">
<MudButton Class="ma-2 pa-2" Variant="Variant.Filled" Color="Color.Primary" OnClick="() => ShowGroupDetails(context.Id)">Details</MudButton>
<MudButton Class="ma-2 pa-2" Variant="Variant.Filled" StartIcon="@Icons.Material.Filled.Create" Color="Color.Secondary" OnClick="() => EditGroup(context.Id)">Edit</MudButton>
<MudButton Class="ma-2 pa-2" Variant="Variant.Filled" StartIcon="@Icons.Material.Filled.Delete" Color="Color.Error" OnClick="() => DeleteGroup(context.Id)">Delete</MudButton>
</MudTd>
</RowTemplate>
</MudTable>
</MudPaper>
<MudPaper Class="pa-4 mb-4">
<MudTable Items="assignments" T="Assignment">
<HeaderContent>
<MudTh>Name</MudTh>
<MudTh>Deadline</MudTh>
<MudTh>Actions</MudTh>
</HeaderContent>
<RowTemplate>
<MudTd DataLabel="Name">@context.Name</MudTd>
<MudTd DataLabel="Deadline">@context.DeadLine</MudTd>
<MudTd DataLabel="Actions">
<MudButton Class="ma-2 pa-2" Variant="Variant.Filled" Color="Color.Primary" OnClick="() => ShowAssignmentDetails(context.Id)">Details</MudButton>
<MudButton Class="ma-2 pa-2" Variant="Variant.Filled" StartIcon="@Icons.Material.Filled.Create" Color="Color.Secondary" OnClick="() => EditAssignment(context.Id)">Edit</MudButton>
<MudButton Class="ma-2 pa-2" Variant="Variant.Filled" StartIcon="@Icons.Material.Filled.Delete" Color="Color.Error" OnClick="() => DeleteAssignment(context.Id)">Delete</MudButton>
</MudTd>
</RowTemplate>
</MudTable>
</MudPaper>
</MudStack>
<MudTextField @bind-Value="@semester" ReadOnly="true" Label="Semester"></MudTextField>
<MudTextField @bind-Value="@githubOrg" ReadOnly="true" Label="Github Organization"></MudTextField>


53 changes: 47 additions & 6 deletions review-ui/Ahk.Review.Ui/Pages/SubjectPages/SubjectDetails.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,15 +24,24 @@ public partial class SubjectDetails : ComponentBase, IDisposable
private List<Group> groups;
private List<Assignment> 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;
}
Expand All @@ -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}");
}
}
}
5 changes: 5 additions & 0 deletions review-ui/Ahk.Review.Ui/Services/AssignmentService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,10 @@ public async Task<List<Assignment>> GetAssignmentsAsync(string subject)
return new Assignment(aDTO);
}).ToList();
}

public async Task DeleteAssignmentAsync(string assignmentId)
{

}
}
}
20 changes: 19 additions & 1 deletion review-ui/Ahk.Review.Ui/Services/GroupService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<GroupDTO>(group));
}
Expand All @@ -34,5 +34,23 @@ public async Task<List<Group>> GetGroupsAsync(string subject)
return new Group(gDTO);
}).ToList();
}

public async Task<Group> 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<GroupDTO>($"edit-group/{subject}", Mapper.Map<GroupDTO>(group));
}

public async Task DeleteGroupAsync(string groupId)
{
await httpClient.DeleteAsync($"delete-group/{groupId}");
}
}
}
2 changes: 1 addition & 1 deletion review-ui/Ahk.Review.Ui/Shared/MainLayout.razor
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<MudLayout>
<Header />
<MudMainContent>
<MudContainer MaxWidth="MaxWidth.Large" Class="my-1 pt-1">
<MudContainer MaxWidth="MaxWidth.ExtraLarge" Class="my-1 pt-1">
@Body
</MudContainer>
</MudMainContent>
Expand Down

0 comments on commit b698831

Please sign in to comment.