Help wanted #23

Merged
danieljsummers merged 20 commits from help-wanted into main 2021-09-01 01:16:43 +00:00
5 changed files with 144 additions and 0 deletions
Showing only changes of commit 73d6d0df94 - Show all commits

View File

@ -4,6 +4,7 @@
<RazorPage_SelectedScaffolderID>RazorPageScaffolder</RazorPage_SelectedScaffolderID>
<RazorPage_SelectedScaffolderCategoryPath>root/Common/RazorPage</RazorPage_SelectedScaffolderCategoryPath>
<ActiveDebugProfile>JobsJobsJobs</ActiveDebugProfile>
<ShowAllFiles>true</ShowAllFiles>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DebuggerFlavor>ProjectDebugger</DebuggerFlavor>

View File

@ -0,0 +1,25 @@
@page "/listings/mine"
@inject HttpClient http
@inject NavigationManager nav
@inject AppState state
<PageTitle Title="My Job Listings" />
<h3>My Job Listings</h3>
<ErrorList Errors=@ErrorMessages>
@if (Loading)
{
<p>Loading job listings&hellip;</p>
}
else
{
@if (Listings.Any())
{
<p>TODO: list them</p>
}
else
{
<p><em>No job listings found</em></p>
}
}
</ErrorList>

View File

@ -0,0 +1,41 @@
using JobsJobsJobs.Shared;
using Microsoft.AspNetCore.Components;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace JobsJobsJobs.Client.Pages.Listings
{
public partial class Mine : ComponentBase
{
/// <summary>
/// Whether the page is loading data
/// </summary>
private bool Loading { get; set; } = true;
/// <summary>
/// Error messages encountered while searching for profiles
/// </summary>
private IList<string> ErrorMessages { get; } = new List<string>();
/// <summary>
/// The job listings entered by the current user
/// </summary>
private IEnumerable<Listing> Listings { get; set; } = Enumerable.Empty<Listing>();
protected override async Task OnInitializedAsync()
{
var listings = await ServerApi.RetrieveMany<Listing>(http, "listing/mine");
if (listings.IsOk)
{
Listings = listings.Ok;
}
else
{
ErrorMessages.Add(listings.Error);
}
}
}
}

View File

@ -0,0 +1,52 @@
using JobsJobsJobs.Server.Data;
using JobsJobsJobs.Shared;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using NodaTime;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
namespace JobsJobsJobs.Server.Areas.Api.Controllers
{
/// <summary>
/// API controller for job listings
/// </summary>
[Route("api/listings")]
[Authorize]
[ApiController]
public class ListingController : ControllerBase
{
/// <summary>
/// The data context
/// </summary>
private readonly JobsDbContext _db;
/// <summary>
/// The NodaTime clock instance
/// </summary>
private readonly IClock _clock;
/// <summary>
/// Constructor
/// </summary>
/// <param name="db">The data context to use for this request</param>
/// <param name="clock">The clock instance to use for this request</param>
public ListingController(JobsDbContext db, IClock clock)
{
_db = db;
_clock = clock;
}
/// <summary>
/// The current citizen ID
/// </summary>
private CitizenId CurrentCitizenId => CitizenId.Parse(User.FindFirst(ClaimTypes.NameIdentifier)!.Value);
[HttpGet("mine")]
public async Task<IActionResult> Mine() =>
Ok(await _db.FindListingsByCitizen(CurrentCitizenId));
}
}

View File

@ -0,0 +1,25 @@
using JobsJobsJobs.Shared;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace JobsJobsJobs.Server.Data
{
/// <summary>
/// Extensions to JobsDbContext to support manipulation of job listings
/// </summary>
public static class ListingExtensions
{
/// <summary>
/// Find all job listings for the given citizen ID
/// </summary>
/// <param name="citizenId">The citizen ID for which job listings should be retrieved</param>
/// <returns>The job listings entered by the given citizen</returns>
public static async Task<IEnumerable<Listing>> FindListingsByCitizen(this JobsDbContext db, CitizenId citizenId)
=> await db.Listings.AsNoTracking()
.Where(l => l.CitizenId == citizenId)
.ToListAsync().ConfigureAwait(false);
}
}