Renamed everything from MultiShop to Props.

This commit is contained in:
2021-07-13 00:35:31 -05:00
parent cefd02f202
commit 7e8a398741
114 changed files with 117 additions and 106 deletions

View File

@@ -0,0 +1,26 @@
using Microsoft.AspNetCore.ApiAuthorization.IdentityServer;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
namespace Props.Controllers
{
public class OidcConfigurationController : Controller
{
private readonly ILogger<OidcConfigurationController> _logger;
public OidcConfigurationController(IClientRequestParametersProvider clientRequestParametersProvider, ILogger<OidcConfigurationController> logger)
{
ClientRequestParametersProvider = clientRequestParametersProvider;
_logger = logger;
}
public IClientRequestParametersProvider ClientRequestParametersProvider { get; }
[HttpGet("_configuration/{clientId}")]
public IActionResult GetClientRequestParameters([FromRoute]string clientId)
{
var parameters = ClientRequestParametersProvider.GetClientParameters(HttpContext, clientId);
return Ok(parameters);
}
}
}

View File

@@ -0,0 +1,32 @@
using System.Collections.Generic;
using System.IO;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Props.Options;
namespace Props.Server.Controllers
{
[ApiController]
[Route("api/[controller]")]
public class PublicApiSettingsController : ControllerBase
{
private IConfiguration configuration;
public PublicApiSettingsController(IConfiguration configuration)
{
this.configuration = configuration;
}
[HttpGet]
public IActionResult Get() {
return Ok(BuildPublicApiSettings());
}
private IReadOnlyDictionary<string, string> BuildPublicApiSettings() {
IdentificationOptions identificationOptions = configuration.GetSection(IdentificationOptions.Identification).Get<IdentificationOptions>();
return new Dictionary<string,string>() {
// Build dictionary containing options client should be aware of.
{"RegistrationEnabled", identificationOptions.RegistrationEnabled.ToString()}
};
}
}
}

View File

@@ -0,0 +1,82 @@
using System.Text.Json;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Props.Data;
using Props.Models;
using Props.Shared.Models;
namespace Props.Server.Controllers
{
[ApiController]
[Authorize]
[Route("api/[controller]")]
public class UserConfigurationsController : ControllerBase
{
private ILogger<UserConfigurationsController> logger;
private UserManager<ApplicationUser> userManager;
private ApplicationDbContext dbContext;
public UserConfigurationsController(UserManager<ApplicationUser> userManager, ApplicationDbContext dbContext, ILogger<UserConfigurationsController> logger)
{
this.userManager = userManager;
this.dbContext = dbContext;
this.logger = logger;
}
[HttpGet]
public async Task<IActionResult> GetSearchOutline() {
ApplicationUser userModel = await userManager.GetUserAsync(User);
return Ok(userModel.SearchOutline);
}
[HttpGet]
public async Task<IActionResult> GetResultsPreferences() {
ApplicationUser userModel = await userManager.GetUserAsync(User);
return Ok(userModel.ResultsPreferences);
}
[HttpGet]
public async Task<IActionResult> GetApplicationPreferences() {
ApplicationUser userModel = await userManager.GetUserAsync(User);
logger.LogInformation(JsonSerializer.Serialize(userModel.ApplicationPreferences));
return Ok(userModel.ApplicationPreferences);
}
[HttpPut]
public async Task<IActionResult> PutSearchOutline(SearchOutline searchOutline) {
ApplicationUser userModel = await userManager.GetUserAsync(User);
if (userModel.SearchOutline.Id != searchOutline.Id || userModel.Id != searchOutline.ApplicationUserId) {
return BadRequest();
}
dbContext.Entry(userModel.SearchOutline).CurrentValues.SetValues(searchOutline);
await userManager.UpdateAsync(userModel);
return NoContent();
}
[HttpPut]
public async Task<IActionResult> PutResultsPreferences(ResultsPreferences resultsPreferences) {
ApplicationUser userModel = await userManager.GetUserAsync(User);
if (userModel.ResultsPreferences.Id != resultsPreferences.Id || userModel.Id != resultsPreferences.ApplicationUserId) {
return BadRequest();
}
dbContext.Entry(userModel.ResultsPreferences).CurrentValues.SetValues(resultsPreferences);
await userManager.UpdateAsync(userModel);
return NoContent();
}
[HttpPut]
public async Task<IActionResult> PutApplicationPreferences(ApplicationPreferences applicationPreferences) {
ApplicationUser userModel = await userManager.GetUserAsync(User);
logger.LogInformation(JsonSerializer.Serialize(applicationPreferences));
if (userModel.ApplicationPreferences.Id != applicationPreferences.Id || userModel.Id != applicationPreferences.ApplicationUserId) {
return BadRequest();
}
dbContext.Entry(userModel.ApplicationPreferences).CurrentValues.SetValues(applicationPreferences);
await userManager.UpdateAsync(userModel);
return NoContent();
}
}
}

View File

@@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
namespace Props.Controllers
{
// TODO: Create new shop search controller.
[Authorize]
[ApiController]
[Route("api/[controller]")]
public class WeatherForecastController : ControllerBase
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
private readonly ILogger<WeatherForecastController> _logger;
public WeatherForecastController(ILogger<WeatherForecastController> logger)
{
_logger = logger;
}
[HttpGet]
public IEnumerable<WeatherForecast> Get()
{
var rng = new Random();
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateTime.Now.AddDays(index),
TemperatureC = rng.Next(-20, 55),
Summary = Summaries[rng.Next(Summaries.Length)]
})
.ToArray();
}
}
}