TourIAm/TIAMWebApp/Server/Controllers/ProfileAPIController.cs

69 lines
2.1 KiB
C#

using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using QRCoder;
using System.Drawing;
using System.Drawing.Imaging;
using AyCode.Core.Enums;
using AyCode.Core.Extensions;
using TIAM.Database.DataLayers.Admins;
using TIAM.Entities.ServiceProviders;
using TIAM.Entities.Users;
using TIAMWebApp.Shared.Application.Models;
using Product = TIAM.Entities.Products.Product;
using TIAM.Entities.Addresses;
using TIAM.Entities.Profiles;
using AyCode.Core.Loggers;
using AyCode.Entities;
using AyCode.Services.SignalRs;
using AyCode.Utils.Extensions;
using TIAM.Entities.Drivers;
using TIAM.Services;
namespace TIAMWebApp.Server.Controllers
{
[Authorize]
[ApiController]
[Route("api/v1/[controller]")]
public class ProfileAPIController(AdminDal adminDal, IEnumerable<IAcLogWriterBase> logWriters) : ControllerBase
{
private readonly TIAM.Core.Loggers.Logger<ServiceProviderAPIController> _logger = new(logWriters.ToArray());
[AllowAnonymous]
[HttpGet]
[Route(APIUrls.GetProfileByIdRouteName)]
[SignalR(SignalRTags.GetProfileById)]
public async Task<string> GetProfileById([FromBody] Guid id)
{
if (id != Guid.Empty)
{
_logger.Info($@"GetServiceProviderById called with id: {id}");
var result = await adminDal.GetProfileByIdAsync(id);
List<Profile> profiles = new List<Profile>();
if (result != null)
profiles.Add(result);
var jsonResult = profiles.ToJson();
return jsonResult;
}
else {
return string.Empty;
}
}
[AllowAnonymous]
[HttpPost]
[Route(APIUrls.UpdateProfileRouteName)]
[SignalR(SignalRTags.UpdateProfile)]
public async Task<string> UpdateProfile(Profile profile)
{
_logger.Info($"UpdateUserProductMapping called! + {profile.Id}");
var result = await adminDal.UpdateProfileAsync(profile);
return result ? profile.ToJson() : string.Empty;
}
}
}