Update CharacterController with Either, also small style fix in UserController #30
@ -1,6 +1,8 @@
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using SessionCompanion.Extensions.EitherType;
|
||||||
using SessionCompanion.Services.Interfaces;
|
using SessionCompanion.Services.Interfaces;
|
||||||
|
using SessionCompanion.ViewModels.ApiResponses;
|
||||||
using SessionCompanion.ViewModels.CharacterViewModels;
|
using SessionCompanion.ViewModels.CharacterViewModels;
|
||||||
|
|
||||||
namespace SessionCompanion.Controllers
|
namespace SessionCompanion.Controllers
|
||||||
@ -19,12 +21,19 @@ namespace SessionCompanion.Controllers
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Metoda zwraca postać ze wskazanym identyfikatorem
|
/// Metoda zwraca postać ze wskazanym identyfikatorem
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="id">Identyfikator postaci</param>
|
/// <param name="characterId">Identyfikator postaci</param>
|
||||||
/// <returns>ViewModel Postaci</returns>
|
/// <returns>ViewModel Postaci/ErrorResponse</returns>
|
||||||
[HttpGet("{id}")]
|
[HttpGet("{characterId}")]
|
||||||
public async Task<CharacterViewModel> Get(int id)
|
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);
|
UserViewModel user = await _service.SearchUserByUsername(userName);
|
||||||
|
|
||||||
if (user != null && user.Password.Equals(password))
|
if (user != null && user.Password.Equals(password))
|
||||||
{
|
|
||||||
return user.Id;
|
return user.Id;
|
||||||
}
|
|
||||||
|
|
||||||
return new ErrorResponse()
|
return new ErrorResponse()
|
||||||
{
|
{
|
||||||
|
@ -8,8 +8,8 @@
|
|||||||
<summary>
|
<summary>
|
||||||
Metoda zwraca postać ze wskazanym identyfikatorem
|
Metoda zwraca postać ze wskazanym identyfikatorem
|
||||||
</summary>
|
</summary>
|
||||||
<param name="id">Identyfikator postaci</param>
|
<param name="characterId">Identyfikator postaci</param>
|
||||||
<returns>ViewModel Postaci</returns>
|
<returns>ViewModel Postaci/ErrorResponse</returns>
|
||||||
</member>
|
</member>
|
||||||
<member name="M:SessionCompanion.Controllers.UserController.Login(System.String,System.String)">
|
<member name="M:SessionCompanion.Controllers.UserController.Login(System.String,System.String)">
|
||||||
<summary>
|
<summary>
|
||||||
|
Loading…
Reference in New Issue
Block a user