Update CharacterController with Either, also small style fix in UserController
This commit is contained in:
parent
50236f8ea0
commit
474d01e901
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
@ -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()
|
||||
{
|
||||
|
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user