SES-148 Add Endpoint to add new weapon to character

This commit is contained in:
Karol Górzyński 2021-01-13 17:37:25 +01:00
parent 8a7c50b307
commit 3ca90663b2

View File

@ -97,5 +97,26 @@ namespace SessionCompanion.Controllers
return new ErrorResponse() { StatusCode = 500, Message = e.Message }; return new ErrorResponse() { StatusCode = 500, Message = e.Message };
} }
} }
/// <summary>
/// Metoda dodaje Weapon do danej postaci
/// </summary>
/// <param name="characterWeaponViewModel"></param>
/// <returns></returns>
[HttpPut("addWeapon")]
public async Task<Either<SuccessResponse, ErrorResponse>> AddCharacterWeapon(CharacterWeaponViewModel characterWeaponViewModel)
{
if (!ModelState.IsValid)
return new ErrorResponse() { StatusCode = 500, Message = "Invalid model!" };
try
{
await _characterWeaponService.Create(characterWeaponViewModel);
await _characterWeaponService.SaveAsync();
return new SuccessResponse("Weapon added to character") { SuccessCode = 200 };
}
catch (Exception e)
{
return new ErrorResponse() { StatusCode = 500, Message = e.Message };
}
}
} }
} }