using System; using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.DependencyInjection; using Timeline.Auth; using Timeline.Services.Mapper; using Timeline.Services.User; namespace Timeline.Controllers.V2 { public class V2ControllerBase : ControllerBase { #region auth protected bool UserHasPermission(UserPermission permission) { return User.HasPermission(permission); } protected long? GetOptionalAuthUserId() { return User.GetOptionalUserId(); } protected long GetAuthUserId() { return GetOptionalAuthUserId() ?? throw new InvalidOperationException(Resource.ExceptionNoUserId); } #endregion #region mapper protected IGenericMapper GetMapper() { return HttpContext.RequestServices.GetRequiredService(); } protected async Task MapAsync(object o) { return await GetMapper().MapAsync(o, Url, User); } protected async Task> MapListAsync(IEnumerable o) { return await GetMapper().MapListAsync(o, Url, User); } protected T AutoMapperMap(object o) { return GetMapper().AutoMapperMap(o); } #endregion } }