Skip to content

Commit

Permalink
Merge pull request #9 from hootanht/main
Browse files Browse the repository at this point in the history
Rename Education to Organization. ab#20103
  • Loading branch information
hootanht authored Nov 6, 2023
2 parents 2213aaa + 46d3bbd commit fa49758
Show file tree
Hide file tree
Showing 22 changed files with 673 additions and 109 deletions.
17 changes: 7 additions & 10 deletions src/CrystallineSociety/Client/Shared/Components/BadgeTree.razor
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@

@if (Badges != null)
{
<BitBasicList TItem="BadgeDto"
ItemSize="4"
Items="Badges"
Style="border: 1px #a19f9d solid; border-radius: 3px; height: auto; width: 50%;max-height:500px;">
<RowTemplate Context="badge">
<div style="border-bottom: 1px #8a8886 solid; padding: 5px 20px;" class="badge-row" @onclick="() => OnBadgeClick(badge)">
<div>Name: @badge.Code</div>
</div>
</RowTemplate>
</BitBasicList>
<ul class="list-group">
<li class="list-group-item active" aria-current="true">An active item</li>
@foreach (var badge in Badges)
{
<li class="list-group-item" @onclick="() => OnBadgeClick(badge)">@badge.Title</li>
}
</ul>
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@



Current: @Organization.Title
@* Current: @Organization.Title *@
<div class="container-fluid pb-3">
<div class="d-grid gap-3" style="grid-template-columns: 1fr 2fr;">
<div class="bg-body-tertiary border rounded-3">
<br><br><br><br><br><br><br><br><br><br>
<BadgeTree BadgeBundleDto="Bundle" BadgeDtoCallBack="@GetBadge"></BadgeTree>
</div>
<div class="bg-body-tertiary border rounded-3">
<br><br><br><br><br><br><br><br><br><br>
<BadgeContent Badge="BadgeDto"></BadgeContent>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,24 @@
using System.Text;
using System.Threading.Tasks;

using CrystallineSociety.Shared.Dtos.BadgeSystem;
using CrystallineSociety.Shared.Dtos.Organization;

namespace CrystallineSociety.Client.Shared.Components
{
public partial class OrganizationBadges
{
[Parameter]
public OrganizationDto Organization { get; set; }
public OrganizationDto Organization { get; set; } = default!;

[Parameter]
public BadgeBundleDto? Bundle { get; set; }

private BadgeDto? BadgeDto { get; set; }

private void GetBadge(BadgeDto badgeDto)
{
BadgeDto = badgeDto;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
@page "/education-program"
@using CrystallineSociety.Shared.Dtos.BadgeSystem
@using CrystallineSociety.Shared.Dtos.EducationProgram
@using CrystallineSociety.Shared.Dtos.Organization
@inherits AppComponentBase

<BitBasicList TItem="EducationProgramDto"
<BitBasicList TItem="OrganizationDto"
ItemSize="4"
Items="EducationPrograms"
Items="Organizations"
Style="border: 1px #a19f9d solid; border-radius: 3px; height: auto; width: 50%;max-height:500px;">
<RowTemplate Context="educationProgram">
<div @key="educationProgram.Code" style="@(EducationPrograms.Count>1 ? "border-bottom: 1px #8a8886 solid; padding: 5px 20px; margin: 10px;" : "")">
<div @key="educationProgram.Code" style="@(Organizations.Count>1 ? "border-bottom: 1px #8a8886 solid; padding: 5px 20px; margin: 10px;" : "")">
<div style="margin-left:3%; display: inline-block;">
<p>Education Program Name: <strong>@educationProgram.Title</strong></p>
<BitButton OnClick="WrapHandled(()=>HandelSyncAsync(educationProgram))">Sync
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,26 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using CrystallineSociety.Shared.Dtos.EducationProgram;
using CrystallineSociety.Shared.Dtos.Organization;

namespace CrystallineSociety.Client.Shared.Pages;
public partial class EducationProgramPage
{
private List<EducationProgramDto> EducationPrograms = new();
private List<OrganizationDto> Organizations = new();
private bool IsSyncing = false;


protected override async Task OnInitAsync()
{
// Todo : complete this code to return dto not entity.
EducationPrograms = await HttpClient.GetFromJsonAsync<List<EducationProgramDto>>("BadgeSystem/GetEducationPrograms");
Organizations = await HttpClient.GetFromJsonAsync<List<OrganizationDto>>("Organization/GetOrganizations");

Check warning on line 18 in src/CrystallineSociety/Client/Shared/Pages/EducationProgramPage.razor.cs

View workflow job for this annotation

GitHub Actions / build blazor api + web assembly

Possible null reference assignment.

Check warning on line 18 in src/CrystallineSociety/Client/Shared/Pages/EducationProgramPage.razor.cs

View workflow job for this annotation

GitHub Actions / build blazor api + web assembly

Possible null reference assignment.
await base.OnInitAsync();
}

private async Task HandelSyncAsync(EducationProgramDto educationProgram)
private async Task HandelSyncAsync(OrganizationDto organization)
{
IsSyncing = true;
await HttpClient.PostAsJsonAsync("BadgeSystem/SyncEducationProgramBadges", educationProgram);
await HttpClient.PostAsJsonAsync("Organization/SyncOrganizationBadges", organization);
IsSyncing = false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
</nav>


<OrganizationBadges Organization=Organization></OrganizationBadges>
<OrganizationBadges Organization=Organization Bundle="Bundle"></OrganizationBadges>

<div>
// Show organization name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,35 @@
using System.Text;
using System.Threading.Tasks;

using CrystallineSociety.Shared.Dtos.BadgeSystem;
using CrystallineSociety.Shared.Dtos.Organization;

namespace CrystallineSociety.Client.Shared.Pages
{
public partial class OrganizationPage
{
[Parameter]
public string OrganizationCode { get; set; }
public string? OrganizationCode { get; set; }

private OrganizationDto Organization { get; set; } = default!;

private OrganizationDto Organization { get; set; }
private BadgeBundleDto? Bundle { get; set; }

protected override async Task OnInitAsync()
{
await LoadOrganizationAsync();
await LoadBadgeSystem();
await base.OnInitAsync();
}

private async Task LoadOrganizationAsync()
{
Organization = new OrganizationDto(){Code = "CSI", Title = "CS Internship", Description = "Our first program"};
Organization = await HttpClient.GetFromJsonAsync($"Organization/GetOrganizationByCode?code={OrganizationCode}", AppJsonContext.Default.OrganizationDto);

Check warning on line 30 in src/CrystallineSociety/Client/Shared/Pages/OrganizationPage.razor.cs

View workflow job for this annotation

GitHub Actions / build blazor api + web assembly

Possible null reference assignment.

Check warning on line 30 in src/CrystallineSociety/Client/Shared/Pages/OrganizationPage.razor.cs

View workflow job for this annotation

GitHub Actions / build blazor api + web assembly

Possible null reference assignment.
}

private async Task LoadBadgeSystem()
{
Bundle = await HttpClient.GetFromJsonAsync($"BadgeSystem/GetBadgeBundleFromGitHub?url={Organization.BadgeSystemUrl}", AppJsonContext.Default.BadgeBundleDto);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using CrystallineSociety.Server.Api.Models;
using CrystallineSociety.Server.Api.Models.TodoItem;
using CrystallineSociety.Shared.Dtos.BadgeSystem;
using CrystallineSociety.Shared.Dtos.EducationProgram;
using CrystallineSociety.Shared.Dtos.Organization;
using CrystallineSociety.Shared.Dtos.TodoItem;
using CrystallineSociety.Shared.Services.Implementations.BadgeSystem;
using Microsoft.VisualBasic;
Expand Down Expand Up @@ -32,7 +32,7 @@ public partial class BadgeSystemController : AppControllerBase
/// Education program service for syncing badge systems with education programs.
/// </summary>
[AutoInject]
public IEducationProgramService EducationProgramService { get; set; }
public IOrganizationService OrganizationService { get; set; }

/// <summary>
/// Live badge system for managing badges.
Expand Down Expand Up @@ -100,26 +100,4 @@ public async Task<List<BadgeCountDto>> GetEarnedBadgesAsync(string username)
{
return await LiveBadgeSystemService.GetEarnedBadgesAsync(username);
}

/// <summary>
/// Syncs the badge system with an education program.
/// </summary>
/// <param name="educationProgram">The education program to sync.</param>
/// <param name="cancellationToken">Cancellation token.</param>
[HttpPost]
public async Task SyncEducationProgramBadgesAsync(EducationProgramDto educationProgram, CancellationToken cancellationToken)
{
await EducationProgramService.SyncBadgeSystemAsync(educationProgram.Code, cancellationToken);
}

/// <summary>
/// Retrieves all education programs.
/// </summary>
/// <param name="cancellationToken">Cancellation token.</param>
/// <returns>All education programs.</returns>
[HttpGet]
public async Task<List<EducationProgramDto>> GetEducationProgramsAsync(CancellationToken cancellationToken)
{
return Mapper.Map<List<EducationProgramDto>>(await EducationProgramService.GetAllEducationProgramsAsync(cancellationToken));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using CrystallineSociety.Server.Api.Services.Implementations;
using CrystallineSociety.Shared.Dtos.Organization;

namespace CrystallineSociety.Server.Api.Controllers;

[Route("api/[controller]/[action]")]
[ApiController]
[AllowAnonymous]
public partial class OrganizationController : AppControllerBase
{

/// <summary>
/// Education program service for syncing badge systems with education programs.
/// </summary>
[AutoInject]
public IOrganizationService OrganizationService { get; set; }

/// <summary>
/// Syncs the badge system with an education program.
/// </summary>
/// <param name="organization">The education program to sync.</param>
/// <param name="cancellationToken">Cancellation token.</param>
[HttpPost]
public async Task SyncOrganizationBadgesAsync(OrganizationDto organization, CancellationToken cancellationToken)
{
await OrganizationService.SyncBadgeSystemAsync(organization.Code, cancellationToken);
}

/// <summary>
/// Retrieves all education programs.
/// </summary>
/// <param name="cancellationToken">Cancellation token.</param>
/// <returns>All education programs.</returns>
[HttpGet]
public async Task<List<OrganizationDto>> GetOrganizationsAsync(CancellationToken cancellationToken)
{
return Mapper.Map<List<OrganizationDto>>(await OrganizationService.GetAllOrganizationAsync(cancellationToken));
}

[HttpGet]
public async Task<OrganizationDto> GetOrganizationByCodeAsync(string code, CancellationToken cancellationToken)
{
return Mapper.Map<OrganizationDto>(await OrganizationService.GetOrganizationAsync(code, cancellationToken));
}
}
2 changes: 1 addition & 1 deletion src/CrystallineSociety/Server/Api/Data/AppDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public override int SaveChanges(bool acceptAllChangesOnSuccess)

public DbSet<Badge> Badges { get; set; }

public DbSet<EducationProgram> EducationPrograms { get; set; }
public DbSet<Organization> Organizations { get; set; }

private void ConfigIdentityTables(ModelBuilder builder)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static void AddServerServices(this IServiceCollection services)
services.AddTransient<ILearnerService, ServerLearnerService>();
// ToDo: Complete.
services.AddTransient(CreateGitHubClient);
services.AddTransient<IEducationProgramService, EducationProgramService>();
services.AddTransient<IOrganizationService, OrganizationService>();
}

public static void AddIdentity(this IServiceCollection services, IConfiguration configuration)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using CrystallineSociety.Server.Api.Models;
using CrystallineSociety.Server.Api.Models.TodoItem;
using CrystallineSociety.Shared.Dtos.EducationProgram;
using CrystallineSociety.Shared.Dtos.Organization;
using CrystallineSociety.Shared.Dtos.TodoItem;

namespace CrystallineSociety.Server.Api.Mappers;
Expand All @@ -9,6 +9,6 @@ public class EducationProgramMapperConfiguration : Profile
{
public EducationProgramMapperConfiguration()
{
CreateMap<EducationProgram, EducationProgramDto>().ReverseMap();
CreateMap<Organization, OrganizationDto>().ReverseMap();
}
}
Loading

0 comments on commit fa49758

Please sign in to comment.