using AutoMapper; using gehGassi.Core.Interfaces; using gehGassi.Dto.DogWalkers; using gehGassi.Dto; using gehGassi.Web.Helper; using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Options; using System.Threading.Tasks; using gehGassi.Domain.Common; using gehGassi.Dto.DogOwners; using gehGassi.Domain.Dogs; using gehGassi.Dto.Dogs; using gehGassi.Web.Auth; using Asp.Versioning; namespace gehGassi.Web.Controllers.Api { /// /// Controller der Zugriff auf DogOwners via Api ermöglicht /// [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] [ApiController] [ApiVersion(1)] [Route("api/dogowners")] [Route("api/v{v:apiVersion}/dogowners")] public class ApiDogOwnersController : ApiBaseController { /// /// Erstellt eine Instanz /// /// Instanz eines IMapper /// Instanz von LocalizationOptions /// Instanz eines IDogOwnerService public ApiDogOwnersController(IMapper mapper, IOptions localizationOptions, IAppUserService appUserService) : base(mapper, localizationOptions, appUserService) { } /// /// Gibt Detail-Infos zu einem DogOwner zurück /// /// Id des DogOwners /// [Route("GetDogOwner")] [HttpGet] public async Task GetDogOwner(string dogOwnerId) { var clientOffset = GetClientDateOffset(); if (User?.Identity != null && User.Identity.IsAuthenticated) { var dogOwner = await AppUserService.GetAsync(dogOwnerId); if (dogOwner != null && dogOwner.Type != AppUserType.DogWalker) { var dto = Mapper.Map(dogOwner); var baseAddress = GetBaseAddress(); if (!string.IsNullOrWhiteSpace(dto.Photo)) dto.Photo = $"{baseAddress}/file/documents/thumbnails/{400}/{dto.Photo}"; var appUserId = User.AppUserId(); dto.Locked = await AppUserService.IsLockedAsync(dogOwner.Id); dto.Blocked = await AppUserService.IsBlockedAsync(appUserId, dogOwner.Id); return Ok(dto); } } return NotFound(CommunicationErrors.Common_NotFound); } } }