74 lines
2.7 KiB
C#
74 lines
2.7 KiB
C#
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
|
|
{
|
|
/// <summary>
|
|
/// Controller der Zugriff auf DogOwners via Api ermöglicht
|
|
/// </summary>
|
|
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
|
|
[ApiController]
|
|
[ApiVersion(1)]
|
|
[Route("api/dogowners")]
|
|
[Route("api/v{v:apiVersion}/dogowners")]
|
|
public class ApiDogOwnersController : ApiBaseController
|
|
{
|
|
/// <summary>
|
|
/// Erstellt eine Instanz
|
|
/// </summary>
|
|
/// <param name="mapper">Instanz eines IMapper</param>
|
|
/// <param name="localizationOptions">Instanz von LocalizationOptions</param>
|
|
/// <param name="appUserService">Instanz eines IDogOwnerService</param>
|
|
public ApiDogOwnersController(IMapper mapper, IOptions<LocalizationOptions> localizationOptions, IAppUserService appUserService) : base(mapper, localizationOptions, appUserService)
|
|
{
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gibt Detail-Infos zu einem DogOwner zurück
|
|
/// </summary>
|
|
/// <param name="dogOwnerId">Id des DogOwners</param>
|
|
/// <returns></returns>
|
|
[Route("GetDogOwner")]
|
|
[HttpGet]
|
|
public async Task<IActionResult> 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<DogOwnerInfoDto>(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);
|
|
}
|
|
}
|
|
}
|