feat 2e save to DB

not fully tested, but seems to work overall
This commit is contained in:
2024-02-20 14:55:08 +01:00
parent 41e894cd42
commit 636dcb92b3
16 changed files with 372 additions and 47 deletions
@@ -12,14 +12,14 @@ namespace Kemkas.Web.Controllers;
/// </summary>
/// <param name="validationService"></param>
/// <param name="dtoToDbModelService"></param>
/// <param name="dbModelToDtoService"></param>
/// <param name="dbModelToDto1EService"></param>
/// <param name="persistenceService"></param>
[ApiController]
[Route("[controller]")]
public class Character1EController(
ICharacterValidationService validationService,
ICharacter1EDtoToDbModelService dtoToDbModelService,
ICharacterDbModelToDtoService dbModelToDtoService,
ICharacterDbModelToDto1EService dbModelToDto1EService,
ICharacterPersistenceService persistenceService)
: ControllerBase
{
@@ -58,7 +58,7 @@ public class Character1EController(
return NotFound();
}
return dbModelToDtoService.Convert(entity);
return dbModelToDto1EService.Convert(entity);
}
[HttpPost("{id:guid}")]
@@ -11,7 +11,8 @@ namespace Kemkas.Web.Controllers;
[Route("[controller]")]
public class Character2EController(
ICharacter2EDtoToDbModelService dtoToDbModelService,
ICharacterPersistenceService persistenceService
ICharacterPersistenceService persistenceService,
ICharacterDbModelToDto2EService dbModelToDtoService
) : ControllerBase
{
[HttpPost]
@@ -39,5 +40,50 @@ public class Character2EController(
var id = await persistenceService.StoreNewCharacter2E(model, isPublic);
return id;
}
[HttpGet("{id:guid}")]
public async Task<ActionResult<Character2eDto>> GetCharacterById([FromRoute] Guid id)
{
var entity = await persistenceService.GetCharacter2EById(id);
if (entity is null)
{
return NotFound();
}
return dbModelToDtoService.Convert(entity);
}
[HttpPost("{id:guid}")]
public async Task<ActionResult<Guid>> UpdateCharacter([FromRoute] Guid id, [FromBody] Character2eDto 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.GetCharacter2EById(id, tracking: true);
if (original is null)
{
return NotFound();
}
try
{
dtoToDbModelService.Update(original, dto);
}
catch (ValidationException ex)
{
return BadRequest(ex.Message);
}
await persistenceService.UpdateCharacter2E(original, isPublic);
return id;
}
}