feat: 2e save character initial implementation WIP
2e is hidden behind url navigation hiding, so hoping that nobody found it yet. Note: DB migration make this commit a bit risky!
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Kemkas.Web.Db.Models;
|
||||
using Kemkas.Web.Services.FirstEdition.Character;
|
||||
using Kemkas.Web.Services.Shared;
|
||||
using Kemkas.Web.ViewModels;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Kemkas.Web.Controllers;
|
||||
|
||||
/// <summary>
|
||||
/// First edition character endpoints
|
||||
/// </summary>
|
||||
/// <param name="validationService"></param>
|
||||
/// <param name="dtoToDbModelService"></param>
|
||||
/// <param name="dbModelToDtoService"></param>
|
||||
/// <param name="persistenceService"></param>
|
||||
[ApiController]
|
||||
[Route("[controller]")]
|
||||
public class Character1EController(
|
||||
ICharacterValidationService validationService,
|
||||
ICharacter1EDtoToDbModelService dtoToDbModelService,
|
||||
ICharacterDbModelToDtoService dbModelToDtoService,
|
||||
ICharacterPersistenceService persistenceService)
|
||||
: ControllerBase
|
||||
{
|
||||
[HttpPost]
|
||||
public async Task<ActionResult<Guid>> StoreNewCharacter([FromBody] Character1eDto dto, [FromQuery]bool isPublic = true)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState);
|
||||
}
|
||||
var errors = validationService.Validate(dto);
|
||||
if (errors != null)
|
||||
{
|
||||
return BadRequest(errors);
|
||||
}
|
||||
|
||||
V1Karakter model;
|
||||
try
|
||||
{
|
||||
model = dtoToDbModelService.Convert(dto);
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
var id = await persistenceService.StoreNewCharacter1E(model, isPublic);
|
||||
return id;
|
||||
}
|
||||
|
||||
[HttpGet("{id:guid}")]
|
||||
public async Task<ActionResult<Character1eDto>> GetCharacterById([FromRoute] Guid id)
|
||||
{
|
||||
var entity = await persistenceService.GetCharacter1EById(id);
|
||||
if (entity is null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
return dbModelToDtoService.Convert(entity);
|
||||
}
|
||||
|
||||
[HttpPost("{id:guid}")]
|
||||
public async Task<ActionResult<Guid>> UpdateCharacter([FromRoute] Guid id, [FromBody] Character1eDto dto, [FromQuery]bool isPublic = true)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState);
|
||||
}
|
||||
var errors = validationService.Validate(dto);
|
||||
if (errors != null)
|
||||
{
|
||||
return BadRequest(errors);
|
||||
}
|
||||
|
||||
var original = await persistenceService.GetCharacter1EById(id, tracking: true);
|
||||
if (original is null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
dtoToDbModelService.Update(original, dto);
|
||||
|
||||
await persistenceService.UpdateCharacter1E(original, isPublic);
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Kemkas.Web.Db.Models;
|
||||
using Kemkas.Web.Services.SecondEdition.Character;
|
||||
using Kemkas.Web.Services.Shared;
|
||||
using Kemkas.Web.ViewModels;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Kemkas.Web.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("[controller]")]
|
||||
public class Character2EController(
|
||||
ICharacter2EDtoToDbModelService dtoToDbModelService,
|
||||
ICharacterPersistenceService persistenceService
|
||||
) : ControllerBase
|
||||
{
|
||||
[HttpPost]
|
||||
public async Task<ActionResult<Guid>> StoreNewCharacter([FromBody] Character2eDto dto, [FromQuery]bool isPublic = true)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState);
|
||||
}
|
||||
// var errors = validationService.Validate(dto);
|
||||
// if (errors != null)
|
||||
// {
|
||||
// return BadRequest(errors);
|
||||
// }
|
||||
|
||||
V2Karakter model;
|
||||
try
|
||||
{
|
||||
model = dtoToDbModelService.Convert(dto);
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
var id = await persistenceService.StoreNewCharacter2E(model, isPublic);
|
||||
return id;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,85 +1,19 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Kemkas.Web.Db.Models;
|
||||
using Kemkas.Web.Services.Character;
|
||||
using Kemkas.Web.Services.FirstEdition.Character;
|
||||
using Kemkas.Web.Services.Shared;
|
||||
using Kemkas.Web.ViewModels;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Kemkas.Web.Controllers;
|
||||
|
||||
/// <summary>
|
||||
/// Shared first and second edition character endpoints
|
||||
/// </summary>
|
||||
/// <param name="persistenceService"></param>
|
||||
[ApiController]
|
||||
[Route("[controller]")]
|
||||
public class CharacterController(
|
||||
ICharacterValidationService validationService,
|
||||
ICharacterDtoToDbModelService dtoToDbModelService,
|
||||
ICharacterDbModelToDtoService dbModelToDtoService,
|
||||
ICharacterPersistenceService persistenceService)
|
||||
: ControllerBase
|
||||
public class CharacterController(ICharacterPersistenceService persistenceService) : ControllerBase
|
||||
{
|
||||
[HttpPost]
|
||||
public async Task<ActionResult<Guid>> StoreNewCharacter([FromBody] CharacterDto dto, [FromQuery]bool isPublic = true)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState);
|
||||
}
|
||||
var errors = validationService.Validate(dto);
|
||||
if (errors != null)
|
||||
{
|
||||
return BadRequest(errors);
|
||||
}
|
||||
|
||||
V1Karakter model;
|
||||
try
|
||||
{
|
||||
model = dtoToDbModelService.Convert(dto);
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
var id = await persistenceService.StoreNewCharacter(model, isPublic);
|
||||
return id;
|
||||
}
|
||||
|
||||
[HttpGet("{id:guid}")]
|
||||
public async Task<ActionResult<CharacterDto>> GetCharacterById([FromRoute] Guid id)
|
||||
{
|
||||
var entity = await persistenceService.GetCharacterById(id);
|
||||
if (entity is null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
return dbModelToDtoService.Convert(entity);
|
||||
}
|
||||
|
||||
[HttpPost("{id:guid}")]
|
||||
public async Task<ActionResult<Guid>> UpdateCharacter([FromRoute] Guid id, [FromBody] CharacterDto dto, [FromQuery]bool isPublic = true)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState);
|
||||
}
|
||||
var errors = validationService.Validate(dto);
|
||||
if (errors != null)
|
||||
{
|
||||
return BadRequest(errors);
|
||||
}
|
||||
|
||||
var original = await persistenceService.GetCharacterById(id, tracking: true);
|
||||
if (original is null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
dtoToDbModelService.Update(original, dto);
|
||||
|
||||
await persistenceService.UpdateCharacter(original, isPublic);
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Authorize]
|
||||
public async Task<List<CharacterListItemDto>> GetAllCharacters()
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
using Kemkas.Web.ViewModels;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Kemkas.Web.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("[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()
|
||||
{
|
||||
return Enumerable.Range(1, 5).Select(
|
||||
index => new WeatherForecast
|
||||
{
|
||||
Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
|
||||
TemperatureC = Random.Shared.Next(-20, 55),
|
||||
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
|
||||
})
|
||||
.ToArray();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user