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
Showing only changes of commit 474d01e901 - Show all commits

View File

@ -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;
} }
} }
} }

View File

@ -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()
{ {

View File

@ -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>