Skip to content

Commit

Permalink
feat: add whilte labeling query (mock data)
Browse files Browse the repository at this point in the history
  • Loading branch information
ksavosteev committed Apr 17, 2024
1 parent ad30a89 commit 0b51111
Show file tree
Hide file tree
Showing 7 changed files with 188 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/VirtoCommerce.WhiteLabeling.Core/Models/FooterLink.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Collections.Generic;

namespace VirtoCommerce.WhiteLabeling.Core.Models
{
public class FooterLink
{
public string Title { get; set; }
public string Url { get; set; }
public IList<FooterLink> ChildItems { get; set; } = [];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Collections.Generic;

namespace VirtoCommerce.WhiteLabeling.Core.Models
{
public class WhiteLabelingSettings
{
public string UserId { get; set; }
public string OrganizationId { get; set; }
public string LogoUrl { get; set; }
public string SecondaryLogoUrl { get; set; }
public string FaviconUrl { get; set; }
public IList<FooterLink> FooterLinks { get; set; } = [];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System.Collections.Generic;
using GraphQL;
using GraphQL.Types;
using VirtoCommerce.ExperienceApiModule.Core.BaseQueries;
using VirtoCommerce.WhiteLabeling.Core.Models;

namespace VirtoCommerce.WhiteLabeling.Data.Queries
{
public class GetWhiteLabelingSettingsQuery : Query<WhiteLabelingSettings>
{
public string OrganizationId { get; set; }

public string UserId { get; set; }

public string CultureName { get; set; }

public override IEnumerable<QueryArgument> GetArguments()
{
yield return Argument<StringGraphType>(nameof(OrganizationId));
yield return Argument<StringGraphType>(nameof(UserId));
yield return Argument<StringGraphType>(nameof(CultureName));
}

public override void Map(IResolveFieldContext context)
{
OrganizationId = context.GetArgument<string>(nameof(OrganizationId));
UserId = context.GetArgument<string>(nameof(UserId));
CultureName = context.GetArgument<string>(nameof(CultureName));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using MediatR;
using Microsoft.AspNetCore.Authorization;
using VirtoCommerce.ExperienceApiModule.Core.BaseQueries;
using VirtoCommerce.WhiteLabeling.Core.Models;
using VirtoCommerce.WhiteLabeling.Data.Schemas;

namespace VirtoCommerce.WhiteLabeling.Data.Queries
{
public class GetWhiteLabelingSettingsQueryBuilder : QueryBuilder<GetWhiteLabelingSettingsQuery, WhiteLabelingSettings, WhiteLabelingSettingsType>
{
public GetWhiteLabelingSettingsQueryBuilder(IMediator mediator, IAuthorizationService authorizationService)
: base(mediator, authorizationService)
{
}

protected override string Name => "whiteLabelingSettings";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using VirtoCommerce.ExperienceApiModule.Core.Infrastructure;
using VirtoCommerce.WhiteLabeling.Core.Models;

namespace VirtoCommerce.WhiteLabeling.Data.Queries
{
public class GetWhiteLabelingSettingsQueryHandler : IQueryHandler<GetWhiteLabelingSettingsQuery, WhiteLabelingSettings>
{
public GetWhiteLabelingSettingsQueryHandler()
{
}

public Task<WhiteLabelingSettings> Handle(GetWhiteLabelingSettingsQuery request, CancellationToken cancellationToken)
{
var settings = new List<WhiteLabelingSettings>()
{
new WhiteLabelingSettings()
{
UserId = "cfcec63a-faa5-4511-9aef-ee7672af6710",
OrganizationId = "f081c52234754c9c8229aa42d6a19220",
LogoUrl = "/static/images/common/logo-1.svg",
SecondaryLogoUrl = "/static/images/common/logo-white-1.svg",
FaviconUrl = "/static/icons/favicon-1.svg",
FooterLinks = new List<FooterLink>()
{
new FooterLink()
{
Title = "Company Details",
Url = "/company-details",
ChildItems = new List<FooterLink>()
{
new FooterLink()
{
Title = "About Us",
Url = "/about-us"
},
new FooterLink()
{
Title = "Investor Relations",
Url = "/investor-relations"
}
}
},
new FooterLink()
{
Title = "Customer Support",
Url = "/customer-support",
ChildItems = new List<FooterLink>()
{
new FooterLink()
{
Title = "Catalog Request",
Url = "/catalog-request"
},
new FooterLink()
{
Title = "Contact Us",
Url = "/contact-us"
}
}
}
}
},
new WhiteLabelingSettings()
{
UserId = "07e6a601-b90e-4dbd-a7d0-0f1f89db4f2e",
OrganizationId = "",
LogoUrl = "/static/images/common/logo.svg",
SecondaryLogoUrl = "/static/images/common/logo-white.svg",
FaviconUrl = "/static/icons/favicon.svg",
}
};

var result = settings.FirstOrDefault(x => x.OrganizationId == request.OrganizationId || x.UserId == request.UserId);
return Task.FromResult(result);
}
}
}
15 changes: 15 additions & 0 deletions src/VirtoCommerce.WhiteLabeling.Data/Schemas/FooterLinkType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using GraphQL.Types;
using VirtoCommerce.WhiteLabeling.Core.Models;

namespace VirtoCommerce.WhiteLabeling.Data.Schemas
{
public class FooterLinkType : ObjectGraphType<FooterLink>
{
public FooterLinkType()
{
Field(x => x.Title, nullable: true).Description("Title of the footer link");
Field(x => x.Url, nullable: true).Description("URL of the footer link");
Field<ListGraphType<FooterLinkType>>("childItems", resolve: context => context.Source.ChildItems);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using GraphQL.Types;
using VirtoCommerce.WhiteLabeling.Core.Models;

namespace VirtoCommerce.WhiteLabeling.Data.Schemas
{
public class WhiteLabelingSettingsType : ObjectGraphType<WhiteLabelingSettings>
{
public WhiteLabelingSettingsType()
{
Field(x => x.UserId, nullable: true).Description("User ID");
Field(x => x.OrganizationId, nullable: true).Description("Organization ID");
Field(x => x.LogoUrl, nullable: true).Description("Logo URL");
Field(x => x.SecondaryLogoUrl, nullable: true).Description("Logo URL for footer");
Field(x => x.FaviconUrl, nullable: true).Description("FavIcon");
Field<ListGraphType<FooterLinkType>>("footerLinks", resolve: context => context.Source.FooterLinks);
}
}
}

0 comments on commit 0b51111

Please sign in to comment.