Update CharacterController with Either, also small style fix in UserController #30

Merged
s426134 merged 1 commits from SES-92 into dev 2020-12-16 21:49:36 +01:00
3 changed files with 16 additions and 9 deletions

View File

@ -1,6 +1,8 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using SessionCompanion.Extensions.EitherType;
using SessionCompanion.Services.Interfaces;
using SessionCompanion.ViewModels.ApiResponses;
using SessionCompanion.ViewModels.CharacterViewModels;
namespace SessionCompanion.Controllers
@ -19,12 +21,19 @@ namespace SessionCompanion.Controllers
/// <summary>
/// Metoda zwraca postać ze wskazanym identyfikatorem
/// </summary>
/// <param name="id">Identyfikator postaci</param>
/// <returns>ViewModel Postaci</returns>
[HttpGet("{id}")]
public async Task<CharacterViewModel> Get(int id)
/// <param name="characterId">Identyfikator postaci</param>
/// <returns>ViewModel Postaci/ErrorResponse</returns>
[HttpGet("{characterId}")]
public async Task<Either<ErrorResponse, CharacterViewModel>> Get(int characterId)
{
return await _service.Get(id);
CharacterViewModel characterViewModel = await _service.Get(characterId);
if (characterViewModel is null)
return new ErrorResponse() {
StatusCode = 204,
Message = "No character with given characterId"
};
return characterViewModel;
}
}
}

View File

@ -34,9 +34,7 @@ namespace SessionCompanion.Controllers
UserViewModel user = await _service.SearchUserByUsername(userName);
if (user != null && user.Password.Equals(password))
{
return user.Id;
}
return new ErrorResponse()
{

View File

@ -8,8 +8,8 @@
<summary>
Metoda zwraca postać ze wskazanym identyfikatorem
</summary>
<param name="id">Identyfikator postaci</param>
<returns>ViewModel Postaci</returns>
<param name="characterId">Identyfikator postaci</param>
<returns>ViewModel Postaci/ErrorResponse</returns>
</member>
<member name="M:SessionCompanion.Controllers.UserController.Login(System.String,System.String)">
<summary>