LANCommander/LANCommander.Server/Controllers/Api/IssueController.cs
Pat Hartl add770b227 Refactor Settings
Settings for the server are now combined with the settings from the SDK. This introduces a large breaking change and a migration should be created. This refactor utilizes .NET Configuration and the Options pattern. This will allow for the overriding of any setting using envionment variables. It also means that Settings.yml can be used to override any .NET configuration. A SettingsProvider implementation was created, and any updating of settings was changed from SettingsService.SaveSettings() to SettingsProvider.Update(s => { ... })
2025-11-16 12:31:25 -06:00

59 lines
1.7 KiB
C#

using AutoMapper;
using LANCommander.Server.Data.Models;
using LANCommander.Server.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
namespace LANCommander.Server.Controllers.Api
{
[Authorize(AuthenticationSchemes = "Bearer")]
[Route("api/[controller]")]
[ApiController]
public class IssueController : BaseApiController
{
private readonly GameService GameService;
private readonly IssueService IssueService;
private readonly UserService UserService;
public IssueController(
ILogger<IssueController> logger,
SettingsProvider<Settings.Settings> settingsProvider,
GameService gameService,
IssueService issueService,
UserService userService) : base(logger, settingsProvider)
{
GameService = gameService;
IssueService = issueService;
UserService = userService;
}
[HttpPost("Open")]
public async Task<bool> OpenAsync(SDK.Models.Issue issueRequest)
{
try
{
var game = await GameService.GetAsync(issueRequest.GameId);
if (game != null)
{
var issue = new Issue()
{
GameId = game.Id,
Description = issueRequest.Description
};
await IssueService.AddAsync(issue);
return true;
}
}
catch (Exception ex)
{
Logger?.LogError(ex, "Could not open new issue");
}
return false;
}
}
}