public async Task <ActionResult <UserModel> > Get(string id, bool includeEntries = false) { try { if (!HttpContext.User.CompareIdWithTokenId(id)) { return(Unauthorized()); } var user = await repository.GetUserById(id, includeEntries); if (user == null) { return(BadRequest("The user doesn't exist.")); } return(Ok(mapper.Map <User, UserModel>(user))); } catch (Exception) { return(StatusCode(StatusCodes.Status500InternalServerError, "Server error")); } }
public async Task <ActionResult <Entry[]> > Get(string userId) { try { if (!HttpContext.User.CompareIdWithTokenId(userId)) { return(Unauthorized()); } var user = await repository.GetUserById(userId, true); if (user == null) { return(BadRequest("The user doesn't exist.")); } return(Ok(user.Entries)); } catch (Exception) { return(StatusCode(StatusCodes.Status500InternalServerError, "Database Failure")); } }