Form style / continents
Toward #2 completion; next up, Markdown input fields...
This commit is contained in:
@@ -9,16 +9,34 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace JobsJobsJobs.Server.Areas.Api.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// API controller for citizen information
|
||||
/// </summary>
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class CitizenController : ControllerBase
|
||||
{
|
||||
/// <summary>
|
||||
/// Authorization configuration section
|
||||
/// </summary>
|
||||
private readonly IConfigurationSection _config;
|
||||
|
||||
/// <summary>
|
||||
/// NodaTime clock
|
||||
/// </summary>
|
||||
private readonly IClock _clock;
|
||||
|
||||
/// <summary>
|
||||
/// The data connection to use for this request
|
||||
/// </summary>
|
||||
private readonly NpgsqlConnection _db;
|
||||
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <param name="config">The authorization configuration section</param>
|
||||
/// <param name="clock">The NodaTime clock instance</param>
|
||||
/// <param name="db">The data connection to use for this request</param>
|
||||
public CitizenController(IConfiguration config, IClock clock, NpgsqlConnection db)
|
||||
{
|
||||
_config = config.GetSection("Auth");
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
using JobsJobsJobs.Server.Data;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Npgsql;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace JobsJobsJobs.Server.Areas.Api.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// API endpoint for continent information
|
||||
/// </summary>
|
||||
[Route("api/[controller]")]
|
||||
[Authorize]
|
||||
[ApiController]
|
||||
public class ContinentController : ControllerBase
|
||||
{
|
||||
/// <summary>
|
||||
/// The database connection to use for this request
|
||||
/// </summary>
|
||||
private readonly NpgsqlConnection _db;
|
||||
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <param name="db">The database connection to use for this request</param>
|
||||
public ContinentController(NpgsqlConnection db)
|
||||
{
|
||||
_db = db;
|
||||
}
|
||||
|
||||
[HttpGet("all")]
|
||||
public async Task<IActionResult> All()
|
||||
{
|
||||
await _db.OpenAsync();
|
||||
return Ok(await _db.AllContinents());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,9 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace JobsJobsJobs.Server.Areas.Api.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// API controller for employment profile information
|
||||
/// </summary>
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class ProfileController : ControllerBase
|
||||
@@ -20,19 +23,23 @@ namespace JobsJobsJobs.Server.Areas.Api.Controllers
|
||||
/// <summary>
|
||||
/// The database connection
|
||||
/// </summary>
|
||||
private readonly NpgsqlConnection db;
|
||||
private readonly NpgsqlConnection _db;
|
||||
|
||||
public ProfileController(NpgsqlConnection dbConn)
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <param name="db">The database connection to use for this request</param>
|
||||
public ProfileController(NpgsqlConnection db)
|
||||
{
|
||||
db = dbConn;
|
||||
_db = db;
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
[HttpGet("")]
|
||||
public async Task<IActionResult> Get()
|
||||
{
|
||||
await db.OpenAsync();
|
||||
var profile = await db.FindProfileByCitizen(
|
||||
await _db.OpenAsync();
|
||||
var profile = await _db.FindProfileByCitizen(
|
||||
CitizenId.Parse(User.FindFirst(ClaimTypes.NameIdentifier)!.Value));
|
||||
return profile == null ? NoContent() : Ok(profile);
|
||||
}
|
||||
|
||||
40
src/JobsJobsJobs/Server/Data/ContinentExtensions.cs
Normal file
40
src/JobsJobsJobs/Server/Data/ContinentExtensions.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using JobsJobsJobs.Shared;
|
||||
using Npgsql;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace JobsJobsJobs.Server.Data
|
||||
{
|
||||
/// <summary>
|
||||
/// Data extensions for manipulation of continent objects
|
||||
/// </summary>
|
||||
public static class ContinentExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Create a continent from the current row in the data reader
|
||||
/// </summary>
|
||||
/// <param name="rdr">The data reader</param>
|
||||
/// <returns>The current row's values as a continent object</returns>
|
||||
private static Continent ToContinent(NpgsqlDataReader rdr) =>
|
||||
new Continent(ContinentId.Parse(rdr.GetString("id")), rdr.GetString("name"));
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve all continents
|
||||
/// </summary>
|
||||
/// <returns>All continents</returns>
|
||||
public static async Task<IEnumerable<Continent>> AllContinents(this NpgsqlConnection conn)
|
||||
{
|
||||
using var cmd = conn.CreateCommand();
|
||||
cmd.CommandText = "SELECT * FROM continent ORDER BY name";
|
||||
|
||||
using var rdr = await cmd.ExecuteReaderAsync().ConfigureAwait(false);
|
||||
var continents = new List<Continent>();
|
||||
while (await rdr.ReadAsync())
|
||||
{
|
||||
continents.Add(ToContinent(rdr));
|
||||
}
|
||||
|
||||
return continents;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,8 +4,8 @@
|
||||
<RazorPage_SelectedScaffolderID>RazorPageScaffolder</RazorPage_SelectedScaffolderID>
|
||||
<RazorPage_SelectedScaffolderCategoryPath>root/Common/RazorPage</RazorPage_SelectedScaffolderCategoryPath>
|
||||
<ActiveDebugProfile>JobsJobsJobs.Server</ActiveDebugProfile>
|
||||
<Controller_SelectedScaffolderID>ApiControllerEmptyScaffolder</Controller_SelectedScaffolderID>
|
||||
<Controller_SelectedScaffolderCategoryPath>root/Common/Api</Controller_SelectedScaffolderCategoryPath>
|
||||
<Controller_SelectedScaffolderID>MvcControllerEmptyScaffolder</Controller_SelectedScaffolderID>
|
||||
<Controller_SelectedScaffolderCategoryPath>root/Common/MVC/Controller</Controller_SelectedScaffolderCategoryPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
<DebuggerFlavor>ProjectDebugger</DebuggerFlavor>
|
||||
|
||||
Reference in New Issue
Block a user